gpt4 book ai didi

html - 使用clearfix取消 float

转载 作者:行者123 更新时间:2023-11-28 08:06:45 25 4
gpt4 key购买 nike

在学习 CSS 的过程中,我尝试使用 clearfix 制作准确的示例,您可以在下面的链接中看到(对于非英语文本,我很抱歉,但我没有其他的) http://htmlbook.ru/files/images/layout2/3-41.png我需要使用 floatclearfix hack

我的代码是:HTML

<!DOCTYPE html>
<html>
<head>
<title>Learning float</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="float.css">
</head>
<div class="col1 clearfix"><h3>Menu</h3>
<p>Best photo</p>
<p>By ages</p>
<p>Rate</p>
<p>By comments</p>
</div>
<div class="col2">
<div class="photo">
<p><img src="http://churchs.kiev.ua/images/stories/Hrams/Myzej/Sofia_kievsk_1.jpg" alt="" /></p>
<p class="caption">Софийский собор</p>
</div>
<div class="photo clearfix">
<p><img src="http://rybinsk.go2all.ru/imgs/92/1/85222.jpg" alt="" /></p>
<p class="caption">Польский костёл</p>
</div>
<p>This text should be below photos</p>
</div>
<p>This text should go below the columns</p>

<div class="footer">Подвал</div>
</body>
</html>

CSS

.col1 {
background-color: #BDBDBD;
width: 250px;
margin-right: 10px;
float: left;
}

.col2 {
background-color: #A9F5F2;
float: left;
width: 500px;
}

.photo {
float: left;
margin-right: 10px;
width: 170px;
}

img {
width: 150px;
height: 150px;
}

.clearfix:after {
content: " ";
visibility: hidden;
display: block;
height: 0;
clear: both;
}

.footer {
position: absolute;
left: 0;
bottom: 0;
width: 100%;
background-color: green;
text-align: center;
}

使用 clearfix 有什么问题。

将不胜感激任何答案!

最佳答案

clearfix:after 'method' 用于当容器不在position absolutefixed 时包装 float 子元素, float 或显示:inline-blockinline-tabletable。在您的情况下,您要清除的元素位于 float 元素之后,您只需要 clear 它们。 两者


http://www.w3.org/wiki/CSS/Properties/clear


.col1 {
background-color: #BDBDBD;
width: 250px;
margin-right: 10px;
float: left;
}

.col2 {
background-color: #A9F5F2;
float: left;
width: 500px;
}

.photo {
float: left;
margin-right: 10px;
width: 170px;
}

img {
width: 150px;
height: 150px;
}

.clearfix {
clear: both;
}

.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: green;
text-align: center;
}

/* add some space to clear the footer */
body {
padding-bottom:2em;/* average height of current footer: tune it if needed */
min-width:800px;
}
<div class="col1 "><h3>Menu</h3>
<p>Best photo</p>
<p>By ages</p>
<p>Rate</p>
<p>By comments</p>
</div>
<div class="col2">
<div class="photo">
<p><img src="http://churchs.kiev.ua/images/stories/Hrams/Myzej/Sofia_kievsk_1.jpg" alt="" /></p>
<p class="caption">Софийский собор</p>
</div>
<div class="photo clearfix">
<p><img src="http://rybinsk.go2all.ru/imgs/92/1/85222.jpg" alt="" /></p>
<p class="caption">Польский костёл</p>
</div>
<p class="clearfix">This text should be below photos</p>
</div>
<p class="clearfix">This text should go below the columns</p>

<div class="footer">Подвал</div>

关于html - 使用clearfix取消 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29456054/

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