简体   繁体   中英

Vertical align icon and text list

I have had this problem various times and never really quite know the best way to approach it.

A screenshot for a better context:

在此处输入图片说明

What it should look like...

在此处输入图片说明

.container {
max-width: 360px;
font-size: 16px;
}
.talking-point {
    margin-bottom: 10px;
    display: table;
    background-image: url('http://s28.postimg.org/yozkg6ueh/speech_bubble.png');
    background-repeat: no-repeat;
    background-position: 0 45%;
    min-height: 35px;
    i {
        padding-left: 10px;
        line-height: 27px;
        color: #fff;
    }
    p {
        padding-left: 18px;
    display: table-cell;
        vertical-align: middle;

    }
}

Please check out the fiddle here Updated as per the below :
http://jsfiddle.net/67AD7/

Now my question is, how do I achieve a 'better' vertical-alignment between the icon and text in this situation. I'm almost tempted to use a table or should I use a list?

Note, I need to be able to insert HTML ('post-count') over the icon as in the examples provided.

Any help is greatly appreciated!

You'll basically have to assigned the background to the i tag . Your CSS ends up looking like below:

.talking-point {
  margin-bottom: 10px;
  display: table;
  min-height: 35px;
  i {
    background: url('http://s28.postimg.org/yozkg6ueh/speech_bubble.png') no-repeat;
    padding-left: 8px;
    line-height: 30px;
    width: 35px;
    height: 35px;
    display: inline-block;
    color: #fff;
  }
  p {
    display: table-cell;
    vertical-align: middle;

  }
}

http://jsfiddle.net/xNTh9/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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