麻烦迫使文字换行

时间:2012-01-20 21:34:39

标签: html css layout word-wrap textwrapping

我试图将几条消息放入类似线程的布局中。要查看我的结果,请转到此处:http://jsfiddle.net/sunjay03/Aykqc/embedded/result/

如果调整屏幕宽度,您将看到下方消息中的文本布局不正确。除此之外,我似乎无法将日期始终显示在屏幕的右侧。

以下是完整jsfiddle的链接:http://jsfiddle.net/sunjay03/Aykqc/

以下是我想要发生的一些图像: preview with large width enter image description here

任何帮助?

2 个答案:

答案 0 :(得分:1)

这是如何 jsFiddle

<强> HTML

<div class="container">
    <div class="name">John Smith</div>
    <div class="date">Nov. 15, 2010</div>
    <div class="content">Aliquam commodo dui at mauris tempus eu commodo nunc commodo. Quisque accumsan semper sapien, quis tristique odio egestas ac.</div>
</div>
<div class="container">
    <div class="name">John Smith</div>
    <div class="date">Nov. 15, 2010</div>
    <div class="content">Aliquam commodo dui at mauris tempus eu commodo nunc commodo. Quisque accumsan semper sapien, quis tristique odio egestas ac.</div>
</div>
<div class="container">
    <div class="name">John Smith</div>
    <div class="date">Nov. 15, 2010</div>
    <div class="content">Aliquam commodo dui at mauris tempus eu commodo nunc commodo. Quisque accumsan semper sapien, quis tristique odio egestas ac.</div>
</div>

<强> CSS

.name {
    float:left;
}
.date {
    float:right;
}
.content {
    clear:both;
}
.container {
    overflow:auto;
    padding-left:115px;
    background: url(http://www.sunjay.ca/images/logo_notext.gif) no-repeat;
    min-height: 110px;
    margin-bottom: 20px;
}

答案 1 :(得分:1)

我摆弄你的小提琴并做了这件事:

http://jsfiddle.net/S7drj/1/

HTML:

<div class="messages">
    <div class="message">
        <div class="message-image">
            <img src="http://www.sunjay.ca/images/logo_notext.gif" alt="profile_image">
        </div>
        <div class="message-body">
            <div class="message-name">
                <span class="message-date">Nov. 15, 2010</span>
                <h3>John Smith</h3>
            </div>
            <div class="message-text">
                <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
            </div>
        </div>
    </div>
    <div class="message">
        <div class="message-image">
            <img src="http://www.sunjay.ca/images/logo_notext.gif" alt="profile_image">
        </div>
        <div class="message-body">
            <div class="message-name">
                <span class="message-date">Nov. 15, 2010</span>
                <h3>Joe Smith</h3>
            </div>
            <div class="message-text">
                <p>Aliquam commodo dui at mauris tempus eu commodo nunc commodo. Quisque accumsan semper sapien, quis tristique odio egestas ac.</p>
            </div>
        </div>
    </div>
</div>

CSS:

body
{
    margin: 20px;
}

.message
{
    padding: 2px;
    margin: 2px;
    clear: both;
    width:100%;
}

.message .message-image
{
    padding: 5px;
    float:left;
}

.message .message-body
{
}

.message .message-body .message-name
{
}

.message .message-body .message-name h3
{
}

.message .message-body .message-text
{
}

.message .message-body .message-date
{
    float: right;
}

这就是你想要的吗?