我有一个元素列表,我在元素(垂直线)之后添加了一个元素,我想将其居中,并且应该是响应式的。
这是我的解决方法
.profile_card-bottom {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
margin-bottom: 64px;
}
li::after {
-webkit-transition: all 0.15s ease-in-out;
transition: all 0.15s ease-in-out;
content: '';
display: block;
float: left;
background-color: #979797;
width: 1px;
opacity: 0.1;
height: 77px;
position: absolute;
bottom: 13px;
right: -57px;
}
li:nth-child(3n)::after {
display: none;
}
li:nth-child(4n)::after {
display: none;
}
.likes,
.following,
.followers,
.follow {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
position: relative;
}
.btn-follow {
background: $button-color;
border-radius: 100px;
border: none;
outline: none;
height: 92px;
width: 268px;
font-size: 30px;
color: #FFFFFF;
font-weight: 600;
letter-spacing: 4.2px;
position: relative;
right: 37px;
top: 9px;
text-transform: uppercase;
cursor: pointer;
}
.assets-count {
font-size: 48px;
color: $li-span-color;
letter-spacing: 0;
font-weight: 400;
}
.assets-title {
font-size: 20px;
color: $h1-span-color;
letter-spacing: 0;
line-height: 11px;
font-weight: $base-font-weight;
}
}
<ul class="profile_card-bottom">
<li class="likes"><span class="assets-count">124</span><span class="assets-title">Likes</span></li>
<li class="following"><span class="assets-count">727</span><span class="assets-title">Following</span></li>
<li class="followers"><span class="assets-count">4437</span><span class="assets-title">Followers</span></li>
<li class="follow"><button class="btn-follow">Follow</button></li>
</ul>
不幸的是,我的解决方案没有给我想要的结果,
我的解决方案在做什么错?任何帮助将不胜感激,谢谢
答案 0 :(得分:1)
我认为您可能会误解:after
生成的内容在文档流中的位置。
:: before和:: after生成的伪元素包含在元素的格式框中...
因此,after元素实际上并不是放置在<li>
的之后,而是放置在<li>
的子节点的末尾。
.profile_card-bottom {
display: flex;
justify-content: space-between;
}
li {
display: flex;
flex: 1 1 auto;
}
li:not(:last-child):after {
content: '';
display: block;
background-color: #979797;
width: 1px;
opacity: 1;
height: 77px;
margin: 0 auto;
height: 100%;
}
<ul class="profile_card-bottom">
<li class="likes"><span class="assets-count">124</span><span class="assets-title">Likes</span></li>
<li class="following"><span class="assets-count">727</span><span class="assets-title">Following</span></li>
<li class="followers"><span class="assets-count">4437</span><span class="assets-title">Followers</span></li>
<li class="follow"><button class="btn-follow">Follow</button></li>
</ul>
答案 1 :(得分:1)
它将与响应一起工作,请尝试以下代码
.profile_card-bottom {
display: flex;
justify-content: space-between;
padding: 0;
}
li {
display: inline-flex;
flex: 1 1 auto;
-webkit-flex-flow: row wrap;
flex-flow: row wrap;
-webkit-align-items: center;
align-items: center;
position: relative;
font-family: sans-serif;
}
li:not(:last-child):after {
content: '';
display: block;
background-color: #ccc;
width: 1px;
opacity: 1;
margin: 0 auto;
height: 100%;
position: absolute;
right: 0;
}
li span {
display: flex;
flex: 1 100%;
justify-content: center;
}
.btn-follow {
background: #FFA640;
border-radius: 50px;
border: none;
outline: none;
font-size: 3vh;
letter-spacing: 1px;
color: #FFFFFF;
font-weight: 600;
text-transform: uppercase;
display: flex;
flex: 1 80%;
justify-content: center;
padding: 7px 15px;
margin: 0 3px;
}
.assets-count {
font-size: 4.5vh;
color: #FFA640;
letter-spacing: 0;
font-weight: 400;
}
.assets-title {
font-size: 2.5vh;
color: #8298B9;
letter-spacing: 0;
font-weight: 200;
}
<ul class="profile_card-bottom">
<li class="likes"><span class="assets-count">124</span><span class="assets-title">Likes</span></li>
<li class="following"><span class="assets-count">727</span><span class="assets-title">Following</span></li>
<li class="followers"><span class="assets-count">4437</span><span class="assets-title">Followers</span></li>
<li class="follow"><button class="btn-follow">Follow</button></li>
</ul>
答案 2 :(得分:0)
我建议您使用div
而不是span
,这样就不需要使用CSS来使跨度成为阻塞(flex)。另外,请使用li:nth-child(-n + 2)::after
而不是使用新规则将最后两个li的样式分开。
请参见以下代码段:
* {
font-family: "calibri";
}
.profile_card-bottom {
display: flex;
justify-content: space-between;
}
li {
display: flex;
flex: 1 1 auto;
}
li:nth-child(-n + 2)::after {
content: '';
display: block;
background-color: #979797;
width: 1px;
opacity: 0.1;
height: 77px;
margin: 0 auto;
height: 100%;
}
li:nth-child(3n)::after {
display: none;
}
li:nth-child(4n)::after {
display: none;
}
li span {
display: block;
}
.btn-follow {
background: #FFA640;
border-radius: 100px;
border: none;
outline: none;
height: 50px;
width: 180px;
font-size: 20px;
color: #FFFFFF;
font-weight: 600;
letter-spacing: 4.2px;
position: relative;
right: 37px;
top: 9px;
text-transform: uppercase;
cursor: pointer;
}
.assets-count {
font-size: 38px;
color: #FFA640;
letter-spacing: 0;
font-weight: 400;
}
.assets-title {
font-size: 15px;
color: #8298B9;
letter-spacing: 0;
line-height: 11px;
font-weight: 200;
}
<ul class="profile_card-bottom">
<li class="likes"><div><span class="assets-count">124</span><span class="assets-title">Likes</span></div></li>
<li class="following"><div><span class="assets-count">727</span><span class="assets-title">Following</span></div></li>
<li class="followers"><div><span class="assets-count">4437</span><span class="assets-title">Followers</span></div></li>
<li class="follow"><button class="btn-follow">Follow</button></li>
</ul>
您也可以here对其进行测试
P.S。 -我将颜色和字体更改为提供的图像;