如何在使用多个类的单个元素上使用多个CSS伪类 :: before 。
这是我的代码:
.how-it-works,
.works .one,
.works .two,
.works .three,
.works .four,
.works .five,
.works .six,
.works .seven {
position:relative;
}
.how-it-works:before,
.works .one:before,
.works .two:before,
.works .three:before,
.works .four:before,
.works .five:before,
.works .six:before,
.works .seven:before {
content: "\f11b";
font-family: FontAwesome;
left:-5px;
position:absolute;
top:0;
-webkit-transform: rotate(30deg);
-moz-transform: rotate(30deg);
-ms-transform: rotate(30deg);
-o-transform: rotate(30deg);
transform: rotate(30deg);
}
.works .one:before {content: "\f091";}
.works .two:before {content: "\f04b";}
.works .three:before{content: "\f10b";}
.works .four:before {content: "\f108";}
.works .five:before {content: "\f109";}
.works .six:before {content: "\f26c";}
.works .seven:before{content: "\f1e6";}

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<body class="works">
<div class="container-fluid">
<div class="row">
<div class="how-it-works one two three four five six seven col-xs-12 col-md-10 col-md-offset-1">
<h1><span>How It Works</span></h1>
</div>
</div>
</div>
</body>
&#13;
我想用这段代码做什么:在div元素的背景中,每个字体都很棒的图标并排显示不同的位置。并在x和y轴上重复。
答案 0 :(得分:0)
.how-it-works
类,并仅更改content
属性。例如:
.how-it-works:before {
content: "\f11b";
font-family: FontAwesome;
left: -5px;
position: absolute;
top: 0;
-webkit-transform: rotate(30deg);
-moz-transform: rotate(30deg);
-ms-transform: rotate(30deg);
-o-transform: rotate(30deg);
transform: rotate(30deg);
}
.how-it-works.one:before {content: "\f091";}
.how-it-works.two:before {content: "\f04b";}
.how-it-works.three:before{content: "\f10b";}
.how-it-works.four:before {content: "\f108";}
.how-it-works.five:before {content: "\f109";}
.how-it-works.six:before {content: "\f26c";}
.how-it-works.seven:before{content: "\f1e6";}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<div class="container-fluid">
<div class="row">
<div class="col-md-10 col-md-offset-1 how-it-works">—</div>
<div class="col-md-10 col-md-offset-1 how-it-works one">1</div>
<div class="col-md-10 col-md-offset-1 how-it-works one two">1 2</div>
<div class="col-md-10 col-md-offset-1 how-it-works one two three">1 2 3</div>
<div class="col-md-10 col-md-offset-1 how-it-works one two three four">1 2 3 4</div>
<div class="col-md-10 col-md-offset-1 how-it-works one two three four five">1 2 3 4 5</div>
<div class="col-md-10 col-md-offset-1 how-it-works one two three four five six">1 2 3 4 5 6</div>
<div class="col-md-10 col-md-offset-1 how-it-works one two three four five six seven">1 2 3 4 5 6 7</div>
</div>
</div>
<span>
标记。例如:
.how-it-works:before,
.how-it-works .one:before,
.how-it-works .two:before,
.how-it-works .three:before,
.how-it-works .four:before,
.how-it-works .five:before,
.how-it-works .six:before,
.how-it-works .seven:before {
display: inline-block;
font-family: FontAwesome;
-webkit-transform: rotate(30deg);
-moz-transform: rotate(30deg);
-ms-transform: rotate(30deg);
-o-transform: rotate(30deg);
transform: rotate(30deg);
}
.how-it-works:before {content: "\f11b";}
.how-it-works .one:before {content: "\f091";}
.how-it-works .two:before {content: "\f04b";}
.how-it-works .three:before{content: "\f10b";}
.how-it-works .four:before {content: "\f108";}
.how-it-works .five:before {content: "\f109";}
.how-it-works .six:before {content: "\f26c";}
.how-it-works .seven:before{content: "\f1e6";}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<div class="container-fluid">
<div class="row">
<div class="col-md-10 col-md-offset-1 how-it-works">—</div>
<div class="col-md-10 col-md-offset-1 how-it-works"><span class="one">1</span></div>
<div class="col-md-10 col-md-offset-1 how-it-works"><span class="one"><span class="two">1 2</span></span></div>
<div class="col-md-10 col-md-offset-1 how-it-works"><span class="one"><span class="two"><span class="three">1 2 3</span></span></span></div>
<div class="col-md-10 col-md-offset-1 how-it-works"><span class="one"><span class="two"><span class="three"><span class="four">1 2 3 4</span></span></span></span></div>
<div class="col-md-10 col-md-offset-1 how-it-works"><span class="one"><span class="two"><span class="three"><span class="four"><span class="five">1 2 3 4 5</span></span></span></span></span></div>
<div class="col-md-10 col-md-offset-1 how-it-works"><span class="one"><span class="two"><span class="three"><span class="four"><span class="five"><span class="six">1 2 3 4 5 6</span></span></span></span></span></span></div>
<div class="col-md-10 col-md-offset-1 how-it-works"><span class="one"><span class="two"><span class="three"><span class="four"><span class="five"><span class="six"><span class="seven">1 2 3 4 5 6 7</span></span></span></span></span></span></span></div>
</div>
</div>
PS。 .col-md-10
相当于.col-xs-12 .col-md-10
。
PPS。默认情况下,Bootstrap的列具有position: relative;
属性。