html - 尝试让我的文本始终具有相同的宽度,即使我的 div 有更多可用空间

标签 html css

我的图片右侧有一张图片和一些文字。

而且我有很多文字,所以我的文字超过了图像的高度,然后我的文字就会在图像的左侧。

但我希望当我的文本超过图像高度时,我希望我的文本继续保持相同的宽度并对齐,就像当我的文本不超过我的图像高度时一样。

为了更好地解释,我想要这个:

enter image description here

不是这个: enter image description here

但是第二张图片是我的,你知道我怎么解决这个问题吗?

我的 fiddle 展示了我拥有的东西:http://jsfiddle.net/43JN5/2/

这是我的 html:

<div>
    <h3>Title of my first post!</h3>    
    <div id="teste">
        <img class="img" style="width:170px;height:170px; float:left;" src="" />
        <p style="background:#fff;">It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem .
            <br />They are good for:<br />
            -Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).<br />
            -Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).<br />
            -Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>

    </div>    

还有我的CSS:

#teste
{   
    text-align:center;
    margin:0 auto 0 auto;
    background:#fff;
}

#teste .img
{
    width:200px;
    height:220px; 
    float:left;
    margin-right:10px;
    border:5px solid red;
    margin-top:15px;

}

#teste p
{
    font-size: 17px;  
    text-align:justify;
    line-height:25px;
    word-spacing:-2px;
    width:100%;
    margin-top:15px;
    min-height:240px;
}

最佳答案

一种方法是将 display:table-cell;vertical-align:top; 应用于图像和文本。

jsFiddle example

关于html - 尝试让我的文本始终具有相同的宽度,即使我的 div 有更多可用空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24213716/

相关文章:

javascript - 使用鼠标位置更改 D3 map 工具提示的类别

html - 使用纯 CSS 显示/隐藏元素的单个按钮

javascript - 当我尝试在我的页面上创建表格时出现此错误 - IndexSizeError : Index or size is negative or greater than the allowed amount

html - 从下拉菜单将多个参数传递给 url

html - 从外部表格边框线填充

css - html + CSS div显示错误

javascript - 选择单选按钮时删除禁用属性

html - 将跨度与按钮放在同一行

javascript - 如何在 JavaScript 中使用条件语句包含多种颜色样式

jquery - 在 jQuery 中使用 .css 方法设置宽度,以窗口调整大小为条件