5 replies [Last post]
rooty
Offline
newbie
Last seen: 9 years 51 weeks ago
Joined: 2004-12-29
Posts: 8
Points: 0

I have a div with a background-image (set to repeat on both x,y-axis) and I'd like to make an alt text so when you hover over it it shows the desired message. Is this possible?

Also my XHTML doesn't validate. Seems you can't enclose a div within <a></a>

http://dev.nullnetwork.com/test/eCom/

doddnetwork
Offline
Regular
Last seen: 9 years 50 weeks ago
Joined: 2005-01-03
Posts: 15
Points: 0

How to add alt text to a DIV?

DIV are divides and are used to split areas of a page up.
They act as containers for text, images other divs etc...

I'd replace the divs with spans where they lie within paragraphs of text etc...

as for you alt question...

check out:
http://www.meyerweb.com/eric/css/edge/popups/demo.html

you should be able to manipulate this so that the

here is an example:

<style>

a.info{
    position:relative; /*this is the key*/
    z-index:24;
    color:#000;
    text-decoration:none}

a.info:hover{z-index:25; background-color:#76B7E7}

a.info span{display: none}

a.info:hover span{ /*the span will display just on :hover state*/
    display:block;
    position:absolute;
	font-weight:bold;
    top:0px;left:20%; width:100px;
    margin-left:-125px;
	border:1px solid #0cf;
    background-color:#0099FF;
	color:#ffffff;
    text-align: center;
	z-index:9999999;}
</style>


<div id=''>
    <a class="info" href="#">?<span>Does the client smoke?</span></a>
</div>

The other alternative I suppose would be some sort of javascript.

Do you mind me asking why you want to display alternative text to the image being displayed?

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 1 week 7 hours ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

How to add alt text to a DIV?

rooty,
Just use the 'title' attribute;

title="text for display goes here"

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

rooty
Offline
newbie
Last seen: 9 years 51 weeks ago
Joined: 2004-12-29
Posts: 8
Points: 0

How to add alt text to a DIV?

doddnetwork,

I've read you can do that with DIVs while seting the display to block and changing the cursor state

Hugo thanks, didn't think of that :?

What could I do with the XHTML W3C error though? Use span instead?

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 1 week 7 hours ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

How to add alt text to a DIV?

You can't nest a block level element i.e div, p etc within an inline element as in a anchor you can use a span which is for enclosing lines of text or inline elements.
You seem to have used some empty spans though I'm not sure why they don't actually span anything if you want the title attribute move it to the anchor along with the styling.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

doddnetwork
Offline
Regular
Last seen: 9 years 50 weeks ago
Joined: 2005-01-03
Posts: 15
Points: 0

How to add alt text to a DIV?

title does work, although I have found that it sometime has a low response time.

In testing some image with alt vs title I found that alt responded faster than title in IE and both were same in mozilla...

If you add the title make sure it all makes sense, Try testing it:

turn images off (browser setting).
turn images off and style sheet off.
style sheet off.

You may find that the title is only relevant when the background picture is there????

Just a thought

For the div thing, just replace it with a span...