提问人:Ship 提问时间:5/7/2022 最后编辑:Ship 更新时间:5/7/2022 访问量:33
漂浮时高度实际上没有变化
Height not actually changing hieght while floating
问:
现在,我正在编写一个具有两列布局的菜单。这是代码。
HTML格式:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>replit</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="stockapps">
<img src="icons/eShop.svg">
<img src="icons/sverse.svg">
</div>
<div class="main">
<p>
Hello!
</p>
</div>
</body>
</html>
CSS:
.stockapps {
background-color: #111;
float: left;
width: 5%;
height: 100%;
}
.stockapps :after {
content: "";
display: table;
clear: both;
}
.stockapps img{
width:100%;
display: inline;
vertical-align: top;
}
.main {
float: left;
padding: 2%;
width: 91%;
overflow: hidden;
}
问题在于 stockapps div 标签没有用高度填充整个屏幕,而是选择仅填充子对象所占用的区域。
我尝试使用清除修复并将溢出设置为隐藏,但似乎都没有解决问题。这可能是一些初学者的错误,因为CSS不是我的强项
这把小提琴展示了这个问题。
答:
0赞
Martin Lévai
5/7/2022
#1
如果我理解正确,您需要为您的菜单创建一个 2 列布局。
为了实现这种布局,我会将 和 包装到另一个带有 class of 的 和 中,并添加以下 CSS 样式:<div class="stockapps">
<div class="main">
<div>
manu-wrap
.menu-wrap {
display: flex;
justify-content: space-between;
}
然后,我将删除这些属性,您应该有一个有效的 2 列布局。float
你可以在这里找到更多关于的信息。display: flex
评论
0赞
Ship
5/7/2022
这似乎没有改变任何事情。这把小提琴展示了这个问题。
0赞
Salwa A. Soliman
5/7/2022
#2
您可以将 stockapps 和 main div 包装到容器 div 中
设置此容器的样式,如下所示
我使用了 stockapps div 的背景颜色来显示它的高度
.container {
display: flex;
align-items: stretch;
/*Set height as you want, you can use height in px */
height: 100vh;
}
.stockapps {
/* used background-color to show you how much height it takes*/
background-color: #999;
/*You can ignore width if it's not convenient for your desired final output */
width: 50%
}
<div class="container">
<div class="stockapps">
<img src="icons/eShop.svg">
<img src="icons/sverse.svg">
</div>
<div class="main">
<p>
Hello!
</p>
</div>
</div>
评论
0赞
Ship
5/8/2022
这修好了!泰斯姆!
评论