chapter11

So if I have a block element with a zero margin, and a
block element below it with a top margin of 20, the margin
between them would end up being 20?

Right. If one of the margins is bigger, then the margin becomes
the larger of the two, even if one margin is zero. But if the margins
are the same, say, 10 pixels, then they just get collapsed together to
10 pixels total

Can inline elements really have margins?

They sure can, although you'll find that you often don't set the
margins of inline elements. The one exception is images. It is very
common to not only set margins but also borders and padding on
images. And while we aren't going to be setting any inline

What if I have one element nested inside another and they
both have margins? Can they collapse?

Yes, that can happen. Here's how to figure out when they will:
whenever you have two vertical margins touching, they will collapse,
even if one element is nested inside the other. Notice that if the outer
element has a border, the margins will never touch

So how exactly does text work as an inline element since
its content is not an element?

Even if text is content, the browser needs to flow it onto the
page, right? So the browser figures out how much text fits on a given
line, and then treats that line of text as if it were an inline element.
The browser even creates a little box around it.

Can I float to the center?

No, CSS only allows you to float an
element to the left or right. But if you think
about it, if you were to float to the center,
then the inline content under the floated
element would have to be flowed around both
sides of your element, which would be qu

Do margins collapse on floated
elements?

No, they don't, and it's pretty easy
to see why. Unlike block elements that
are flowed on the page, floated elements
are just, well, floating. In other words, the
margins of floated elements aren't actually
touching the margins of the elements in the
norm

Can I float an inline element?

Yes, you sure can. The best example �and a common
one�is to float images. Give it a try�float an image left or right in a
paragraph and you'll see your text flow around it. Don't forget to add
padding to give the image a little room, and possibly a border

Is it correct to think about floated elements as elements
that are ignored by block elements, while inline elements know
they are there?

Yes, that's a good way of thinking about it. Inline content
nested inside a block element always flows around a floated element,
observing the boundaries of the floated element, while block elements
are flowed onto the page as normal. The exception is whe

What is the position property
set to by default?

The default value for positioning
is "static". With static positioning,
the element is placed in the normal
document flow and isn't positioned by
you�the browser decides where it
goes. You can use the float property to
take an element out of the flow, and

Are there position property
values other than static and
absolute?

There are actually four: static,
absolute, fixed, and relative. You've
already heard about static and absolute.
Fixed positioning places an element in
a location that is relative to the browser
window (rather than the page), so fixed
elements never move.

Do I have to use pixels for
positioning?

No�another common way to
position elements is using percentages.
If you use percentages, the positions of
your elements may appear to change as
you change the width of your browser.
So, for example, if your browser is 800
pixels wide, and your element's l

Can I only position <div>s?

You can absolutely position any
element, block or inline. Just remember
that when an element is absolutely
positioned, it is removed from the normal
flow of the page.

So, I can position an inline
element?

Yes, you sure can. For instance,
it's common to position the <img>
element. You can position <em>s,
<span>s, and so on as well, but it isn't
common to do so.

Do I have to specify a width for
an absolutely positioned element just
like the floated elements?

No, you don't have to specify a
width for absolutely positioned elements.
But if you don't, by default, the block
element will take up the entire width
of the browser, minus any offset you
specify from the left or right. This might
be exactly what you wan

Do I have to know how to
use z-indexes to use absolute
positioning?

No, z-indexes tend to be used
most often for various advanced uses
of CSS, especially when web page
scripting is involved, so they're a little
beyond the scope of this book. But they
are a part of how absolute positioning
works, so it's good to know about

Can I float an inline element?

Yes, you sure can. The best example �and a common
one�is to float images. Give it a try�float an image left or right in a
paragraph and you'll see your text flow around it. Don't forget to add
padding to give the image a little room, and possibly a border

Can I float an inline element?

Yes, you sure can. The best example �and a common
one�is to float images. Give it a try�float an image left or right in a
paragraph and you'll see your text flow around it. Don't forget to add
padding to give the image a little room, and possibly a border

Is it correct to think about floated elements as elements
that are ignored by block elements, while inline elements know
they are there?

Yes, that's a good way of thinking about it. Inline content
nested inside a block element always flows around a floated element,
observing the boundaries of the floated element, while block elements
are flowed onto the page as normal. The exception is whe