Reply LinkBack Thread Tools Search this Thread
Old 01-06-2007, 09:27   #1 (permalink)
Michal
Registered User
 
Join Date: Dec 2004
Posts: 42
Border underline for heading text...

Hey there.

I'm having a problem creating the desired effect for some heading text.

As per a design I'm coding from, I need the underline of the heading text to be a bottom margin (due to it's positioning and it's thickness).

I've added the underline effect with the border-bottom property, but my question is... how do I get the "underline" to only run along as far as the text itself goes, while behaving like a block level element in relation to the surrounding text?

If I make the heading into a inline element, the border-bottom underline displays how I would like, but unfortunately it effs up in terms of layout.

Is there any way to achieve this without resorting to putting the heading inside a div?


Any help would be muchly appreciated.
  Reply With Quote
Old 01-06-2007, 09:42   #2 (permalink)
steveb
389 ppm and rising
 
steveb's Avatar
 
Join Date: Aug 2005
Location: Järvenpää, Finland
Posts: 4,940
Sounds like that's something you need to incorporate into the text itself, rather than try to get CSS to do it. You might even need to turn the affected text into a graphic, which probably won't be a big problem for heading text.
__________________
My free fonts www.utfi.net
  Reply With Quote
Old 01-06-2007, 10:15   #3 (permalink)
Michal
Registered User
 
Join Date: Dec 2004
Posts: 42
Unfortunately it looks as if it does actually need to be text and not graphic.

Hopefully there's a way, but if it can't be done I'll have to take it up with the designer on Monday.

In the past I've actually thought about including such headings into one my own designs, only to decided against it as I was unsure of how to implement them correctly. I'd be very interested to know of a method, if only for that reason!
  Reply With Quote
Old 01-06-2007, 10:20   #4 (permalink)
Stickman
Dr. Lucien Sanchez
 
Stickman's Avatar
 
Join Date: Mar 2003
Location: UK
Posts: 5,527
It shouldn't be that difficult. A link would help though - what does 'eff up in terms of layout' mean?

Have you tried float:left and display:block?

Are you even using floats?
  Reply With Quote
Old 01-06-2007, 10:23   #5 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 6,998
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
wrap an inline element around it maybe? <strong> <em> <span> and style that to display the border.

<hx><em>Heading here</em><hx>
__________________
  Reply With Quote
Old 01-06-2007, 10:43   #6 (permalink)
Michal
Registered User
 
Join Date: Dec 2004
Posts: 42
Quote:
Originally Posted by Stickman
It shouldn't be that difficult. A link would help though - what does 'eff up in terms of layout' mean?

Have you tried float:left and display:block?

Are you even using floats?
By 'effing up in terms of layout', I meant that all the text that should be below the header just runs over it as if the header was invisible or something.

display:block was precisely what I wasn't using in the header, due to that fact that it forced the border/underline beyond the length of the text. Instead, I made the header inline, which caused said layout problems.




Quote:
Originally Posted by emilpaun
wrap an inline element around it maybe? <strong> <em> <span> and style that to display the border.
Just done exactly that with <span> and it works a treat! Thanks mate!

I have little experience in using <span>. For some reason I was thinking that the only way around this might be to use a <div>, but was reluctant to put that among text.

Please excuse the stupidity, I'm only a part time coder (more of a designer), and doing this task as part of work experience! I'm learning all the time!


A question - is <span> preferable to <em> or <strong> in such scenarios?
  Reply With Quote
Old 01-06-2007, 10:48   #7 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 6,998
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
erm, I think span is "inert" from a presentational point of view. Which means it bears little importance on the way tex is rendered in the browser or on the way it is interpreted by screenreaders or search engines, whereas <strong> and <em> imply emphasis, rendering text bold or italic.

Or I might be completely wrong.
Some reading here
SPAN and Div

Also read on block and inline elements
__________________
  Reply With Quote
Old 01-06-2007, 10:53   #8 (permalink)
Stickman
Dr. Lucien Sanchez
 
Stickman's Avatar
 
Join Date: Mar 2003
Location: UK
Posts: 5,527
Quote:
Originally Posted by Michal
display:block was precisely what I wasn't using in the header, due to that fact that it forced the border/underline beyond the length of the text.
..on it's own. I meant using float as well.

Anyway, span away.
  Reply With Quote
Old 01-06-2007, 10:55   #9 (permalink)
Michal
Registered User
 
Join Date: Dec 2004
Posts: 42
Quote:
Originally Posted by emilpaun
erm, I think span is "inert" from a presentational point of view. Which means it bears little importance on the way tex is rendered in the browser or on the way it is interpreted by screenreaders or search engines, whereas <strong> and <em> imply emphasis, rendering text bold or italic.

