CSS div溢出问题

时间:2013-06-24 07:00:02

标签: css

我正在尝试使用CSS创建一个简单的聊天室,其中包含他们的消息和用户名。我所做的是我已将消息和用户名包裹在<div>内。当邮件越过<div>时,会出现此问题。它不会推送包含其他消息的其他<div>

感谢您帮助我。

这里是jsiddle

http://jsfiddle.net/gjuv8/

enter image description here enter image description here

CSS

 body { background-color: #535954}
 .box22 {  content: "";display: block;clear: both;background-color: #FFFFFF;width: 500px;height:400px;position: relative;left: 450px;top: 230px; }

 .user{font-size:18px;font-family:Arial;color: #3A3E42 ;font-weight: bold;float:right;position: relative;left: -20px;top: 0px;}
 .message{font-size:18px;font-family:Arial;color: #3A3E42 ;font-weight: bold;float:left;position: relative;left: 10px;top: 40px;}
 .wrapper{position: relative;left: 10px;top: 50px;background-color: #FFFFFF;width: 480px;height: 100px}

HTML

<link rel="stylesheet" href="css/float.css">
<div class="box22">

<div class="wrapper">
<span class="user">johnny123 </span>
<span class="message">message  message overflow message  message overflowmessage  message overflowmessage  message overflowmessage  message overflow</span>
</div>

<div class="wrapper">d
<span class="user">glasses glasses </span>
<span class="message">michael </span>
</div>
</div>

4 个答案:

答案 0 :(得分:3)

要使其发挥作用还有很多需要改变

  body { background-color: #535954}
    .box22 {  content: "";display: block;clear: both;background-color: #FFFFFF;width: 500px;height:400px;position: relative;left: 450px;top: 230px; }

    .user{font-size:18px;font-family:Arial;color: #3A3E42 ;font-weight: bold;text-align:right}
    .message{font-size:18px;font-family:Arial;color: #3A3E42 ;font-weight: bold;}
    .wrapper{position:relative;background-color: #FFFFFF;width: 480px;}

查看demo此处

答案 1 :(得分:3)

我确定可以试试这个css:

body {
    background-color: #535954
}
.box22 {
    content: "";
    display: block;
    clear: both;
    background-color: #FFFFFF;
    width: 500px;
    height: 400px;
    position: relative;
    left: 450px;
    top: 230px;
}
.user {
    font-size: 18px;
    font-family: Arial;
    color: #3A3E42;
    font-weight: bold;
    float: right;
    position: relative;
    left: -20px;
    top: 0px;
}
.message {
    font-size: 18px;
    font-family: Arial;
    color: #3A3E42;
    font-weight: bold;
    float: left;
    position: absolute;
    left: 10px;
    top: 32px;
}
.wrapper {
    position: relative;
    left: 10px;
    top: 50px;
    background-color: #FFFFFF;
    width: 480px;
    height: 100px
    margin:5px 0;
}

html来源:

<div class="box22">
  <div class="wrapper"> <span class="user">johnny123 </span> <span class="message">message  message overflow message  message overflowmessage  message overflowmessage  message overflowmessage  message overflow</span> </div>
  <div class="wrapper"> <span class="user">glasses glasses </span> <span class="message">michael </span> </div>
</div>

答案 2 :(得分:0)

我认为这可能对你有用,无论如何减少你的代码。对于消息和名称你放一个容器div。只是把浮动:左;最小高度:“一些所需的高度”;高度:自动;为你的容器div。它只会导致你去扩大高度

答案 3 :(得分:0)

你只是设置了很多静态高度和宽度...我会像下面的代码那样做...让我知道它是否适合你的需要,欢呼

CSS:

 body {
        background-color: #535954
    }

    .box22 {
        position: relative;
        display: block;
        width: 50%;
        margin: 0 auto;
        background-color: #FFFFFF;
        position: relative;
    }

    .user {
        position: relative;
        font-size: 18px;
        font-family: Arial;
        color: #3A3E42;
        font-weight: bold;
        text-align: right;
        padding: 2%;
    }

    .message {
        position: relative;
        font-size: 18px;
        font-family: Arial;
        color: #3A3E42;
        font-weight: bold;
    }

    .wrapper {
        position: relative;
        background-color: #FFFFFF;
    }

HTML:

<div class="box22">
    <div class="wrapper">
        <div class="user">johnny123 </div>
        <div class="message">message
            message overflow message message overflowmessage message
            overflowmessage message overflowmessage message overflow
            <br />
            overflowmessage message overflowmessage message overflow
            <br />
            overflowmessage message overflowmessage message overflow
            <br />
            overflowmessage message overflowmessage message overflow
        </div>
    </div>

    <div class="wrapper">
        <div class="user">glasses glasses </div>
        <div class="message">
            michael
            <br />
            overflowmessage message overflowmessage message overflow
            <br />
            overflowmessage message overflowmessage message overflow
        </div>
    </div>
</div>