gpt4 book ai didi

HTML/CSS : How can I float the 'a href' elements to the left without them leaving the div element that they are inside in?

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

我有下面的演示代码:

<html>
<head>
<style type="text/css">
a{
display:block;
float:left;
}
#linkDiv{
border-style:solid;
}
</style>
</head>
<body>
<div id="linkDiv">
<a href="">test</a>
<a href="">test</a>
<a href="">test</a>
</div>
</body>
</html>

我希望我的链接是 block 状的,而且每个链接都彼此相邻。没有 float:left 这就是我得到的:

enter image description here

然而,当我使用 float:left 时,结果是这样的:

enter image description here

提前致谢

最佳答案

您需要在父元素上使用“clearfix”:

overflow: hidden;

或者

/**
* For modern browsers
* 1. The space content is one way to avoid an Opera bug when the
* contenteditable attribute is included anywhere else in the document.
* Otherwise it causes space to appear at the top and bottom of elements
* that are clearfixed.
* 2. The use of `table` rather than `block` is only necessary if using
* `:before` to contain the top-margins of child elements.
*/
.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;
}

http://nicolasgallagher.com/micro-clearfix-hack/

关于HTML/CSS : How can I float the 'a href' elements to the left without them leaving the div element that they are inside in?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13752679/

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