By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,648 Members | 1,203 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,648 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a

"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

P: n/a

"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

P: n/a
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.