1

The text should be next to the image. I just have the problem that the text below the list point is displayed, not right next to it. What is the problem here? I've looked at other examples that make it exactly the same. But in the examples it works however.enter image description here

.icon {
    list-style-type: none;
}
          
.icon li:nth-child(1):before {content: url(icon-1.png)' ';}
.icon li:nth-child(2):before {content: url(icon-2.png)' ';}
.icon li:nth-child(3):before {content: url(icon-3.png)' ';}
<ul class="icon">
<li>
<h3>Lorem ipsum</h3>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,</li>
<li>
<h3>Lorem ipsum</h3>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,</li>
<li>
<h3>Lorem ipsum</h3>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,</li>
</ul>
azrm
  • 189
  • 1
  • 12
  • Possible duplicate of [Adjust list style image position?](http://stackoverflow.com/questions/1708833/adjust-list-style-image-position) – Carlos Martins Dec 12 '16 at 14:36

3 Answers3

1

You can use CSS Flexbox and make your <h3> includes all the text with a <span>, then make your <li> a flex container. Like:

<li>
  <h3>Lorem ipsum<span>Lorem ipsum dolor sit amet, consetetur sadipscing elitr,</span></h3>
</li>

Have a look at the snippet below:

.icon {
    list-style-type: none;
}
          
.icon li:nth-child(1):before {content: url('http://placehold.it/50x50')' ';}
.icon li:nth-child(2):before {content: url(http://placehold.it/50x50)' ';}
.icon li:nth-child(3):before {content: url(http://placehold.it/50x50)' ';}

li {
  display: flex;
  align-items: center;
  margin: 10px 0;
}

li:before {
  height: 50px;
}

h3 {
  display: inline-block;
  vertical-align: middle;
  margin: 0;
  padding-left: 10px;
}

span {
  display: block;
  font-weight: normal;
  font-size: small;
}
<ul class="icon">
<li>
  <h3>Lorem ipsum<span>Lorem ipsum dolor sit amet, consetetur sadipscing elitr,</span></h3>
</li>
<li>
  <h3>Lorem ipsum<span>Lorem ipsum dolor sit amet, consetetur sadipscing elitr,</span></h3>
</li>
<li>
  <h3>Lorem ipsum<span>Lorem ipsum dolor sit amet, consetetur sadipscing elitr,</span></h3>
</li>
</ul>

Hope this helps!

Saurav Rastogi
  • 8,959
  • 3
  • 25
  • 34
1

Here icon li:nth-child(1):before is behaving like block level element and <h3> both is also a block level element. So change your css to:

.icon li:nth-child(1):before {content: url(icon-1.png)' ';}
.icon li:before { display: inline-block }
h3 {display: inline-block; }
rapidRoll
  • 182
  • 9
0

PFB the working snippet. I just added a div tag b/w <li> and </li> and applied CSS for all the <div> tags which are direct children of <li> to have CSS property display:inline-block

.icon {
    list-style-type: none;
}
li>div
{
 display:inline-block;
}
.icon li:nth-child(1):before {content: url(icon-1.png)' ';}
.icon li:nth-child(2):before {content: url(icon-2.png)' ';}
.icon li:nth-child(3):before {content: url(icon-3.png)' ';}
<ul class="icon">
<li>
<div>
<h3>Lorem ipsum</h3>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,</div></li>
<li>
<div>
<h3>Lorem ipsum</h3>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,</div></li>
<li>
<div>
<h3>Lorem ipsum</h3>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr,</div></li>
</ul>
Harinder
  • 106
  • 1
  • 11