Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 使用div作为填充符_Css_Html - Fatal编程技术网

Css 使用div作为填充符

Css 使用div作为填充符,css,html,Css,Html,我很感激这可能是一个简单的问题,但我找不到答案 我有一个div。在这个div中我有3列(由div组成) 第一个div中有一些文本,第三个div中也有一些文本。我想让中间的div占据所有剩余的空间 我在绝对位置、固定位置和相对位置上都打过球 这就是我的意思: <div id="divheader"> <div style="float: left; width: 85px;">Caption to the left</div> <div s

我很感激这可能是一个简单的问题,但我找不到答案

我有一个div。在这个div中我有3列(由div组成)

第一个div中有一些文本,第三个div中也有一些文本。我想让中间的div占据所有剩余的空间

我在绝对位置、固定位置和相对位置上都打过球

这就是我的意思:

<div id="divheader">
    <div style="float: left; width: 85px;">Caption to the left</div>
    <div style="float: left; width: 100%;">this div has no caption but I want it to take up the remaining space</div>
    <div style="float: left; width: 185px;">caption to the right</div>
</div>
<div id="divpage">
    stuff
</div>
<div id="divfooter">
    footer stuff

左边的标题
这个div没有标题,但我希望它占用剩余的空间
右边的标题
东西
页脚材料

您可以使用
表格单元格
显示来实现此目的

HTML:

<div class="divided">
    <div style="width: 85px;">Caption to the left</div>
    <div>this div has no caption but I want it to take up the remaining space</div>
    <div style="width: 185px;">caption to the right</div>
</div>
.divided {
   display: table;
}
.divided > div {
    display: table-cell;
}

  • :适用于现代浏览器

你可以把最后一个div正确地放置,不用担心中间有一个div,如果你没有使用它的话。

<div>
    <div style="float: left; width: 85px;">Caption to the left</div>
    <div style="float: right; width: 185px;">caption to the right</div>
</div>

左边的标题
右边的标题

您可以使用显示表(这样做的好处是它还可以保持所有三列的高度相同):


左边的标题
这个div没有标题,但我希望它占用剩余的空间
右边的标题

或者,如果您希望它与旧浏览器更兼容,则可以使用填充和负边距:

<div style="padding:0 185px 0 85px">
    <div style="float: left; width: 85px; margin-left:-85px;">Caption to the left</div>
    <div style="float: left; width: 100%;">this div has no caption but I want it to take up the remaining space</div>
    <div style="float: right; width: 185px; margin-right:-185px;">caption to the right</div>
</div>

左边的标题
这个div没有标题,但我希望它占用剩余的空间
右边的标题

您希望中间的div有任何格式,还是纯粹为了使最后一个div正确?谢谢您的关注。我希望最后一节课向右转。但请记住,这是我的页眉,我将有一个div页面和div页脚(我将修改问题)+1:对于解决方案:)我应该做同样的:)嗨,谢谢你。信息量很大。我更喜欢@fraggy的答案,但我可能会在其他地方使用它,我希望中间的差异有一些内容/格式+谢谢你。这适合我现在的需要。嗨,谢谢你。信息量很大。我更喜欢@fraggy的答案,但我可能会在其他地方使用它,我希望中间的差异有一些内容/格式+1.
<div style="padding:0 185px 0 85px">
    <div style="float: left; width: 85px; margin-left:-85px;">Caption to the left</div>
    <div style="float: left; width: 100%;">this div has no caption but I want it to take up the remaining space</div>
    <div style="float: right; width: 185px; margin-right:-185px;">caption to the right</div>
</div>