Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is my content showing outside the div?

Tags:

html

css

I have a "bubble" with content, which is working fine. Now, I want to display a count (2 lines) which should always be in the bottom right corner of that div, INSIDE it. I tried many things but for some reason it always overlaps the div and shows outside. What am I doing wrong?

<style type="text/css">
body{
background-color:#f3f3f3;
}
.commentbox{
background-color: #ffffff;
width: 200px;
border-color: #D1D1D1;
border-radius: 4px;
border-style: solid;
border-width: 1px; 
padding-bottom: 9px;
padding-left: 9px;
padding-right: 9px;
padding-top: 9px;
position:relative;
}
.count{
float:right;
text-align:right;
}
</style>

<div class="commentbox">
<div class="title">Some several lines long long long long content text goes here 
</div>
<div class="count">123<br>456</div>
</div>
like image 486
user1227914 Avatar asked Apr 08 '12 10:04

user1227914


People also ask

How do I make the content stay inside a div?

You can force the content of the HTML <div> element stay on the same line by using a little CSS. Use the overflow property, as well as the white-space property set to “nowrap”.

How do I make an image not overflow in a div?

Answer: Use the CSS max-width Property Additionally, you can also apply the max-height property if you've a fixed height div element, so that the image doesn't overflow from the div's boundary horizontally or vertically.


3 Answers

Since you're already using position:relative on the parent div. Try this instead:

.count {
   position:absolute;
   right:0;
   bottom:10px;
}
like image 146
rgin Avatar answered Oct 06 '22 21:10

rgin


You are floating .count so it doesn't influence it's parent container's height.

Set overflow: hidden on the parent (.commentbox) or use one of the other float containing techniques so that it does.

like image 27
Quentin Avatar answered Oct 06 '22 23:10

Quentin


Do you really need float: right; for .count? I think text-align should be enough for the desired layout.

like image 26
diewie Avatar answered Oct 06 '22 21:10

diewie