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>
3
  • +1 For a clearly framed question. Commented Jun 24, 2013 at 7:07
  • without looking too closely at your code, I think you can accomplish it by simply using float: left and clear: left in the wrapper class. To bring the contents of it a little bit to the right, you can use padding-left: 10px. Commented Jun 24, 2013 at 7:07
  • If you want to show whole messages why do you put height: 100px there? And you don't need to float the elements there I think. I think you are making something easy into something difficult. Commented Jun 24, 2013 at 7:14

4 Answers 4

3

There are a lot to change to make it work

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

Check out the demo here

Sign up to request clarification or add additional context in comments.

1 Comment

@JackRoster: wellcome, glad to be of help.
3

may i sure try this 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 source :

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

Comments

0

I think this may work for u irrespectively to reduce ur code.For the messages and name u put one container div. just put float:left; min-height:"some required height" ; height:auto; for ur container div. it will simply lead u to go with expanded height

Comments

0

You are just setting to much static heights and widths ... i would do it like the code below ... let me know if it works for your need, cheers

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>

2 Comments

i just tried ur solution , you need to specify a <br> otherwise the content is just going to overflow outside the div , thank u for the help :)
Oh, no, i jus put the <br/>'s there to save lines of text, try to remove them and write big ammounts of text you will see the same effect ... cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.