我有一个元素(例如一个 div 标签,它占用屏幕宽度的 1/3,最小宽度为 500px,最大宽度为 700px。在它旁边,还有另一个元素占用了屏幕的其余部分屏幕。如果我只分配 66% 的宽度,只要其他元素的高度不采用最大值之一,它就可以正常工作,此时会发生溢出或元素只是让空间溢出。
谁知道这是在没有构建过于复杂的 javaScript 脚本的情况下通过 html 完成的?
最好的问候, 斯特凡
编辑代码: 这个灵魂提供了一个简单的例子,只要网站小于500px,两者都是屏幕的50%,但如果变大,右边(标有world)应该填充超过50%。
<html>
<head>
<style type="text/css">
* {
border: 1px solid black;
}
html,body,.fullheight {
height: 99%;
width: 99%;
}
table {
table-layout: auto;
}
.minfield {
max-width: 250px;
border: 1px solid red;
overflow: hidden;
}
.leftfloat{
float: left;
}
.maxsize{
height: 99%;
width: 49%;
}
</style>
</head>
<body>
<div class="fullheight">
<div class="leftfloat minfield maxsize">
<p>hello</p>
</div>
<div class="leftfloat maxsize">
<p>world</p>
</div>
</div>
</body>
最佳答案
可能重复:Make a div fill the remaining screen space
编辑: 看看我使用我之前提供的解决方案之一做了什么:
<html>
<body>
<div class="fullHeight">
<div class="minField maxSize"><p>hello</p></div>
<div class="maxField maxSize"><p>World</p></div>
</div>
</body>
</html>
* {
border: 1px solid black;
}
html,body,.fullHeight {
height: 99%;
width: 99%;
}
.maxSize{
height: 99%;
}
.minField{
float:left;
width:250px; /* This is a must so you could define min/max */
max-width:250px;
width: expression(this.width > 250 ? 250: true); /* IE Hack for max-width */
background-color:#ff0000;
}
.maxField {
margin-left: 250px;
background-color:#00FF00;
}
关于具有最小宽度和最大宽度的 HTML 全屏布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6435695/