如何在css中同时获取图标和标题

时间:2016-03-22 13:51:06

标签: html css

我想将图标和标题排在同一行:

enter image description here

但我还是这样:

enter image description here

守则:



.icon-small i{
  height: 38px;  
  width: 38px; 
  color: #fff;
  background-color: #888;
  border-radius: 10%;
  text-align: center;
  vertical-align: middle;
  padding-top: 12px;

}
.icon-small + p{
  margin-top: 15px;

}
.icon-small h4,
.icon-small h5{
  text-align: left;
}

<div class="row">
  <div class="col span-1-of-3">
    <span class="icon-small">
      <i class="fa fa-television"></i>
      <h4>Web applications</h4>
      <h5>Mobile & Tablets Ready</h5>
    </span>
    <p>Powerful, fast and robust web applications to cater for complex business needs.</p>
  </div>
  <div class="col span-1-of-3">
    <span class="icon-small">
      <i class="fa fa-mobile-phone"></i>
      <h4>Mobile apps</h4>
      <h5>For the iPhone, iPad & Android</h5>
    </span>
    <p>Apps that connect directly to your customers.</p>
  </div> 
  <div class="col span-1-of-3">
    <span class="icon-small">
      <i class="fa fa-image"></i>
      <h4> Graphic </h4>
      <h5>Infographics, site designs and more</h5>
    </span>
    <p>Let our graphics speak the thousand words that you simply don't have the time to say.</p> 
  </div>
</div>
&#13;
&#13;
&#13;

我只是做了一些事情,但没有用。我使用了Font Awesome和响应式网格系统。

我用它来重置默认样式:

* {
    margin: 0px;
    padding: 0px;
    box-sizing: border-box;
}

4 个答案:

答案 0 :(得分:3)

我想你想要.icon-small i { float: left; margin-right: 10px; /* ... */ } 图标:

.icon-small + p {
    clear: left;
    /* ... */
}

好的衡量标准:

import grails.test.mixin.integration.Integration
import grails.transaction.*
import spock.lang.*

@Integration
@Rollback
class SampleSpec extends Specification {
    def grailsApplication

    void "test something"() {
        expect:"fix me"
            grailsApplication.config.getProperty('testing.defaults.startUrl') == 
                'http://localhost:8080/'
    }
}

https://jsfiddle.net/mblase75/e42rsw04/

答案 1 :(得分:1)

您可以在父级上使用display:inline-block并在子级上显示:inline - 或者,您可以使用:在伪类之前使用绝对定位来定位它。

<div class="logo">
    <div class="text">Some Text</div>
</div>

.text{
    position:relative;
}

.text::before {
    position:absolute;
    margin-left: -30px;
    background-image: url("youricon.png");
    background-color: #fff;
    height:<<height of your icon goes here>>;
    width:<<width of your icon goes here>>;
}

OR

<div class="logo">
    <div class="icon"><img src="youricon.png" alt="Logo"></div>
    <div class="text">Some Text</div>
</div>


.logo{
    display: inline-block;
    width: 100%;
}

.icon, .text {
    display:inline;
}

.text{
    margin-left:10px;
}

答案 2 :(得分:0)

只需使用position:absolute作为图标文本块内的图标。

.icon-small {
    position: relative;
    padding: 0 0 0 48px; /* 38px icon width + 10px gap between icon and text */
}

.icon-small i {
    height: 38px;  
    width: 38px;
    position: absolute;
    left: 0;
    top: 0;
}

答案 3 :(得分:0)

  

由于没有人建议使用flexbox   看看这个http://jsfiddle.net/hnsd4np6/2/

<div class="row container">
 <div class="col span-1-of-3 box">
   <span class="icon-small">
   <i class="fa fa-television"></i>
  <div class="details">
    <h4>Web applications</h4>
    <h5>Mobile & Tablets Ready</h5>
  </div>
</span>
<p>Powerful, fast and robust web applications to cater for complex business needs.</p>
</div>
<div class="col span-1-of-3 box">
  <span class="icon-small">
    <i class="fa fa-mobile-phone"></i>
    <div class="details">
      <h4>Mobile apps</h4>
      <h5>For the iPhone, iPad & Android</h5>
   </div>
</span>
<p>Apps that connect directly to your customers.</p>
</div> 
 <div class="col span-1-of-3 box">
   <span class="icon-small">
     <i class="fa fa-image"></i>
    <div class="details">
      <h4> Graphic </h4>
      <h5>Infographics, site designs and more</h5>
   </div>
</span>
</div>
</div>
  

html部分新添加的一些内容是

  1. 将课程container添加到课程row
  2. 向班级box添加了一个班级col span-1-of-3,以便将每个产品单独分开
  3. 添加了课程details以分隔图标及其说明

    CSS
  4.   

    上述新添加的类的样式

    .icon-small{
     display:flex;
    flex-direction:row;
    align-items:center;
    }
      .details{
        padding:0 1em;
      }
    .box{
        border:1px solid #333;
        background-color:#fff;
        width:300px;
        padding:1em;
       }
      .container{
        display:flex;
        flex-direction:row;
        flex-wrap:wrap;
        border:1px solid #333;
        background-color:powderblue;
       }
    
    <br>
    

    如果您想了解有关flexbox clickhere

    的更多信息