0

body {
  padding: 50px;
  font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}

a {
  color: "#00b7ff"
}

#content {
  background-color: aquamarine;
  width: 800px;
  height: 300px;
  margin-left: auto;
  margin-right: auto;
  border: 2px solid blueviolet;
}

#room {
  background-color: burlywood;
  margin-bottom: 1em;
}

#messages {
  width: 690px;
  height: 300px;
  overflow: scroll;
  background-color: cadetblue;
  margin-bottom: 1em;
  margin-right: 10px;
  border: 2px solid blue;
}
<div id='content'>
  <div id='room'></div>
  <div id='room-list'></div>
  <div id='messages'></div>

  <form id='send-form'>
    <input id='send-messsage' />
    <input type=s ubmit id='send-button' value='Send' />

    <div id='help'>
      Chat commands:
      <ul>
        <li>Change nickname: <code>/nick [username]</code> </li>
        <li>Join/create room: <code>/join [room name]</code> </li>
      </ul>
    </div>

  </form>

</div>

Results in:

enter image description here

Please explain why is the inner rectangle coming out and what can be done to prevent it?

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411

3 Answers3

2

I believe this might help:

If we reduce the height of #message to 282px it will align properly. Because the above div which is #room is taking 1em = 16px and the #content is taking 2px border. so total 18px it is coming out of the parent div.

I have tried the changes it is working fine.

body {
  padding: 50px;
  font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
}

a {
  color: "#00b7ff"
}

#content {
  background-color: aquamarine;
  width: 800px;
  height: 300px;
  margin-left: auto;
  margin-right: auto;
  border: 2px solid blueviolet;
}

#room {
  background-color: blurrywood;
  margin-bottom: 1em;
}

#messages {
  width: 690px;
  height: 282px;
  overflow: scroll;
  background-color: cadetblue;
  margin-bottom: 1em;
  margin-right: 10px;
  border: 2px solid blue;
}
<div id='content'>
  <div id='room'></div>
  <div id='room-list'></div>
  <div id='messages'></div>

  <form id='send-form'>
    <input id='send-messsage' />
    <input type=s ubmit id='send-button' value='Send' />

    <div id='help'>
      Chat commands:
      <ul>
        <li>Change nickname: <code>/nick [username]</code> </li>
        <li>Join/create room: <code>/join [room name]</code> </li>
      </ul>
    </div>

  </form>

</div>
Dharman
  • 30,962
  • 25
  • 85
  • 135
Sam Phillemon
  • 202
  • 3
  • 10
1
  #content{
    overflow:hidden;
    }
#messages{
line-height:50%;
}
0
  1. The #message div is too big.
  2. The default overflow property of the parent div is evidently set to visible.

Now, as for how to fix it, it depends on what you are trying to do. But those are the two contributing factors.

coreyp_1
  • 319
  • 1
  • 8