fixed menu bar

aric87

New Member
New to web design, trying to do a fixed nav bar. The background for the bar is indenting on the left, with the page margin, however it is not stopping on the right.
 

Attachments

  • home1.txt
    2.1 KB · Views: 25

leroy30

New Member
Do you have a question or are you just telling us?

I don't mean to be rude but this is not a support forum. If you plan to ask help questions on your very first post at least *ASK* the question and put some relevant detail to help us help you. Simply posting the whole file of your page isn't helping us help you it's taking the least amount of time to ask us to put in the most amount of time to help you!

Re-write your question and post a picture of what it IS doing and another one of what it SHOULD be doing and you'll find it easier to get a response from here!
 

aric87

New Member
My apologies, I did not mean to be rude. I am wondering why the background for the mav bar would not follow the body margins. I figured the text file
Would load faster than images. There is a company logo, which spans the page, and I would like he nav bar to match. The image is set at 100%, as is the nav bar. When you set the image size, or text or anything for that matter, and add padding to that, would The padding expand into the margins? Or would
The padding reduce the image size to fit within the page constraints because it is a %?

Again, I apologize for being rude. I am very eager to learn and there doesn't seem to be a beginner/ dumb question forum.

Thank you!
 

Phreaddee

Super Moderator
Staff member
box model = margin + border + padding + WIDTH + padding + border + margin

so a div set at 200px with padding of 20px margin of 20px and a border of 5px would be 290px (20+5+20+200+20+5+20)

the same is true with % so if you've set a width to 100% and then add padding and or margins and or borders it will thus be larger that 100%, which either breaks out of its parent container or wraps.
 

PixelPusher

Super Moderator
Staff member
Bare in mind, the div element is a block element. Meaning it will span the width of its parent by default when its position is "static" or "relative" and adjust for any padding, margins or borders you apply (without having a width value declared).

It is only when you change the position to "absolute" or "fixed" that a defined will be required to have the element span the width of its parent, and it is then that you will need to consider the space taken by padding, margins and borders (as stated by Phraddee).
 

chrishirst

Well-Known Member
Staff member
Bare in mind, the div element is a block element. Meaning it will span the width of its parent by default when its position is "static" or "relative" and adjust for any padding, margins or borders you apply (without having a width value declared).
Maybe a little bit misleading there. The width property value applies to the content area of the W3c box, so if you have borders, padding or margins applied to the child element it will reduce the child content area width to allow the margin edges of the element to fit inside the parent element's padding edges.


It is only when you change the position to "absolute" or "fixed" that a defined will be required to have the element span the width of its parent, and it is then that you will need to consider the space taken by padding, margins and borders (as stated by Phraddee).
Not quite right, absolute and fixed positioned block elements will take their width from the padding edges the nearest positioned ancestor if the element's width property is undefined or set to auto.


http://www.w3.org/TR/CSS2/visudet.html#containing-block-details
If the element has 'position: absolute', the containing block is established by the nearest ancestor with a 'position' of 'absolute', 'relative' or 'fixed', in the following way:

In the case that the ancestor is an inline element, the containing block is the bounding box around the padding boxes of the first and the last inline boxes generated for that element. In CSS 2.1, if the inline element is split across multiple lines, the containing block is undefined.
Otherwise, the containing block is formed by the padding edge of the ancestor.

If there is no such ancestor, the containing block is the initial containing block.
 

Ennesus

New Member
box model = margin + border + padding + WIDTH + padding + border + margin

so a div set at 200px with padding of 20px margin of 20px and a border of 5px would be 290px (20+5+20+200+20+5+20)

the same is true with % so if you've set a width to 100% and then add padding and or margins and or borders it will thus be larger that 100%, which either breaks out of its parent container or wraps.

You can change the box model with

-webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
-moz-box-sizing: border-box; /* Firefox, other Gecko */
box-sizing: border-box; /* Opera/IE 8+ */

So the padding comes inside

Check
http://css-tricks.com/box-sizing/
 
Top