Image and text on same line?

陌路散爱 提交于 2019-12-24 14:26:06

问题


This is giving me a headache...

I'm trying to have an image of fixed height/width on the left, and text on the right, in the same line of course. The overall container has a dynamic width of 90% of viewport, meaning that the text on the right will also have a dynamic width (90% - image width) since the image on the left is fixed. The text needs to be aligned left, so "float:right" won't work. I've tried countless combinations of floats, aligns, table cells, etc, nothing works... closest I've got to was they were in the same line, but the text was forced aligned to the right.

Image of what I mean: http://i.imgur.com/QRDhLro.png

#container {
overflow:hidden;
position:relative;
width:90%;
min-width:800px;
margin-bottom:20px;
margin-top:20px;
margin-left:auto;
margin-right:auto;
}
.leftimage {
width:600px;
height:100px;
}
.righttext {    
float:right;
}

...
...

<div id="container">

    <div class="righttext">lorem ipsum lorem ipsum <br> lorem ipsum lorem ipsum </div>

    <div class="leftimage"><img src="../pictures/test.png"></div>

</div>

回答1:


Move

<div class="righttext">lorem ipsum lorem ipsum <br> lorem ipsum lorem ipsum </div>

after

<div class="leftimage"><img src="../pictures/test.png"></div>

CSS:

.righttext{
    float: none;
    margin-left: 600px;
}



回答2:


Maybe just:

<img src="#" align="left">
<p>This is my paragraph to the right of my image</p>

This does work, as demonstrated here: http://jsfiddle.net/tWqwh/



来源:https://stackoverflow.com/questions/15622844/image-and-text-on-same-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!