我正在尝试使用字体图标作为背景图像,我使用flexbox水平和垂直居中。我把它设置在身体上。
我希望所有其他内容都在font-icon之上,而我使用相同的flex属性来集中内容。
我在codepen创建了一支笔。
------ HTML -------------
<div class="module-card">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem possimus ipsam commodi consequuntur quo dolor ad cupiditate blanditiis perferendis maiores incidunt dolores similique officiis a provident, obcaecati temporibus! Culpa, reprehenderit.</p>
</div>
----- -------------的CSS
body{
display: flex;
align-items: center;
justify-content: center;
height:100vh;
z-index:-1;
}
body:before {
content: "\f113";
font-family: FontAwesome;
/*--adjust as necessary--*/
color: blue;
font-size: 30em;
text-shadow: 2px 2px #ff0000;
}
.module-card {
width:50%;
background: #fff;
padding: 10px;
display: flex;
flex-direction: column;
background: rgba(0,191,255,0.2);
z-index:9999;
}
是否可以这样做而不是背景图像?
感谢, 苏海尔。
答案 0 :(得分:1)
只需要将你的html / css修改为类似这样的内容:http://codepen.io/anon/pen/EVLpGq
HTML:
<div class="someother-dif">
<div class="module-card">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatem possimus ipsam commodi consequuntur quo dolor ad cupiditate blanditiis perferendis maiores incidunt dolores similique officiis a provident, obcaecati temporibus! Culpa, reprehenderit.</p>
</div>
</div>
CSS:
body{
display: flex;
align-items: center;
justify-content: center;
height:100vh;
z-index:-1;
}
/*replace the content value with the
corresponding value from the list below*/
body:after {
content: "\f113";
font-family: FontAwesome;
/*--adjust as necessary--*/
color: blue;
font-size: 30em;
text-shadow: 2px 2px #ff0000;
z-index:1;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-decoration: inherit;
position: absolute;
font-size: 400px;
top: 50%;
left: 50%;
margin: -300px 0 0 -200px;
z-index: 1;
}
.someother-dif:after{
}
.module-card {
width:50%;
margin-left:auto;
margin-right:auto;
background: #fff;
padding: 10px;
display: flex;
flex-direction: column;
background: rgba(0,191,255,0.2);
z-index:9999;
position:relative;
}
答案 1 :(得分:1)
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height:100vh;
z-index:-1;
position: relative;
}
body::after {
content: "\f113";
font-family: FontAwesome;
color: blue;
font-size: 30em;
text-shadow: 2px 2px #ff0000;
}
.module-card {
width:50%;
background: #fff;
padding: 10px;
display: flex;
/* flex-direction: column; */
background: rgba(0,191,255,0.2);
z-index:9999;
/* center and overlay content */
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}