【发布时间】:2019-07-10 13:27:03
【问题描述】:
我正在尝试使用以下代码对齐文本中心,但它不起作用。我的代码笔link 和代码:
body {
padding: 0;
margin: 0;
}
.container {
width: 1200px;
overflow: auto;
margin: 240px auto;
background: transparent;
position: relative;
}
.container .box {
position: relative;
float: left;
width: calc(400px - 30px);
height: calc(300px - 30px);
background: yellow;
overflow: hidden;
margin: 15px;
border-radius: 10px;
box-sizing: border-box;
}
.container .box .icon {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: red;
transition: 0.5s;
z-index: 1;
}
.container .box:hover .icon {
top: 20px;
left: calc(50% - 40px);
width: 80px;
height: 80px;
border-radius: 50%;
}
.container .box .icon .fa {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 80px;
color: #fff;
transition: 0.5s;
}
.container .box:hover .icon .fa {
font-size: 40px;
}
.container .box .content {
position: absolute;
top: 100px;
height: calc(100% - 100px);
padding: 20px;
box-sizing: border-box;
transition: 0.5s;
text-align: center;
}
<div class="container">
<div class="box">
<div class="icon">
<i class="fa fa-search" aria-hidden="true"></i>
</div>
<div class="content">
<h3>Search</h3>
<p>sadfdfoiljwkjfensadfdfoiljwkjfensadfdfoiljwkjfensadfdfoiljwkjfensadfdfoiljwkjfen</p>
</div>
</div>
</div>
【问题讨论】:
标签: html css flexbox css-position centering