Or I might be completely wrong.
Some reading here
The global structure of an HTML document
So, in other words, using <strong> might be more appropriate than <span> when applied to prominent header text?

Also, is it better to have such tags within the <h#> tags or enclosing them?
  Reply With Quote
Old 01-06-2007, 11:01   #10 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 6,998
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
<h#> are block level elements, they can not be enclosed in inline elements, but the other way around.
__________________
  Reply With Quote
Old 01-06-2007, 11:20   #11 (permalink)
Michal
Registered User
 
Join Date: Dec 2004
Posts: 42
Quote:
Originally Posted by Stickman
..on it's own. I meant using float as well.

Anyway, span away.

I've just tried:

Code:
h1 { display: inline; float: left; }

But for some reason adding clear:right doesn't work (the paragraph text runs up alongside it's right side)... although adding clear:left to <p> has the desired effect.

It appears to work wonderfully in fact, and would eliminate the need for me to use <span> in this instance.

But just to make sure, is adding clear:left to a paragraph okay? Could it cause problems?
  Reply With Quote
Old 01-06-2007, 11:22   #12 (permalink)
Michal
Registered User
 
Join Date: Dec 2004
Posts: 42
Quote:
Originally Posted by emilpaun
<h#> are block level elements, they can not be enclosed in inline elements, but the other way around.
What about making a <h#> into an inline element, as per my above post?
  Reply With Quote
Old 01-06-2007, 12:14   #13 (permalink)
emil
dt immigrant
 
emil's Avatar
 
Join Date: Nov 2004
Location: Bucharest - Romania
Posts: 6,998
Send a message via ICQ to emil Send a message via MSN to emil Send a message via Yahoo to emil Send a message via Skype™ to emil
you can assign a css property to make it behave like an inline style, but codewise your html would be invalid should you decide to do it the other way around. (ie wrap the h in strong)
__________________
  Reply With Quote
Old 01-06-2007, 12:32   #14 (permalink)
Agricola
Senior Member
 
Agricola's Avatar
 
Join Date: May 2007
Location: England
Posts: 365
To throw a spanner in the works, underlined text should ONLY be used for hyperlinks.
  Reply With Quote
Old 01-06-2007, 13:07   #15 (permalink)
Michal
Registered User
 
Join Date: Dec 2004
Posts: 42
But I think the object sometimes, when a bottom border is applied to headings like this, is for it to appear as a divider rather than an text underline per se.
  Reply With Quote
Old 01-06-2007, 13:40   #16 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
So, if I get you right, you want to underline text in a heading? If so, why are you using border-bottom??

What's wrong with h* { text-decoration: underline; }

I really hope I'm missing something...

Code:
h1 { display: inline; float: left; }
I don't see how this should work. The float sets it to display: block; so the display: inline; should be overruled...in other words, no different than just float: left; by itself.

However, that above is invalid CSS since you are required to specify a width on a float (except in the case of replaced elements, which headings are not).

So, it looks like floating it to control the width is out.
  Reply With Quote
Old 01-06-2007, 13:52   #17 (permalink)
Michal
Registered User
 
Join Date: Dec 2004
Posts: 42
pgo, in the designs I am building the site from, the underline is a different colour to the text, is thicker in proportion, and is about 15 pixels below it... hence the need to use a bottom border.
  Reply With Quote
Old 01-06-2007, 13:57   #18 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
Ah, I get it. So, what's wrong with:

HTML Code:
<h*><span>Text</span></h*>

Code:
h* span { border-bottom: whatever; }
That should work, as far as I know, borders can be applied to inline elements like spans.

Span will be a better bet for you since the heading itself already implies emphasis and you're only using the inline element as a style hook (i.e. it should have no semantic meaning).
  Reply With Quote
Old 01-06-2007, 14:01   #19 (permalink)
Michal
Registered User
 
Join Date: Dec 2004
Posts: 42
Quote:
Originally Posted by pgo
Code:
h1 { display: inline; float: left; }
I don't see how this should work. The float sets it to display: block; so the display: inline; should be overruled...in other words, no different than just float: left; by itself.

However, that above is invalid CSS since you are required to specify a width on a float (except in the case of replaced elements, which headings are not).

So, it looks like floating it to control the width is out.
With this method, the underline/border renders so that extends no further than the text, and that's what I want. Coupled with clear:left applied to the following paragraphs, it seems to work perfectly.

But I'm unsure if it's a right way of doing things, so I'm using <span> for the time being.
  Reply With Quote
Old 01-06-2007, 14:21   #20 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
Quote:
Originally Posted by Michal
With this method, the underline/border renders so that extends no further than the text, and that's what I want. Coupled with clear:left applied to the following paragraphs, it seems to work perfectly.
It may "work" but it's not valid.

Besides, like I said, the display: inline; float: left; combination is redundant.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8