简体   繁体   English

如何在li css中分离图像和文本

[英]how to separate image and text in li css

Is there a way to format my text in one right place (separated from the image, whole heading)?有没有办法在一个正确的地方格式化我的文本(与图像分开,整个标题)?

This is my HTML:这是我的 HTML:

 <div class="tab-pane container fade" id="environmental"> <div class="row"> <div class="content-info col col-sm-6 no-l-padding"> <h3 class="red-title">ENVIRONMENTAL</h3> <div class="container"> <div class="row"> <div class="col-sm-6"> <li class="list-item"><img class="heat" src="http://dubai.themyriad.com/wp-content/uploads/2020/02/heat.png">UV RATED WALLS – HEAT TRANSMISSION REDUCTION </li> <li class="list-item"><img class="air_window" src="http://dubai.themyriad.com/wp-content/uploads/2020/02/air_window.png">DOUBLE GLAZED WINDOWS – COOL AIR CONTAINMENT </li> <li class="list-item"><img class="low_energy" src="http://dubai.themyriad.com/wp-content/uploads/2020/02/low_energy.png">LOW ENERGY CONSUMING HEAT PUMPS </li> </div> <div class="col-sm-6"> <li class="list-item"><img class="solar_panel" src="http://dubai.themyriad.com/wp-content/uploads/2020/02/solar_panel.png">SOLAR PANELS SPACE </li> <li class="list-item"><img class="sensor" src="http://dubai.themyriad.com/wp-content/uploads/2020/02/sensor.png">OCCUPANCY SENSORS TO CONTROL LIGHTING AND AC – BOTH IN-ROOM AND THROUGHOUT COMMON AREAS </li> <li class="list-item"><img class="shower" src="http://dubai.themyriad.com/wp-content/uploads/2020/02/shower.png">WATER CONSERVING SHOWERHEADS </li> </div> </div> </div>

Right now, it looks like this:现在,它看起来像这样:
在此处输入图片说明



But, I need this:但是,我需要这个:
在此处输入图片说明

Just use a <span> tag to wrap your HTML.只需使用<span>标签来包装您的 HTML。 It's inline level element so no impact to HTML structure.它是内联级元素,因此对 HTML 结构没有影响。 Additionally you can provide CSS to span tag此外,您可以提供 CSS 来跨标签

like li span {max-width:100px}li span {max-width:100px}

<li class="list-item"><img class="heat"src="http://dubai.themyriad.com/wp-content/uploads/2020/02/heat.png" >
<span>UV RATED WALLS – HEAT TRANSMISSION REDUCTION</span>

</li>

There are many ways to do this like using a float, using display: table, using flex-box.有很多方法可以做到这一点,比如使用浮动、使用 display: table、使用 flex-box。 I have used the flex-box in my answer.我在答案中使用了 flex-box。 Also your content was not in a tag.此外,您的内容不在标签中。 So I have used p tag for that.所以我为此使用了 p 标签。 Hope this helps.希望这可以帮助。

 li{ list-style:none; } .list-item{ display: -webkit-box; display: -ms-flexbox; display: flex; -ms-flex-wrap: wrap; flex-wrap: wrap; -webkit-box-align: center; -ms-flex-align: center; align-items: center; } .img-sec{ width: 10%; } .list-item p{ width: 90%; }
 <div class="tab-pane container fade" id="environmental"> <div class="row"> <div class="content-info col col-sm-6 no-l-padding"> <h3 class="red-title">ENVIRONMENTAL</h3> <div class="container"> <div class="row"> <div class="col-sm-6" > <li class="list-item"><div class="img-sec"><img class="heat"src="http://dubai.themyriad.com/wp-content/uploads/2020/02/heat.png" ></div> <p>UV RATED WALLS – HEAT TRANSMISSION REDUCTION</p> </li> <li class="list-item"><div class="img-sec"><img class="air_window"src="http://dubai.themyriad.com/wp-content/uploads/2020/02/air_window.png" ></div> <p>DOUBLE GLAZED WINDOWS – COOL AIR CONTAINMENT </p> </li> </div> </div> </div>

try this...尝试这个...

 li.list-item { display: flex; margin-bottom: 12px; align-items: center; } li img { margin-right: 21px; }
 <div class="tab-pane container fade" id="environmental"> <div class="row"> <div class="content-info col col-sm-6 no-l-padding"> <h3 class="red-title">ENVIRONMENTAL</h3> <div class="container"> <div class="row"> <div class="col-sm-6"> <li class="list-item"><img class="heat" src="http://dubai.themyriad.com/wp-content/uploads/2020/02/heat.png">UV RATED WALLS – HEAT TRANSMISSION REDUCTION </li> <li class="list-item"><img class="air_window" src="http://dubai.themyriad.com/wp-content/uploads/2020/02/air_window.png">DOUBLE GLAZED WINDOWS – COOL AIR CONTAINMENT </li> <li class="list-item"><img class="low_energy" src="http://dubai.themyriad.com/wp-content/uploads/2020/02/low_energy.png">LOW ENERGY CONSUMING HEAT PUMPS </li> </div> <div class="col-sm-6"> <li class="list-item"><img class="solar_panel" src="http://dubai.themyriad.com/wp-content/uploads/2020/02/solar_panel.png">SOLAR PANELS SPACE </li> <li class="list-item"><img class="sensor" src="http://dubai.themyriad.com/wp-content/uploads/2020/02/sensor.png">OCCUPANCY SENSORS TO CONTROL LIGHTING AND AC – BOTH IN-ROOM AND THROUGHOUT COMMON AREAS </li> <li class="list-item"><img class="shower" src="http://dubai.themyriad.com/wp-content/uploads/2020/02/shower.png">WATER CONSERVING SHOWERHEADS </li> </div> </div> </div>

If you are using Bootstrap, then try Flex utility, this is nice and easy!如果您正在使用 Bootstrap,请尝试使用 Flex 实用程序,这很好很简单! :) :)

Well supports horizontal and vertical alignment also. Well 还支持水平和垂直对齐。 https://getbootstrap.com/docs/4.3/utilities/flex/ https://getbootstrap.com/docs/4.3/utilities/flex/

<ul class="list-unstyled">
  <li class="list-item">
      <div class="d-flex justify-content-start align-items-center">
          <div>
              <img width="48" class="heat" src="http://dubai.themyriad.com/wp-content/uploads/2020/02/heat.png">
          </div>
          <div class="pl-2 text-uppercase">
              UV Rated Walls - Heat Transmission Reduction
          </div>
      </div>
  </li>
</ul>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM