css - 一个框决定高度,其他宽度
拥有两个 div 的最佳方式是什么,左右相邻,一个决定宽度,另一个决定高度:
CSS:
body
{
width:960px;
margin:auto;
}
.wholething
{
background-color:red;
}
.leftside
{
width:230px;
background-color:blue;
}
.rightside
{
height:640px;
background-color:green;
}
HTML:
<div class="wholething">
<div class="leftside">
</div>
<div class="rightside">
</div>
</div>
结果看起来像一个蓝色框,宽 230 像素,高 640 像素,并且一个绿框,宽 730 像素,高 640 像素。然后,如果 CSS 的宽度或高度发生变化,两个框都会相应调整。请仅添加到CSS;除非绝对必要,否则不要删除 css。
What is the best way to have two divs, left and right of each other, where one dictates the width, and the other dictates the height:
CSS:
body
{
width:960px;
margin:auto;
}
.wholething
{
background-color:red;
}
.leftside
{
width:230px;
background-color:blue;
}
.rightside
{
height:640px;
background-color:green;
}
HTML:
<div class="wholething">
<div class="leftside">
</div>
<div class="rightside">
</div>
</div>
The result would look like a blue box 230px wide and 640 px high, and a green box 730 px wide and 640 px high. Then, if the CSS is changed for width or height, both boxes will adjust accordingly. Please only add to the css; do not remove css unless absolutely necessary.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那会起作用的。但是,您需要更改第二个的
left
以匹配第一个的width
。That'll work. However you will need to change the
left
of the second one to match thewidth
of the first.