我已经建立了一个部分,该部分最终将成为产品过滤器。我已经具有单击父选项时的功能,列表会展开以显示子选项。唯一的问题是,我需要将父选项和样式跨度向上推,子选项的底部是该行底部的父选项和跨度所在的位置,如果这有意义的话...
反应:
import React, {Component} from "react";
import "./LeftMenuBar.js.css";
class LeftMenuBar extends Component {
constructor (props) {
super(props);
this.state = {
isHidden: true
}
}
handleToggle(e){
console.log(e);
this.setState({
isHidden: !this.state.isHidden
})
}
render() {
console.log(this.state.isHidden);
return (
<div className="LeftMenu">
<div className="filterList">
<ul className="ul-style">
<li id="filterOption"><a onClick={(e) => this.handleToggle(e)} href="#"><span className="dot"/>Option 1</a>
<ul className={`list ${this.state.isHidden ? 'is-hidden' : ''}`}>
<li className="expanded">Sub</li>
<li className="expanded">Sub</li>
<li className="expanded">Sub</li>
</ul>
</li>
</ul>
</div>
<div className="filterLine">
</div>
</div>
);
}
}
导出默认的LeftMenuBar;
这是CSS:
.LeftMenu {
position: absolute;
left: 0;
width: 200px;
height: 400px;
z-index: 3;
}
.filterLine {
position: absolute;
width: 1px;
left: 75px;
top: 180px;
background-color: black;
height: 100%;
}
.LeftMenu.logo {
width: 50px;
height: 50px;
}
.filterList {
position: absolute;
top: 200px;
left: 75px;
}
#filterOption {
position: relative;
list-style: none;
display: inline-block;
left: 0;
}
#filterOption a {
display: inline-block;
color: black;
padding-top: 0;
margin-top: 0;
}
.dot {
z-index: 3;
position: relative;
border: 5px solid #e9e9e9;
height: 20px;
width: 20px;
background-color: black;
border-radius: 50%;
display: inline-block;
left: -20px;
}
.ul-style {
position: absolute;
padding: 0;
list-style-type: none;
top: 360px;
width: 95px;
}
.list.is-hidden {
display: none;
}
li a {
color: black;
}
.expanded {
display: block;
left: 0;
list-style-type: none;
margin: 0;
padding: 0;
}
答案 0 :(得分:0)
我需要将上级选项和样式跨度向上推,子选项的底部是上级选项和跨度所在的位置。
将CSS替换为以下内容,以查看flexbox的几行内容如何处理:
.LeftMenu {
width: 200px;
height: 400px;
}
.filterList {
display: flex;
align-items: flex-end;
height: 100%;
}
.is-hidden {
display: none;
}
这是一个演示沙箱:https://codesandbox.io/s/xr47k1wqlq