简体   繁体   English

文字以div左浮动图像换行,而不是div带有右浮动图像换行

[英]Text wraps in div with left floated image but not the div with the right floated image

I have been able to sucessfully wrap text in a div with an image to the left but I can't wrap the text in a div with the image floated to the right. 我已经能够成功地将文本包装在div中,图像在左侧,但我无法将文本包装在div中,图像在右侧。 I have tried floating p left. 我试过向左浮动p。 I have also tried making changing the display mode of the div with right floated image to inline and inline block. 我还尝试过将带有右浮动图像的div的显示模式更改为嵌入式和嵌入式块。 I also tried using text-align left. 我也尝试使用文字左对齐。

Here is the code for the div were the text wraps ok. 这是文本自动换行的div代码。

#text_area_top  
        { 
            margin-top:5%; margin-left: 2%; 
            height: 150px; width:700px;  position:relative; 
            font-family:Arial, Helvetica, sans-serif; font-size:18px;
        }

Here is the code for the div where the text won't wrap. 这是div的代码,其中文本不会自动换行。

#text_area_bottom
        {
            margin-top:5%; margin-left: 2%; 
            height: 150px; width:700px;  position:relative; 
            font-family:Arial, Helvetica, sans-serif; font-size:18px; 
            background-color:#00FF00; 
            text-align:left;
        }
#text_area_bottom img { float:right; }

Here is some extra code that would be important to know for solving this problem. 这是一些额外的代码,对于解决此问题而言,了解这些代码很重要。

p { display:inline-block; position:absolute; margin:0px;   }

If there is any more information you need me to include please let me know and I will post promptly. 如果您需要我提供其他任何信息,请告诉我,我会及时发布。

Here is the html: 这是html:

  <div class="content">
            <div id="text_area_top">
                <img src="img.png" id="content_img" />
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ornare 
                  urna et ligula lobortis sed aliquam eros eleifend. Aliquam gravida tellus mollis                   
                   massa rhoncus egestas.

                   Aliquam molestie arcu vitae est accumsan rutrum. Cras vitae tellus justo. Quisque pulvinar                adipiscing dolor, non consectetur enim  vehicula quis.Etiam tortor augue, interdum et congue a,                                  imperdiet sed risus. Cras sagittis vestibulum</p>
              </div>

              <div id="text_area_bottom">
                <img src="img.png" id="content_img2" />
                <p>Scelerisque vitae, convallis non nibh. Maecenas euismod lacinia ipsum, non vulputate metus eleifend id. Quisque sagittis posuere massa, sed pretium odio                 dignissim eu. In sit amet est non lectus semper pellentesque vitae in tellus. Nullam facilisis auctor quam at pretium.
                </p>

             </div>
</div>

Try that it work on my side. 尝试它在我这边工作。

p { width:500px; display:inline-block; position:relative; margin:0px; } 

just add a width for your p tag. 只需为p标签添加宽度。

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

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