gpt4 book ai didi

html - 包含 float 子项的元素的宽度自动问题

转载 作者:太空宇宙 更新时间:2023-11-04 14:25:24 27 4
gpt4 key购买 nike

这种奇怪的行为快把我逼疯了。如果我在服务器上上传页面,第一次在 chrome/safari 打开它时,我遇到了这个问题:

enter image description here

如果我刷新它,或者当我在本地处理页面时,完全没有问题。

enter image description here

nav 根本不会扩展其 width: auto 以适应所有 a float 元素。

这是非常简单的代码(我删除了不相关的规则,但知道我使用的是网络字体是否有用):

html:

<nav>
<a href="#">button</a>
<a href="#">button</a>
<a href="#">button</a>
<div class="clear"></div>
</nav>

CSS:

nav {
position: absolute;
top: 50%;
margin-top: -17px;
width: auto;
height: 33px;
}

nav > a {
box-sizing: border-box;
display: block;
float: left;
padding: 11px 13px;
height: 100%;
border: 1px solid #7a7e7f;
}

div.clear {
clear: both;
}

最佳答案

基本上将导航元素的宽度设置为 100% 就可以了。这是一个优化的例子:

HTML

<nav>
<a href="#">button</a>
<a href="#">button</a>
<a href="#">button</a>
</nav>

CSS

nav {
position: absolute;
top: 50%;
margin-top: -17px;
width: 100%;
overflow: hidden; /* Makes the clearing div obsolete */
}

nav > a {
box-sizing: border-box;
float: left;
padding: 11px 13px;
border: 1px solid #7a7e7f;
}

在 Codepen 上查看:http://codepen.io/zitrusfrisch/pen/Jcirx

关于html - 包含 float 子项的元素的宽度自动问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19597240/

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