HTML:
<ul>
<li>eins</li>
<li>zwei</li>
<li>drei</li>
</ul>
CSS:
li::before {
content: "– " " ";
}
li {
list-style: outside none none;
padding: 0 0 0 10px;
text-indent: -10px;
}
I would like to add an extra space after the - of each li. I tried:
content: "- "
but it doesnt work. How can I add this.
thanks
thomas
You can moderate the space by adding padding-right to it.
Like this
li::before {
content: "+";
padding-right: 10px;
}
li {
list-style: outside none none;
padding: 0 0 0 10px;
text-indent: -10px;
}
<ul>
<li>eins</li>
<li>zwei</li>
<li>drei</li>
</ul>
you could use \00a0 (unicode) in css content
content: "–\00a0\00a0\";
try: https://jsfiddle.net/Lh6ro16g/
Place :before with position: absolute and increase / decrease padding-left on <li> to set indent as much as you want. This method will allow you to have text aligned vertically even if it goes in multiple lines.
li::before {
position: absolute;
content: "–";
top: 1px;
left: 0;
}
li {
list-style: outside none none;
padding-left: 20px;
position: relative;
}
<ul>
<li>eins</li>
<li>zwei</li>
<li>drei</li>
<li>Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet</li>
</ul>
you can increase / decrease space using padding-right on li as much as you want.
<ul>
<li>eins</li>
<li>zwei</li>
<li>drei</li>
enter</ul>
li:before {
content: "-";
padding-right: 20px;
}
li{
list-style:outside none;
}
Related
What I want to achieve is make a tag text to start new line under it own text not under numbers
ul.myul {
counter-reset: li;
}
ul.myul li {
counter-increment: li;
list-style: none;
margin-bottom: 10px;
}
ul.myul li a::before {
content: "0" counter(li);
font-size: 22px;
font-family: 'poppinsbold';
color: red;
margin-right: 10px;
}
<div style="width:400px">
<ul class="myul">
<li><a>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum</a></li>
<li><a>lorem ipsum lorem</a></li>
</ul>
</div>
This is what I want actually, it should goes to new line after red line, not behind the redline:
ul.myul {
counter-reset: li;
}
ul.myul li {
counter-increment: li;
list-style: none;
margin-bottom: 10px;
}
ul.myul li a::before {
content: "0" counter(li);
font-size: 22px;
font-family: 'poppinsbold';
color: red;
margin-right: 10px;
}
.myul::after {
content: "";
width: 2px;
height: 100%;
background: red;
position: absolute;
top: 0;
left: 78px;
}
<div style="width:400px">
<ul class="myul">
<li><a>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum</a></li>
<li><a>lorem ipsum lorem</a></li>
</ul>
</div>
#CBroe had already mentioned it correctly in the comment. The ul CSS property list-style-position: outside; is the right way to go here.
ul.myul {
counter-reset: li;
}
ul.myul li {
counter-increment: li;
list-style: none;
margin-bottom: 10px;
padding-left: 50px;
list-style-position: outside;
position: relative;
}
ul.myul li::before {
content: "0" counter(li) ".";
font-size: 22px;
font-family: 'poppinsbold';
color: red;
left: 0;
position: absolute;
top: 0;
}
.myul::after {
content: "";
width: 2px;
height: 100%;
background: red;
position: absolute;
top: 0;
left: 86px;
}
<div style="width:400px">
<ul class="myul">
<li>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum</li>
<li><a>lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum</a></li>
<li><a>lorem ipsum lorem</a></li>
</ul>
</div>
I have this image I am trying to replicate:
Basically, I want the border to go around the image and cut off within a certain distance.
I cannot seem to get the border to cut off.
This is the HTML for this quote and image
<div class="quote-container">
<img class="testimonial-img" src="./Photos/StethoscopeVector.png" alt="">
<div class="quote-container-text">
<h3>Testimonial Quote</h3>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean mollis<br/>erat vel ultricies imperdiet. Lorem ipsum dolor sit amet, consectetur<br/>
adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscingelit."
</p>
</div>
</div>
CSS for Quote and Image
.quote-container {
padding: 5em 0;
height: 100%
}
.testimonial-img {
position: absolute;
margin-left: 11.5em;
margin-top: -3em;
}
.quote-container-text {
text-align: center;
color: white;
margin-top: 2em;
border: 2px solid white;
width: 65%;
padding: 2em;
margin: auto;
}
Which currently looks like this image:
I have tried using shape-outside but it doesn't work and I believe it's because the image is being set to absolute.
This is the stethoscope image. White image, no background.
first of all move your image inside of your container-text and then give border to the right and bottom of it and use pseudo selectors :after and :before for the left border and top border.
for more explanation please refer this snippet.
.quote-container {
padding: 5em 0;
height: 100%;
}
.testimonial-img {
position: absolute;
top: -50px;
left: -13px;
}
.quote-container-text {
text-align: center;
color: white;
margin-top: 2em;
border-right: 2px solid white;
border-bottom: 2px solid #fff;
width: 65%;
padding: 2em;
margin: auto;
position: relative;
}
.quote-container-text:before {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 2px;
height: calc(100% - 60px);
background-color: #fff;
}
.quote-container-text:after {
position: absolute;
height: 2px;
width: calc(100% - 100px);
right: 0;
top: 0;
content: "";
background-color: #fff;
}
<body style="background-color: #2196F3">
<div class="quote-container">
<div class="quote-container-text">
<img class="testimonial-img" src="https://i.stack.imgur.com/nj8on.png" alt="">
<h3>Testimonial Quote</h3>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean mollis<br/>erat vel ultricies imperdiet. Lorem ipsum dolor sit amet, consectetur<br/>
adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscingelit."
</p>
</div>
</div>
</body>
for background-image instead of bg-color.
.quote-container {
padding: 5em 0;
height: 100%;
background-image: url('https://media.istockphoto.com/photos/vintage-retro-grungy-background-design-and-pattern-texture-picture-id656453072?k=6&m=656453072&s=612x612&w=0&h=4TW6UwMWJrHwF4SiNBwCZfZNJ1jVvkwgz3agbGBihyE=');
background-repeat: no-repeat;
background-size: cover;
}
.testimonial-img {
position: absolute;
top: -50px;
left: -13px;
}
.quote-container-text {
text-align: center;
color: white;
margin-top: 2em;
border-right: 2px solid white;
border-bottom: 2px solid #fff;
width: 65%;
padding: 2em;
margin: auto;
position: relative;
}
.quote-container-text:before {
content: "";
position: absolute;
bottom: 0;
left: 0;
width: 2px;
height: calc(100% - 60px);
background-color: #fff;
}
.quote-container-text:after {
position: absolute;
height: 2px;
width: calc(100% - 100px);
right: 0;
top: 0;
content: "";
background-color: #fff;
}
<body>
<div class="quote-container">
<div class="quote-container-text">
<img class="testimonial-img" src="https://i.stack.imgur.com/nj8on.png" alt="">
<h3>Testimonial Quote</h3>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean mollis<br/>erat vel ultricies imperdiet. Lorem ipsum dolor sit amet, consectetur<br/>
adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscingelit."
</p>
</div>
</div>
</body>
Thank You...
Your image has a transparent background, and it appears above the border. To fix that, you can set the border on an absolutely positioned pseudo-element (::before), and use clip-path to remove the top left corner:
.quote-container {
padding: 5em;
background: steelblue;
}
.quote-container-text {
position: relative;
width: 65%;
padding: 2em;
margin: auto;
text-align: center;
color: white;
}
.quote-container-text::before {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
border: 2px solid white;
clip-path: polygon(55px 0%, 100% 0%, 100% 100%, 0% 100%, 0% 55px, 55px 55px);
content: '';
}
.testimonial-img {
position: absolute;
top: 0;
left: 0;
transform: translate(-50%, -50%);
}
body {
margin: 0;
}
<div class="quote-container">
<div class="quote-container-text">
<img class="testimonial-img" src="https://i.stack.imgur.com/nj8on.png" alt="">
<h3>Testimonial Quote</h3>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean mollis<br/>erat vel ultricies imperdiet. Lorem ipsum dolor sit amet, consectetur<br/> adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscingelit."
</p>
</div>
</div>
An easy way to do this would be to use an image with a background color the same as the background color of the outermost container. Also, it's important to realize that setting something to absolute will make it absolute to the innermost container that has a relative positioning. Note that I used some random image from the web for the example, but you can conform it to your image. If you want your transparent image to have a background, wrap it in a div and set the background of the div.
First move the image inside the quote container text.
<div class="quote-container">
<div class="quote-container-text">
<div id="test-img-container">
<img class="testimonial-img" src="https://cdn3.iconfinder.com/data/icons/medical-174/100/healthy-06-512.png" alt="">
</div>
<h3>Testimonial Quote</h3>
<p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean mollis<br/>erat vel ultricies imperdiet. Lorem ipsum dolor sit amet, consectetur<br>
adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscingelit."
</p>
</div>
</div>
Next set the image to absolute with top and left stylings and make the quote-container-text element to be relatively positioned:
.quote-container {
padding: 5em 0;
height: 100%;
background:steelblue;
}
#test-img-container{
position: absolute;
left:-25px;
top:-25px;
background:steelblue;
}
.testimonial-img {
width:50px;
height:auto;
}
.quote-container-text {
text-align: center;
color: white;
margin-top: 2em;
border: 2px solid white;
width: 65%;
padding: 2em;
position:relative;
margin: auto;
}
Also note that this works best if you specify a hard width to the image so that you can evenly use the margin stylings on the image.
https://jsfiddle.net/dgf1ms8r/7/
I am creating a timeline but it's not displaying my design output. I have to display the first child after the image and next child before image with a full underline. I tried but my underline not displaying proper even image is not display the right way
Would you help me out in this?
I need a output like this.
.timeline ul li {
list-style-type: none;
position: relative;
width: 6px;
margin: 0 auto;
padding-top: 50px;
/* background: #fff;*/
border-right: 2px solid #ff0000;
}
.timeline ul li::after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 30px;
height: 30px;
background: inherit;
}
.timeline ul li:nth-child(odd),
.timeline ul li:nth-child(even){
width:50%;
float:left;
clear:right;
text-align:right;
position:relative;
}
.timeline ul li:nth-child(even){
width:50%;
float:right;
clear:left;
text-align:left;
position:relative;
}
.timeline ul li:nth-child(odd):after,
.timeline ul li:nth-child(even):before{
background: url('https://image.flaticon.com/icons/png/512/67/67347.png') no-repeat;
width: 24px;
height: 20px;
background-size: 100% 100%;
}
<div class="timeline">
<ul>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
</ul>
</div>
This is not perfect or dynamic but it will get you on the right path.
use nth-child(odd/even) to select every second row
li:nth-child(odd) {
float: left;
border-right: thick solid #ff0000;
margin: 0px;
padding-right: 20px;
background-image: url('https://image.flaticon.com/icons/png/512/67/67347.png');
background-repeat: no-repeat;
background-size: 20px 20px;
background-position-x: 254px;
background-position-y: 18px;
}
li:nth-child(even) {
float: right;
border-left: thick solid #ff0000;
margin-right: 186px;
padding-left: 20px;
background-image: url('https://image.flaticon.com/icons/png/512/67/67347.png');
background-repeat: no-repeat;
background-size: 20px 20px;
background-position-y: 18px;
}
ul{
list-style: none;
}
li{
padding: 20px 0 0 0;
}
div{
width: 777px;
}
img{
width: 20px;
}
<div class="timeline">
<ul>
<li>
Lorem ipsum dolor sit amet, consectetu
</li>
<li>
Lorem ipsum dolor sit amet, consectetu
</li>
<li>
Lorem ipsum dolor sit amet, consectetu
</li>
<li>
Lorem ipsum dolor sit amet, consectetu
</li>
<li>
Lorem ipsum dolor sit amet, consectetu
</li>
</ul>
</div>
here is my solution :
jsFiddle
.timeline ul li {
list-style-type: none;
position: relative;
width: 6px;
margin: 0 auto;
padding-top: 50px;
/* background: #fff;*/
}
.timeline ul li:nth-child(odd) {
border-right: 2px solid #ff0000;
}
.timeline ul li:nth-child(even) {
border-left: 2px solid #ff0000;
}
.timeline ul li::after {
content: '';
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 30px;
height: 30px;
background: inherit;
}
.timeline ul li:nth-child(odd){
width:50%;
float:left;
clear:right;
text-align:right;
position:relative;
}
.timeline ul li:nth-child(even){
width:49.7%;
float:right;
clear:left;
text-align:left;
position:relative;
}
.timeline ul li:nth-child(odd):after,
.timeline ul li:nth-child(odd):before{
background: url('https://image.flaticon.com/icons/png/512/67/67347.png') no-repeat;
width: 24px;
height: 20px;
background-size: 100% 100%;
}
<div class="timeline">
<ul>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
</ul>
</div>
You can change a part of CSS as below: Jsfiddle
.timeline ul li:nth-child(1), .timeline ul li:nth-child(2n+1){
width: 50%;
float: left;
clear: right;
text-align: right;
position: relative;
border-right: 5px inset black; //border
left: -5px; //alignment
}
.timeline ul li:nth-child(2n){
width: 50%;
float: right;
clear: left;
text-align: left;
position: relative;
border-left: 5px inset black; //border
}
There are a couple of thing missing or wrong with your code.
You applied the border on both the divs on the same side. I fixed this by giving them both a different border.
To make sure the border was included within the size of the element I used box-sizing: border-box;.
As with some of the other answers they became jagged so I applied a width to the element of 50% - half the border size i.e. width: calc(50% - 1px). This should always result in a straight line.
You never made sure the actual :before would be displayed. So i applied the same rules for the :after to the :before.
Gave the li a small padding so it wouldn't be stuck to the border, resulting in some space for the image.
The code below should work the way you intended. As for margins and padding, you are ofcourse free to adjust them to your needs.
.timeline ul li {
list-style-type: none;
position: relative;
width: calc(50% + 1px);
margin: 0 auto;
padding-top: 50px;
box-sizing: border-box;
}
.timeline ul li::after, .timeline ul li::before {
position: absolute;
transform: translateX(-50%);
width: 24px;
height: 20px;
content: '';
}
.timeline ul li:nth-child(odd){
float:left;
clear:right;
text-align:right;
border-right: 2px solid #ff0000;
padding-right: 2em;
}
.timeline ul li:nth-child(even){
float:right;
clear:left;
text-align:left;
border-left: 2px solid #ff0000;
padding-left: 2em;
}
.timeline ul li:nth-child(odd):after{
background: url('https://image.flaticon.com/icons/png/512/67/67347.png') no-repeat;
background-size: 100% 100%;
right: -5px;
}
.timeline ul li:nth-child(even):before{
background: url('https://image.flaticon.com/icons/png/512/67/67347.png') no-repeat;
background-size: 100% 100%;
left: 20px;
}
<div class="timeline">
<ul>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
<li>Lorem ipsum dolor sit amet, consectetu</li>
</ul>
</div>
I am trying to create a div that is two different colors, split horizontally, with an angled(triangle) divider/indicator that points from the left side to the right side. This is the mockup I got:
I found a guide for making something very similar here (the 'Talk Bubble' example):
https://css-tricks.com/examples/ShapesOfCSS/
and here I found an example for creating a bi-colored div:
CSS: Set a background color which is 50% of the width of the window
I have a CodePen here with what I've got, and I'm just struggling a little bit to put the pieces above together to meet the mockup. I'm trying to make sure that the angled indicator is a maximum of 100% of the height of this div, as it will be with other similar divs of other colors and I don't want overlapping edges.
https://codepen.io/chjaro/pen/MGmLxb?editors=1100
#cs-results>#csBullets {
text-align: justify;
margin: 0 auto;
width: 40em;
padding-left: 100px;
font-size: 24px;
}
#csBullets>ul>li {
list-style: none;
color: #fff;
}
#csBullets>ul>li::before {
content: "\2022";
color: #188ac5 !important;
position: relative;
top: 0em;
padding-right: 10px;
}
#csTitle {
color: white;
font-size: 48px;
margin: auto;
max-width: 75%;
padding: 20px 0 50px 0;
}
#cs-what-we-did {
height: 400px;
background: linear-gradient(90deg, #9fa0a2 40%, #58595B 40%);
z-index: -3;
margin: 0;
padding: 0 20%;
}
#csBullets {
/* background-color: #9fa0a2; */
height: 400px;
margin: -9% 0 -10% 0;
padding: 8% 0
}
#csBullets:after {
content: "";
position: absolute;
left: 66%;
top: 0;
width: 0;
height: 0;
border-top: 175px solid transparent;
border-left: 150px solid #9fa0a2;
border-bottom: 200px solid transparent;
z-index: -1
}
#media screen and (max-width: 990px) {
#csBullets:after {
display: none !important;
}
#cs-what-we-did {
height: 100%;
background: linear-gradient(90deg, #9fa0a2 50%, #58595B 50%);
z-index: -3;
}
#csBullets {
height: 100%;
}
}
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div id="cs-what-we-did" class="col-lg-12 container-fluid cs-single">
<div class="sectionTitleBar">
<h2 class="sectionTitle" style="color: #fff;">Section Title</h2>
</div>
<div class="col-md-6" style="" id="csBullets">
<h3 class="sectionTitle" style="color:#fff;">Goals</h3>
<ul>
<li>Placeholder</li>
<li>Placeholder</li>
<li>Placeholder</li>
<li>Placeholder</li>
</ul>
</div>
<div class="col-md-6" style="z-index: -1">
<h3 class="sectionTitle" style="color:#fff;">Results</h3>
<p style="text-align: left; color: #fff">Placeholder placeholder placeholder placeholder placeholder placeholder placeholder placeholder placeholder placeholder placeholder placeholder placeholder.</p>
<p style="text-align: left; color: #fff">“Placeholder placeholder placeholder placeholder placeholder ,” Placeholder says. “Placeholder placeholder placeholder placeholder placeholder placeholder placeholder placeholder placeholder placeholder placeholder placeholder placeholder placeholder
placeholder placeholder placeholder placeholder placeholder placeholder.”</p>
</div>
</div>
I would take a different approach to this and just use absolutely positioned pseudo elements to create the elements for the angle, then transform them to get the shape you want. After that you use some z-index magic to keep it behind the content in case of overlap. This way it'll always be relative to the container itself, so it'll work regardless of the container's height.
.container {
width: 100%;
display: flex;
overflow: hidden;
position: relative;
}
.title {
position: absolute;
top: 20px;
left: 0;
right: 0;
margin: 0;
text-align: center;
z-index: 3;
}
.left,
.right {
flex: 1;
padding: 50px 60px 20px;
}
.left {
z-index: 2;
background: gold;
}
.right {
background: tomato;
position: relative;
z-index: 1;
}
.right::before,
.right::after {
z-index: -1;
content: "";
background-color: gold;
position: absolute;
width: 50%;
right: 100%;
}
.right::before {
top: 0;
bottom: 48%;
transform: rotate(-15deg);
transform-origin: top right;
}
.right::after {
bottom: 0;
top: 48%;
transform: rotate(15deg);
transform-origin: bottom right;
}
<div class="container">
<h1 class="title">Lorem ipsum dolor sit amet.</h1>
<div class="left">
<h1>Lorem ipsum.</h1>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Commodi, recusandae.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</li>
<li>Lorem ipsum dolor sit amet.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Necessitatibus assumenda sit cupiditate facere, nihil temporibus.</li>
</ul>
</div>
<div class="right">
<h1>Lorem ipsum.</h1>
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Commodi, recusandae.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</li>
<li>Lorem ipsum dolor sit amet.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Necessitatibus assumenda sit cupiditate facere, nihil temporibus.</li>
<li>Lorem ipsum dolor sit amet.</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Necessitatibus assumenda sit cupiditate facere, nihil temporibus.</li>
</ul>
</div>
</div>
I needed to create a list with a custom list-index which is vertically centered to the content of the list items.
As I am using flex already I thought the easiest might be to give the list-item a display:flex; and style it. This works, but as soon, as the list-item contains other elements it is messed up. As you can see in the example below.
Whats the best way to vertically center the list-index?
-- Updated Example --
ol {
list-style: none;
padding: 0;
width: 200px;
}
ol > li {
display: flex;
margin-top: 20px;
align-items: center;
}
ol > li:before {
color: red;
content: attr(data-count)' ›';
flex display: block;
flex-shrink: 0;
text-align: right;
min-width: 24px;
padding-right: 5px;
}
<ol>
<li data-count="1">Lorem ipsum dolor sit amet, consectetur adipisicing elit</li>
<li data-count="10">Lorem ipsum dolor sit <span>amet</span>, consectetur adipisicing elit</li>
<li data-count="999">Lorem ipsum dolor sit amet, consectetur adipisicing elit</li>
</ol>
I think that the best option is to wrap all elements inside li in one other element and that should fix the problem.
ul {
list-style: none;
padding: 0;
width: 200px;
}
ul > li {
display: flex;
margin-top: 20px;
align-items: center;
}
ul > li:before {
color: red;
content: '›';
flex display: block;
flex-shrink: 0;
text-align: center;
width: 30px;
}
<ul>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit</li>
<li>
<p>Lorem ipsum dolor sit <span>amet</span>, consectetur adipisicing elit</p>
</li>
<li>Lorem ipsum dolor sit amet, consectetur adipisicing elit</li>
</ul>
Solution could be to use display:table, instead of flex, in this particular case.
ol {
list-style: none;
padding: 0;
width: 200px;
display:table;
border-spacing:0 20px;
}
ol > li {
display:table-row;
vertical-align:middle;
}
ol > li:before {
color: red;
content: attr(data-count)' ›';
display:table-cell;
vertical-align:middle;
text-align: right;
white-space: nowrap;
padding-right: 10px;
}
<ol>
<li data-count="1">Lorem ipsum dolor sit amet, consectetur adipisicing elit</li>
<li data-count="10">Lorem ipsum dolor sit <span>amet</span>, consectetur adipisicing elit</li>
<li data-count="999 99">Lorem ipsum dolor sit amet, consectetur adipisicing elit</li>
</ol>
Here's a method with absolute positioning to keep the arrows vertically centered.
ol {
list-style: none;
padding: 0;
width: 200px;
}
ol > li {
margin: 20px 0 0;
padding-left: 36px;
position: relative;
}
ol > li:before {
color: red;
content: attr(data-count)' ›';
font-size: 14px;
line-height: 1;
position: absolute;
left: 0;
top: 50%; /* vertically center */
margin-top: -7px; /* and shift up based on 16px height */
}
<ol>
<li data-count="1">Lorem ipsum dolor sit amet, consectetur adipisicing elit</li>
<li data-count="10">Lorem ipsum dolor sit <span>amet</span>, consectetur adipisicing elit</li>
<li data-count="999">Lorem ipsum dolor sit amet, consectetur adipisicing elit</li>
</ol>