tags:

views:

368

answers:

6

The code below is an example of what I am trying to do, I need this div to span 600px wide however regardless if I put max-width: 600px; or width: 600px; it is still the width of my PC screen.

How can I make it 600px wide?

<style>
.errormsg3 { 
    text-align: center;
    font-weight:bold;
    color:white;
    font-size: 16px;
    background-color:red;
    padding:8px;
    max-width: 600px;
}
</style>

<?PHP
if (isset($_SESSION['sess_msg'])) {
    echo '<div class="errormsg3">' .$_SESSION['sess_msg']. '</div>';
    unset($_SESSION['sess_msg']);
} 
?>

UPDATE

It is working now, firefox seems to be caching my site so maybe thats why it wouldn't work before.

The div is red, is it possible to add padding to the div, outside of the red part, so there is like a padding/space that is white

+1  A: 

That CSS works fine for me. Are you sure you don't have another CSS rule that's overriding it? Try using a tool like Firebug that can show you the computed style for an element and where it came from.

Amber
I just updated my post, are you using firefox?
jasondavis
A: 

I would try debugging it with Firebug to ensure that nothing is overriding that div class, and checking to see how the containing elements are laid out.

womp
A: 

Add overflow: auto; to your CSS.

dutch
A: 
-max-width: 600px;
+width: 600px;

IE doesn't like max-width. Tested and works in IE/FF/Chrome.

Andrejs Cainikovs
That would be IE6 and below
Steve Gilham
To clarify -- IE 6 and below didn't honour max-width; later versions need a width as well (such as a percentage) which max-width will cap.
Steve Gilham
Thanks for an update!
Andrejs Cainikovs
A: 

Make sure there is nothing inside of your that is larger than the div. IE sometimes (depends on version) renders divs with larger interior content by expanding the div to account for the content.

The easy way to test this is to add overflow:hidden and see if it hides anything.

Russell Steen
A: 

Using this as a HTML file

<html><head><style>
body {text-align: center;}
.errormsg3 { 
    text-align: center;
    font-weight:bold;
    color:white;
    font-size: 16px;
    background-color:red;
    padding:8px;
    width: 600px;
    margin: 0 auto;
}
</style>

<body>
if (isset($_SESSION['sess_msg'])) {
    echo '<div class="errormsg3">' .$_SESSION['sess_msg']. '</div>';
    unset($_SESSION['sess_msg']);
} 
</body>

I get a centred 600px wide message on FF 3.5.2, Opera 9.64, IE 8.0.6001.18813 on Vista 32 bit. IE needs the extra text-align to centre the block, the margin: 0 auto does for the other browsers.

Steve Gilham