超过图像高度时,我的文字会向左移动

时间:2014-08-23 01:32:56

标签: html css

我的css有问题,当我的段落很长时,我希望我的文字继续与图片旁边的测试对齐。

但我没有这个,我的文字在超出图像高度时向左移动,正如你在我的图像中看到的那样。

而且,我有一个空白区域,在下面的图片中用圆圈标记,我不明白为什么。

enter image description here

你知道我怎么能得到这样的效果我的下图?

enter image description here

我忘记了解问题: http://jsfiddle.net/ejjtepfo/2/

我的Html:

<div class="modal">
    <h2>Title of news</h2>
    <span id="data">20/10/2014</span><br />
    <img class="img" src=""/>
    <p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
    <div class="clear_p"></div>
    <div id="pdfs">
        <h3>Links</h3>
        <ul class="links">
            <li> <a href=""></a>Link 1</li>
            <li> <a href=""></a>Link 2</li>http://jsfiddle.net/#tidy
            <li> <a href=""></a>Link 3</li>
        </ul>
    </div>
</div>

6 个答案:

答案 0 :(得分:1)

您可以将段落包装在div标签中:

<img src="http://www.peacethroughpie.org/wp-content/uploads/2013/09/baked-pie.jpg">
<div><p> ... </p></div>

然后你可以将div设置为宽度100% - 图像宽度并将其浮动到右边。

img {
    float: left;
    width: 20%;
}
div {
    display: block;
    width: 80%;
    float: right;
}

看起来像这样: http://imgur.com/zL5v33z

答案 1 :(得分:1)

只需添加 float:right;您的段落的位置:相对,如果它位于图像下方,则调整段落的宽度。

答案 2 :(得分:1)

您可以将<p>的左边距设置为等于图像的宽度

HTML

<img src="" />
<p>...</p>

CSS

img {
   float: left;
   width: 100px;
}

p {
  margin-left: 100px;
}

答案 3 :(得分:1)

DEMO:http://jsfiddle.net/wL6jua0L/

使用box-sizing:border-box,padding和negative margin。假设,如在OP中,图像被固定为200px宽,这意味着使用5px边框,您可以添加您想要的实际宽度,因为border-box包含边框和填充。关于其他屏幕截图下方的间隙,如果将段落线高度更改为24px,则不会存在或者您可以操纵图像高度。谷歌垂直节奏和图像。

enter image description here

.modal .img {
    width:210px;
    height:230px; 
    border:5px solid #f3f3f3;
    margin:18px -220px 0 0;
    box-sizing:border-box;
    float:left;
}

.modal p{
    box-sizing:border-box;
    font-size: 16px;  
    text-align:left;
    line-height:25px;   
    float:left;
    padding:0 10px 0 230px;
}

答案 4 :(得分:0)

overflow:hidden添加到段落的格式中。

答案 5 :(得分:0)

在html文件中为您的图片添加div,并将其添加到您的css

 #image{
 width:210px;
 height:1000px;
 float:left;
 }