javascript - 为什么在 React 项目的 CSS 中添加水平滚动条时 div 的大小会减小?
问题描述
请参考这张图片。在此处输入图像描述
两个列表中的卡片具有相同的尺寸。但在第二个列表中,我启用了滚动。启用它后,尺寸突然发生变化,事情变得笨拙。
我附上源代码:
const cast_lists = this.state.cast.map(ar =>{
return(
<Card style={{ width: 120, height : 230, borderColor : "black", borderWidth: 1, borderStyle : "solid", marginLeft: 5, position: "relative"}}>
<Card.Img variant="top" src={"https://image.tmdb.org/t/p/w500" + ar.profile_path} style = {{height: 150, width: 120, marginLeft: -60, borderColor : "black", borderWidth: 10, position: "relative"}} />
<Card.Body>
<Card.Title style = {{paddingTop: 150, paddingLeft: 0, fontWeight: "bold"}}> {ar.name} </Card.Title>
<Card.Body>{ar.character}</Card.Body>
</Card.Body>
</Card>
)
})
作为渲染的回报,代码是:
<div className = {styles.top}>
<h2>Top Crew</h2>
<div style = {{display: "flex", flexDirection : "row", overflow: "auto"}}>
{crew_lists.slice(0,5)}
</div>
<h2>Top Crew</h2>
<div style = {{display: "flex", flexDirection : "row", overflowX: "scroll", width: 500}}>
{cast_lists}
</div>
</div>
styles.top 将高度和宽度设置为 100%。请帮我解决这个问题。
解决方案
你试过width: 500
从第二个中删除吗div
推荐阅读
- javascript - SocketIO 的问题
- javascript - 在 Angular 中,当我不知道扩展名时如何加载图像?
- r - 使用 %in% 根据染色体和位置过滤行
- recurrence - 基本递归函数的运行时复杂性
- c# - 使用 MySql 数据库文件 (XAMPP) 发布 Visual Studio 软件
- python - 将字典列表转换为字典
- c# - 有没有办法在 Azure Data Lake Store 上使用 SSIS 处理“任何文件”?
- html - 如何使用 Bootstrap 4 垂直对齐列内的内容
- git - 在远程分支中查找文件的最后提交 ID
- python - 如何在 Tkinter 中将按钮连接到字典