Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

css - How can I position image before each item in inline list?

I'm attempting to create a inline list that display an image before each list item. Currently the image appears above the list item and not on the same line.

My aim is to get the image to appear to the left of the item, on the same line so it acts like a bullet/space between each item.

This is what my current attempt looks like ... This is what my current attempt looks like

Markup:

    <ul class="list-inline">
      <li class="list-inline-item"><h4>Item One</h4></li>
      <li class="list-inline-item"><h4>Item Two</h4></li>
      <li class="list-inline-item"><h4>Item Three</h4></li>
    </ul>

Css:

ul li::before { 
content: url("~@/assets/asset-1.png");
display:inline-block
}

As you can see I'm currently using bootstrap 4 and it's classes to achieve the inline list.

question from:https://stackoverflow.com/questions/65927888/how-can-i-position-image-before-each-item-in-inline-list

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are missing the h4 definition in the css as Temani Afif stated above.

CSS:

ul li h4::before { 
  content: url("~@/assets/asset-1.png");
  display:inline-block
}

Alternatively, if you're interested - FlexBox makes this really easy and fun to do!

This site is really well put together and a great FlexBox reference: https://css-tricks.com/snippets/css/a-guide-to-flexbox/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...