Jump to content

Recommended Posts

the main reason to do this is because you should never use an image to convey anything you can do with semantic markup.

 

The use of background images and hiding text allows you to provide a nice eye-catching design or company logo but still maintain readability for text only or assistive technology devices.

Link to comment
https://forums.phpfreaks.com/topic/104700-why-background-image/#findComment-536364
Share on other sites

If you use a <img src="" />, enclosed within <a></a> (so it can link back to the homepage) and that uses some style of margin...  will create problems in modern browsers like FF.

 

FF makes a border around the link (after you click it). Since there is a "margin: something" it makes the linked border from the initial place the image was pushed from with the margin, instead of enclosing the image properly.

 

A background image would fix this problem.

Link to comment
https://forums.phpfreaks.com/topic/104700-why-background-image/#findComment-536466
Share on other sites

Hi. thank you guys.

 

I have a question regarding the links on image. How should I set link on background-image?

 

For example i put the image in <h2 style='background-image:url(img.jpg);'>, and i want to set a link on the image shows.

 

I've tried <a><h2></h2></a>, it works, but it's not allowed in xhtml.

 

any advice?

 

regards,

ayok

Link to comment
https://forums.phpfreaks.com/topic/104700-why-background-image/#findComment-536562
Share on other sites

Just to clarify, ayok, you "should" have text inside the <h2> tags.

 

Like TM said, if you are using an image instead of text, that's poor markup - and if you do that anyway, you may as well just use the <img src="" /> instead of the image as background. At least that way people with visual disabilities will know there is an image there.

 

Using blank header <h2> tags removes any benefit of using headers in the first place.

Link to comment
https://forums.phpfreaks.com/topic/104700-why-background-image/#findComment-537060
Share on other sites

<h2><a href="">text</a><h2>

 

give the a tag in side h2...

 

h2 a

{

display: block;

text-indent: -9999px;

}

 

When you turn images off, you're left with nothing there. This technique is discouraged in favour of using an empty span that is layered over the top of the text - the unsemantic markup is a small price to pay for increased accessibility:

 

<h2><a href="#non">text<span></span></a></h2>

h2 a {position:relative; display:block; width:200px; height:20px; overflow:hidden;}
h2 a span {position:absolute; top:0; left:0; width:100%; height:100%: background:url(/images/h2-background.gif) no-repeat 0 0; cursor:pointer;}

Link to comment
https://forums.phpfreaks.com/topic/104700-why-background-image/#findComment-537801
Share on other sites

If you use a <img src="" />, enclosed within <a></a> (so it can link back to the homepage) and that uses some style of margin...  will create problems in modern browsers like FF.

 

FF makes a border around the link (after you click it). Since there is a "margin: something" it makes the linked border from the initial place the image was pushed from with the margin, instead of enclosing the image properly.

 

A background image would fix this problem.

 

Just to come back to this. There is no technical problem with using an image within an anchor. Just set the image to {display:block;} and use {border:0;} to avoid the issues with the inline "margin" often found at the base of the image. There are many sites that use img tags for logos with no technical problem.

Link to comment
https://forums.phpfreaks.com/topic/104700-why-background-image/#findComment-539487
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.