我正在使用react-select,并且产生了一些下拉列表。但是,当我单击顶部的div时,它会将下面的底部推入。我正在使用flex内联显示它们。有人可以帮我解决以下问题吗?非常感谢您的帮助!
我对CSS / React非常陌生。请帮我。下面是代码:
const customStyles = {
control: (provided, state)=> ({
...provided,
width: 210,
position: 'relative',
top: 40,
// height: 25,
// minHeight: 10,
// overflow:'hidden'
}),
menu: (provided, state) => ({
...provided,
width: 210,
position: 'relative',
top: 40
}),
menulist: (provided, state) => ({
...provided,
width: 210,
}),
option: (provided, state) => ({
...provided,
width: 210,
height: 24,
minHeight: 15,
paddingTop:0,
fontSize: '0.8em',
}),
placeholder: (provided, state) => ({
...provided,
fontSize: '0.8em',
color: colourOptions[1].color,
fontWeight: 400,
// position: 'relative',
// top: 2,
overflow:'hidden'
}),
multiValue: (styles, { data }) => {
const color = colourOptions[0].color;
return {
...styles,
backgroundColor: colourOptions[0].color
};
},
multiValueLabel: (styles, { data }) => ({
...styles,
color: 'white',
height: 18,
minHeight: 15,
fontSize:12,
paddingTop:0
}),
multiValueRemove: (styles, { data }) => ({
...styles,
color: colourOptions[1].color,
':hover': {
backgroundColor: colourOptions[0].color,
color: 'white',
},
}),
dropdownIndicator : (styles, { data }) => ({
...styles,
color: colourOptions[1].color,
size:6,
':hover': {
color: colourOptions[0].color,
},
}),
};
class DefectsContainer extends Component {
state = {
teams: [{ value: 'a', label: 'Alpha' },
{ value: 'b', label: 'Beta' },
{ value: 'c', label: 'Gamma' }],
selectedOption:null
};
handleChange = selectedOption => {
this.setState(
{ selectedOption },
() => console.log(`Option selected:`, this.state.selectedOption)
);
};
render() {
const { selectedOption } = this.state;
return (
<div className="defect-dashboard-main-div">
<div className="defect-dashboard-container">
<div className="filterContainer">
<div className="filterChildDiv">
<label className="filterHeader">Project</label>
<Select className="select-teams" closeMenuOnSelect={false} isMulti options={this.state.teams}
autosize={false} value={selectedOption} onChange={this.handleChange} styles={customStyles}
placeholder="Select Project(s)..." theme={theme => ({
...theme,
borderRadius: 3,
borderColor: colourOptions[0].color,
colors: {
...theme.colors,
primary25: 'hotpink'
}
})}
/>
</div>
<div className="filterChildDiv">
<label className="filterHeader">Category</label>
<Select className="select-teams" closeMenuOnSelect={false} isMulti options={this.state.teams}
autosize={false} value={selectedOption} onChange={this.handleChange} styles={customStyles}
placeholder="Select Category..." theme={theme => ({
...theme,
borderRadius: 3,
borderColor: colourOptions[0].color,
colors: {
...theme.colors,
primary25: 'hotpink'
}
})}
/>
</div>
....
我的CSS文件:
.filterContainer{
box-sizing: border-box;
display: flex;
flex-wrap: wrap;
}
.filterChildDiv{
flex: 1;
/* float: left; */
margin-right: 20px;
}
.defect-dashboard-table-env-main{
width:1400px!important;
height: 1050px!important;
position: absolute;
top:40px;
left:120px;
}
默认情况下,选择菜单的样式具有绝对位置,这可以通过从文档流中删除元素来使其覆盖其他元素。在您的自定义样式中,您将菜单位置设置为相对,因此打开菜单并将其插入文档流时,其他相对定位的元素也会移动。从customStyles.menu函数返回的对象中删除position: relative
将解决此问题。