469,360 Members | 1,799 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,360 developers. It's quick & easy.

CSS Syntax for element "X" followed by element "Y" ?

I'm trying to limit the space between an <h1> and an <h2>, which
immediately follows. Isn't there some syntax for this?

<h1>Main Header</h1>
<h2>Sub Header</h2>

There's too much space between the two by default, but I only want to
modify the relative proximity when <h1/> is followed by <h2/>.

This is possible, isn't it?

Thanks,
Jamie
Jul 20 '05 #1
4 8455
On Wed, 19 May 2004 11:06:48 -0400, Jamie Jackson
<mc*************************@hotmail.com> wrote:
I'm trying to limit the space between an <h1> and an <h2>, which
immediately follows. Isn't there some syntax for this?

<h1>Main Header</h1>
<h2>Sub Header</h2>

There's too much space between the two by default, but I only want to
modify the relative proximity when <h1/> is followed by <h2/>.

This is possible, isn't it?

Thanks,
Jamie


There is CSS for this, but support is weak. I suggest classing such h1's
and setting margin-bottom: 0 to them, which leaves the h2 margin only,
which I suspect is desired.
Jul 20 '05 #2

"Jamie Jackson" <mc*************************@hotmail.com> wrote in message
news:9n********************************@4ax.com...
I'm trying to limit the space between an <h1> and an <h2>, which
immediately follows. Isn't there some syntax for this?

<h1>Main Header</h1>
<h2>Sub Header</h2>

There's too much space between the two by default, but I only want to
modify the relative proximity when <h1/> is followed by <h2/>.

This is possible, isn't it?


Yes and no. The actual margin between vertically adjacent blocks is the
greater of the top block's bottom margin and the bottom block's top margin.
You can use

h1 + h2 { margin-top: ??; }

to set the top margin for the H2 element, but there isn't any way to select
an H1 that immediately precedes an H2. (If ALL your H1's are directly
followed by an H2, then you can just set margin-bottom for all H1's.)

Jul 20 '05 #3

"Harlan Messinger" <h.*********@comcast.net> wrote in message
news:2h************@uni-berlin.de...

"Jamie Jackson" <mc*************************@hotmail.com> wrote in message
news:9n********************************@4ax.com...
I'm trying to limit the space between an <h1> and an <h2>, which
immediately follows. Isn't there some syntax for this?

<h1>Main Header</h1>
<h2>Sub Header</h2>

There's too much space between the two by default, but I only want to
modify the relative proximity when <h1/> is followed by <h2/>.

This is possible, isn't it?
Yes and no. The actual margin between vertically adjacent blocks is the
greater of the top block's bottom margin and the bottom block's top

margin. You can use

h1 + h2 { margin-top: ??; }

to set the top margin for the H2 element, but there isn't any way to select an H1 that immediately precedes an H2. (If ALL your H1's are directly
followed by an H2, then you can just set margin-bottom for all H1's.)


Oh, and IE won't recognize the h1 + h2 syntax anyway.

Jul 20 '05 #4
On Wed, 19 May 2004 11:33:47 -0400, "Harlan Messinger"
<h.*********@comcast.net> wrote:

"Harlan Messinger" <h.*********@comcast.net> wrote in message
news:2h************@uni-berlin.de...

"Jamie Jackson" <mc*************************@hotmail.com> wrote in message
news:9n********************************@4ax.com...
> I'm trying to limit the space between an <h1> and an <h2>, which
> immediately follows. Isn't there some syntax for this?
>
> <h1>Main Header</h1>
> <h2>Sub Header</h2>
>
> There's too much space between the two by default, but I only want to
> modify the relative proximity when <h1/> is followed by <h2/>.
>
> This is possible, isn't it?


Yes and no. The actual margin between vertically adjacent blocks is the
greater of the top block's bottom margin and the bottom block's top

margin.
You can use

h1 + h2 { margin-top: ??; }

to set the top margin for the H2 element, but there isn't any way to

select
an H1 that immediately precedes an H2. (If ALL your H1's are directly
followed by an H2, then you can just set margin-bottom for all H1's.)


Oh, and IE won't recognize the h1 + h2 syntax anyway.


Okay guys, thanks for the solutions. I'll play with them.

Jamie
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Barry | last post: by
2 posts views Thread by DraguVaso | last post: by
4 posts views Thread by Tom Eldridge | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.