又一个定位之谜

时间:2012-07-05 12:25:20

标签: html css

我想要一个带有方形图像的两列列表和旁边的两行文字,很好地对齐

_________                                    ________
|       |                             |     |        |
|       |     Line one h3 tag         |     |        |     Line one h3 tag
|       |     Line two p tag          |     |        |     Line two p tag
|       |                             |     |        |
_________                             |     __________

这是我的代码:http://jsfiddle.net/PEMKs/3/

HTML:

<div class="wrapper">    
    <div class="right clearfix">
        <img src="http://placehold.it/100x100" >
        <h4>My name is Markup.</h4><p>I live in Vienna</p>
    </div>
    <div class="left ">
        <img src="http://placehold.it/100x100" >
        <h4>My name is Markup.</h4> <p>I live in Vienna</p>
    </div>
</div>​

CSS:

.wrapper{
    width:650px
}

.right{
    width:300px; 
    height:100px; 
    position:relative;
    float:right;
}

.right h4, .right p{
    float:right;
    margin-right:25px;
    font-family:sans-serif;
}

.left{
    width:300px;
    height:100px;
    position:relative;
    margin-right:145px;
    border-right:1px dashed #cccccc;
}

.left h4, .left p{
float:right;
    margin-right:25px;
        font-family:sans-serif;
}

.clearfix:after {
   content: ".";
   visibility: hidden;
   display: block;
   height: 0;
   clear: both;
}

p{
 display:inline-block;   
}

3 个答案:

答案 0 :(得分:0)

这对你有用吗?

http://jsfiddle.net/42XUW/

答案 1 :(得分:0)

您可以为图片添加CSS样式

.left img { float: right;}

答案 2 :(得分:0)

<div class="wrapper">    
    <div class="right clearfix">
        <img src="http://placehold.it/100x100" style="float:left;" >
        <h4>My name is Markup.</h4><p>I live in Vienna</p>
    </div>
    <div class="left ">
        <img src="http://placehold.it/100x100" style="float:left;" >
        <h4>My name is Markup.</h4> <p>I live in Vienna</p>
    </div>
</div>​

图像的样式将设置为float:left。它解决了你的问题。