gpt4 book ai didi

html - 使用 :after psudeo selector? 清除 float

转载 作者:行者123 更新时间:2023-11-28 12:15:37 27 4
gpt4 key购买 nike

所以我正在尝试做 float ,我需要使用 :after 技术,但它不起作用。我需要清除红色和蓝色框之后的 float 。我已经尝试了一切。这是我的代码:

<!doctype html>
<html>
<head>
<title>Floats!</title>

<style type="text/css">
/* Eric Meyer's Reset CSS v2.0 - http://cssreset.com */
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{border:0;font-size:100%;font:inherit;vertical-align:baseline;margin:0;padding:0}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:none}table{border-collapse:collapse;border-spacing:0}

/* apply a natural box layout model to all elements */


*, *:before, *:after {
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
}

@media only screen and (min-width: 768px){
html, body {
margin-top: 15%;
background: #000000;
}

.wrapper {
width: 90%;
margin: 0 auto;
padding: 1em;
background: #3e3d3b;
color: #fff;
}

.box {
border-width: 4px;
border-style: solid;
height: 100px;
margin-bottom: 1em;
}

.red {
background: #ab331c;
border-color: #6f2011;
width: 32%;
float: right;
margin-right: 34%;

}

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

.blue {
background: #4d6bb6;
border-color: #243255;
width: 66%;
}

.green {
background: #6bbf85;
border-color: #2c4e36;
width: 32%;
margin-left: 34%;
}

.purple {
background: #9a74bb;
border-color: #503d62;
width: 32%;
float:right;
margin-top: -18%;
}

.orange {
background: #c09344;
border-color: #664e23;
width: 32%;
float:left;

}

.yellow {
background: #f0e192;
border-color: #726a44;
height: 212px;
float: right;
width: 32%;
margin-top: -17.5%;
}

.hotpink {
background: #d15ecf;
border-color: #612b60;
width: 32%;
float:left;

}
}



</style>
</head>
<body>

<div class="wrapper">
<div class="box hotpink" id="red"></div>
<div class="box red"></div>

<!-- <div style="clear: both;"></div> -->

<div class="box yellow"></div>
<div class="box blue"></div>

<!-- <div style="clear: both;"></div> -->

<div class="box orange"></div>
<div class="box green"></div>
<div class="box purple"></div>
</div>

</body>
</html>

带有“clear”的 div 适合我,但 :after 伪选择器不适合我。我不知道我是针对错误的元素还是什么。到目前为止,我已经尝试过(对于红色框):

.box.red:after
.box:after
.red:after
.box .red:after
.box red:after

到目前为止,没有任何效果。请帮忙。

编辑:这是 http://jsfiddle.net/vQRRU/

最佳答案

好吧,您需要稍微调整宽度和边距,但只需将 clear: both; 添加到 .blue 即可完成。如果是需要使用 :after:before 之类的家庭作业,那么在我吃完墨西哥卷饼后,我将不得不重新考虑一分钟。

关于html - 使用 :after psudeo selector? 清除 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19200521/

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