Connecting Tech Pros Worldwide Help | Site Map

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

Jamie Jackson
Guest
 
Posts: n/a
#1: Jul 20 '05
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
Neal
Guest
 
Posts: n/a
#2: Jul 20 '05

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


On Wed, 19 May 2004 11:06:48 -0400, Jamie Jackson
<mcsqueebagePleaseDontSpamMe@hotmail.com> wrote:
[color=blue]
> 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[/color]

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.
Harlan Messinger
Guest
 
Posts: n/a
#3: Jul 20 '05

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



"Jamie Jackson" <mcsqueebagePleaseDontSpamMe@hotmail.com> wrote in message
news:9ntma05o6r5tn736nt4hushgnaaki1acpr@4ax.com...[color=blue]
> 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?[/color]

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.)

Harlan Messinger
Guest
 
Posts: n/a
#4: Jul 20 '05

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



"Harlan Messinger" <h.messinger@comcast.net> wrote in message
news:2h1c5mF7sg5eU1@uni-berlin.de...[color=blue]
>
> "Jamie Jackson" <mcsqueebagePleaseDontSpamMe@hotmail.com> wrote in message
> news:9ntma05o6r5tn736nt4hushgnaaki1acpr@4ax.com...[color=green]
> > 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?[/color]
>
> 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[/color]
margin.[color=blue]
> You can use
>
> h1 + h2 { margin-top: ??; }
>
> to set the top margin for the H2 element, but there isn't any way to[/color]
select[color=blue]
> 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.)[/color]

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

Jamie Jackson
Guest
 
Posts: n/a
#5: Jul 20 '05

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


On Wed, 19 May 2004 11:33:47 -0400, "Harlan Messinger"
<h.messinger@comcast.net> wrote:
[color=blue]
>
>"Harlan Messinger" <h.messinger@comcast.net> wrote in message
>news:2h1c5mF7sg5eU1@uni-berlin.de...[color=green]
>>
>> "Jamie Jackson" <mcsqueebagePleaseDontSpamMe@hotmail.com> wrote in message
>> news:9ntma05o6r5tn736nt4hushgnaaki1acpr@4ax.com...[color=darkred]
>> > 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?[/color]
>>
>> 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[/color]
>margin.[color=green]
>> You can use
>>
>> h1 + h2 { margin-top: ??; }
>>
>> to set the top margin for the H2 element, but there isn't any way to[/color]
>select[color=green]
>> 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.)[/color]
>
>Oh, and IE won't recognize the h1 + h2 syntax anyway.[/color]

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

Jamie
Closed Thread


Similar HTML / CSS bytes