具有最小宽度和最大宽度的 HTML 全屏布局

标签 html css

我有一个元素(例如一个 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>

Demo | FullScreen

最佳答案

可能重复:Make a div fill the remaining screen space

还有一个: How to make a div to fill a remaining horizontal space (a very simple but annoying problem for CSS experts)

编辑: 看看我使用我之前提供的解决方案之一做了什么:

<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;             
}

jsFiddler Code | jsFiddler FullScreen

关于具有最小宽度和最大宽度的 HTML 全屏布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6435695/

相关文章:

html - 如何在 Google Apps 脚本中将 css 连接到 html

css - div 内的全 Angular 背景颜色

css - jquery使默认导航栏按钮处于事件状态

css - Windows 8 - 使用图像作为背景

javascript - Angular 6 - 是否可以在同一页面上使用两个 Angular 元素组件?

html - 如何使用 JQuery 从动态 html 表中获取选定的行值?

javascript - 在WebStorm中粘贴后如何使代码对齐?

html - 顺风 : equal height columns

html - 如何将文本/标题放在图像上?

javascript - 如果窗口调整大小,jQuery 检查元素的 css 属性