gpt4 book ai didi

html - 没有计算器的三个 float 列

转载 作者:行者123 更新时间:2023-11-28 10:24:33 24 4
gpt4 key购买 nike

我在此处询问并回答了有关带有悬垂和 float Logo 的三列布局的问题:

Three Column CSS Layout

答案是有问题的,因为 CSS 的“计算”功能不受支持,尤其是在移动设备上,导致三列在较小的设备上堆积到左侧。那么在不使用 calc 的情况下解决这个三列布局问题的方法可能是什么?

HTML:

<body>
<div class="container">
<div class="topcontain cf">
<div class="topleft">testing left</div>
<div class="topcenter"><img class="" src="http://s3.postimg.org/4smfaxjtb/toutdemo.png"></div>
<div class="topright">testing right</div>
</div>
<div class="bodypart">
<div class="logo"><img src="http://s3.postimg.org/o974xgexb/demologo.png"></div>
<div class="bodycopy">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facere, voluptas, nobis consequatur natus odit incidunt doloribus ipsa cum commodi dolor nostrum id saepe illo harum provident explicabo pariatur autem. Quam.</p>
ETC...
</div>
</div>
</div>
</body>

...和CSS:

.container {
text-align: center;
}
.topcontain {
width:80%
text-align:center;
/*overflow: hidden;*/
border:1px solid #f00;
height:75px;
position:relative;
}
.topcontain > div {     -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
box-sizing: border-box;}
.topleft {
/*margin:auto;*/
width:35%;
width: calc(50% - 128px); /*not working on mobile, safari*/

float:left;
border:1px solid #00f;
}
.topcenter {
width:256px;
float:left;
border:1px solid #0f0;
}
.topright {
float:right;
width:35%;
width: calc(50% - 128px); /*not working on mobile, safari*/

border:1px solid #ff0;
}

.bodycopy {
text-align:left;
}
.logo { clear: left; }

.cf:before,
.cf:after {
content: " "; /* 1 */
display: table; /* 2 */
}

.cf:after {
clear: both;
}

/**
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.cf {
*zoom: 1;
}

在这里 fiddle :http://jsfiddle.net/Znz2P/10/

最佳答案

您可以使用 display: table/table-cell。

因此,对于包装器,您设置 display: table;对于 3 个 div,您设置 display: table-cell;对于中间的 div,你设置 width: 256px;

作为表格单元格,其他 2 个 div 将具有相同的宽度 -> (wrapper width - 256)/2

.topcontain { display: table; }
.topcontain > div { display: table-cell; }
.topcenter { width: 256px; }

http://jsfiddle.net/Znz2P/14/

关于html - 没有计算器的三个 float 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23793282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com