Solved

Div height in Firefox

Posted on 2007-11-24
4
4,298 Views
Last Modified: 2009-02-13
Hello experts,

I have a simple div that has some PHP generated text inside and a predefined height in CSS.

Sometimes the text inside the div is larger than the div and in IE the div automatically adjuts the height so that the extra text fits in. But this doesn't happen in Firefox. Is there any way I could have the same behaviour in Firefox?

Here is the css for the div:
#daycell #date {
      border: 1px solid #000000;
      font-family: Arial, Helvetica, sans-serif;
      font-size: 12px;
      font-weight: bold;
      color: #FFFFFF;
      height: 30px;
      line-height: normal;
      text-align: center;
      background-color: #666666;
      margin-bottom: 4px;
}

And the div is something like:

<div id="date">
<?=$random_day_quote?>
</div>

Many thanks,
M
0
Comment
Question by:mircea_a
4 Comments
 
LVL 30

Accepted Solution

by:
Steggs earned 250 total points
ID: 20342561
Hello,

Yes. IE treats 'height' like 'min-height'... so if you set a height of 30px... IE will let the div grow with the content when it exceeds 30px. Firefox will not let the div grow if the content exceeds 30px because it treats height as height.

So, you want to use height for IE and min-height for Firefox and others. We use height:auto !important to override the height:30px for Firefox and others. IE does not recognise !important. Try this:

#daycell #date {
      border: 1px solid #000000;
      font-family: Arial, Helvetica, sans-serif;
      font-size: 12px;
      font-weight: bold;
      color: #FFFFFF;
min-height:30px
height:auto !important;
      height: 30px;
      line-height: normal;
      text-align: center;
      background-color: #666666;
      margin-bottom: 4px;
}
0
 
LVL 29

Assisted Solution

by:Göran Andersson
Göran Andersson earned 250 total points
ID: 20342672
There is a rendering error in IE that makes it behave that way. It makes the element grow according to the content, eventhough you have specified the size. Firefox handles this correctly, and honours the specified size.

If you don't specify any height on the element, it will adjust itself according to it's contents. You can for example use padding if you want extra space above and below the text.

#date {
      border: 1px solid #000;
      font-family: Arial, Helvetica, sans-serif;
      font-size: 12px;
      font-weight: bold;
      color: #fff;
      padding: 5px 0;
      line-height: normal;
      text-align: center;
      background-color: #666;
      margin-bottom: 4px;
}
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20558533
Forced accept.

Computer101
EE Admin
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
spacing 5 29
How to set checkbox values for checked or not checked 3 28
Image decoding from Camera 3 45
Modify Table Width 6 13
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now