css - 弹出框显示在左上角,因为 div 的宽度非常小,例如 < 2.5 px
问题描述
我在我的 react js 代码中使用了 reactstrap popover。Popover 显示在左上角,因为 div 的宽度几乎小于 2.5px
我正在使用下面提到的版本“reactstrap”:“^7.0.1”,“react”:“^16.3.2”,
<Popover placement="bottom" style={{ backgroundColor: 'lightgrey', textAlign: 'left', width: '235px' }} isOpen={this.props.popoverVisible} target={this.props.target}>
<PopoverBody>
<div>
{this.getPopOverName(this.props.item)}
<div><b>Start: </b>{this.dateObject.start}</div>
<div><b>End: </b>{this.dateObject.end}</div>
</div>
</PopoverBody>
</Popover>
![在此处输入图像描述[1]][1]
解决方案
从您在评论中的 stackblitz中,从您的 styles.css 中删除该属性以获得与我在这里建议border-style:solid;
的相同的结果
相关的 CSS:
.tinyDiv{
background:red; height:10px; width:3px; margin-left:10%;
/* border-style:solid; */
border-width:2px;
border-color:blue;
}
相关JS:
class MyPopOver extends React.Component {
constructor(props) {
super(props);
this.state = {
popoverOpen: false
};
}
onHover = () => {
this.setState({
popoverOpen: true,
})
}
onHoverLeave = () => {
this.setState({
popoverOpen: false,
})
}
render() {
return (<>
<div className='tinyDiv' id="Popover1" onMouseEnter={this.onHover}
onMouseLeave={this.onHoverLeave}>
<Popover placement="bottom" isOpen={this.state.popoverOpen} target="Popover1" style={{ backgroundColor: 'lightgrey'}}>
<PopoverBody>Sed posuere consectetur est at lobortis. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.</PopoverBody>
</Popover>
</div></>
)
}
}
推荐阅读
- ubuntu - 为什么 POI(excel 文件)在不同的 ubuntu 系统上创建不同
- javascript - 是否可以使用 discordjs 机器人命令设置自定义不和谐存在/活动/状态?
- c# - 是否可以更改 WinFormCore DataGridViewCell 中的 cell.value
- azure-data-factory - 自动创建的表的 Azure 数据工厂复制活动自定义架构名称
- python - 使用神经网络根据体重和身高预测年龄
- reactjs - 使用 npx create-react-app my-app 时出错
- proxy - Spring Cloud Gateway - 路由代理
- php - 如何比较一个列数组和另一个?
- node.js - 在 Node JS 中使用 Fluent FFMPEG 从屏幕截图创建视频缩略图
- javascript - 如何从 Handlebars 模板中获取部分