4

I'm trying to create a simple chat room using CSS which consist of their message and their username. What I have done is I've wrapped the message and username inside a <div>. The problem occurs when the message goes over the <div>. It doesn't push other <div>s containing other message below.

Thank you for helping me.

here the 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

4 回答 4

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;}

在这里查看演示

于 2013-06-24T07:09:17.990 回答
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>
于 2013-06-24T07:10:35.900 回答
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>
于 2013-06-24T07:20:19.573 回答
0

我认为这可能对您有用,以减少您的代码。对于消息和名称,您放置一个容器 div。只需放浮动:左;min-height:"一些需要的高度" ; 高度:自动;对于你的容器 div。它只会引导你扩大高度

于 2013-06-24T07:17:15.090 回答