Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent overlapping of text on bottom-aligned DIV element

Tags:

html

css

position

When I try to bottom-align text in a DIV element, I face the issue that when the text above is long enough to reach the bottom of the DIV element, it overlaps with the bottom-aligned text. Here is the code: http://jsfiddle.net/Kw758/

<html>
<head>
<title>Date</title>
<style type="text/css">
#container {
  position: relative;
  border: 1px solid gray;
  width: 200px;
}

#date {
  margin-top: 1em;
  position: absolute;
  bottom: 5px;
  right: 5px;
}
</style>
</head>
<body>
<div id="container">
    <span>
    This is a very very long text that might overlap with the date
    just below this.
    </span>
    <div id="date">
    January 1, 2012
    </div>
</div>
</body>
</html>

How can I prevent the overlapping of the text in SPAN element and the text in DIV element?

The reason why I am bottom-aligning it with 'position' attribute instead of just setting the date to 'float: right' is because in my actual problem, the DIV is supposed to have a min-height set, so the bottom border of the DIV element might be very far away from the text in the SPAN element.

like image 855
Lone Learner Avatar asked Nov 13 '22 08:11

Lone Learner


1 Answers

Wouldn't it be enough to set a padding-bottom to #container?

#container {
  position: relative;
  border: 1px solid gray;
  width: 200px;
  padding-bottom: 30px; /* depending on font-size of span */
}
like image 194
Simon Steinberger Avatar answered Dec 18 '22 19:12

Simon Steinberger