CSS-启用“;“自动扩展”;内容超出宽度/高度参数时绝对定位的DIV

CSS-启用“;“自动扩展”;内容超出宽度/高度参数时绝对定位的DIV,css,wordpress-theming,Css,Wordpress Theming,这是一个奇怪的例子,但这里有: 当插入超出其边界的内容时,如何使绝对定位的DIV展开?代码如下: <html> <head> <style> * {margin: 0; padding: 0;} body {white-space: nowrap; text-align: center; color: white; font-size: 2em;} div#container {position: rel

这是一个奇怪的例子,但这里有:

当插入超出其边界的内容时,如何使绝对定位的DIV展开?代码如下:

<html>
<head>
    <style>
        * {margin: 0; padding: 0;}
        body {white-space: nowrap; text-align: center; color: white; font-size: 2em;}
        div#container {position: relative; height: 100px; width: 50px;}

        div#a {height: 50px; width: 25px; background-color: red; position: absolute; top: 0; left: 0;}
        div#b {height: 50px; width: 25px; background-color: blue; position: absolute; top: 0; right: 0}
        div#c {height: 50px; width: 25px; background-color: orange; position: absolute; bottom: 0; left: 0;}        
        div#d {height: 50px; width: 25px; background-color: purple; position: absolute; bottom: 0; right: 0;}

        span#title {position: relative; overflow: visible}
    </style>
</head>
<body>
    <div id="container">
        <div id="a"><span id="title">This is my title</span></div>
        <div id="b">B</div>
        <div id="c">C</div>
        <div id="d">D</div>
    </div>
</body>

*{边距:0;填充:0;}
正文{空白:nowrap;文本对齐:居中;颜色:白色;字体大小:2em;}
div#容器{位置:相对;高度:100px;宽度:50px;}
div#a{高度:50px;宽度:25px;背景色:红色;位置:绝对;顶部:0;左侧:0;}
div#b{高度:50px;宽度:25px;背景色:蓝色;位置:绝对;顶部:0;右侧:0}
div#c{高度:50px;宽度:25px;背景色:橙色;位置:绝对;底部:0;左侧:0;}
div#d{高度:50px;宽度:25px;背景色:紫色;位置:绝对;底部:0;右侧:0;}
span#title{位置:相对;溢出:可见}
这是我的头衔
B
C
D

在上面的示例中,DIV“a”中的内容是隐藏的(由于宽度/高度限制)。如果我们将其设置为“最小高度”和“最小宽度”,则内容仅位于其他div的“后面”,但不会移动它们。我怎样才能做到这一点

注意:我正试图解决这个问题,因为我需要“重新定位”HTML中div的顺序(我正试图在Wordpress中创建一个子模板)。非常感谢任何示例/资源

干杯,
Sapiensgladio

您可以使用
min height
min width
定义这些尺寸的最小值,这些值将根据需要扩展以容纳新的/附加的/更大的内容

您可以使用
max height
max width
属性,这将允许元素根据需要从标注的最小允许值移动到最大允许值

CSS示例:

#content {
    position: absolute;
    min-height: 5em;
    max-height: 15em;
    min-width: 5em;
    max-width: 15em;
    border: 1px solid #f90;
    bottom: 0.5em;
    right: 0.5em;
    overflow: auto;
}


上面的演示使用jQuery向
#content
div添加额外的内容,但这只是出于动态演示的目的,jQuery在任何方面都是而不是,css工作所必需的。

如果您需要重新定位div的顺序,从而真正改变事情,那么最好使用jQuery解决方案来重新排列元素。。