The Dead Man
The Dead Man

Reputation: 5556

How to center after pseudo-elements?

I have a list of elements , I have added after element (vertical line) , I would like to center it and it should be responsive.

Here is what I want enter image description here

Here is my solution

.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>

Unfortunatelly my solution is not giving me the result I want,

What am I doing wrong in my solution? any help will be apreciated , Thanks

Upvotes: 1

Views: 85

Answers (3)

Nimitt Shah
Nimitt Shah

Reputation: 4587

I would suggest you to use div instead of span so you don't need to use CSS for span to make it block (flex). Also, use li:nth-child(-n + 2)::after instead of separating style for last two li with new rule.

See below Snippet:

* {
 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>

You can also test it here

P.S. - I have changed the color and fonts to look like provided image;

Upvotes: 0

Firoz
Firoz

Reputation: 101

It Will work with responsive, Try this code

.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>

Upvotes: 1

ksav
ksav

Reputation: 20821

I think you might misunderstand where the :after generated content ends up in the document flow.

The pseudo-elements generated by ::before and ::after are contained by the element's formatting box...

So the after element is not actually placed after the <li>, but at the end of the <li>'s child nodes.

.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>

Upvotes: 1

Related Questions