Solved

Div height in Firefox

Posted on 2007-11-24
4
4,306 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.

803 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