Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give alt and title for background image?

How to give alt and title for background image? Is it possible?

<div id="cont"></div>

  #cont
  {
     background:#FFF url(../images/post.png) no-repeat;
  }
like image 958
Prashobh Avatar asked Aug 02 '12 09:08

Prashobh


2 Answers

You cannot give an alt and title for a css background, but you can give a title to the div.

<div id="cont" title="Title!"></div>

The title will popup upon mouse-idle over the div element.

like image 160
Rodik Avatar answered Oct 19 '22 05:10

Rodik


it's simple to give a title tag to the div itself.

about the alt, if you desperately need it, the main road to go would be to put an img in the div with height="100%" and width="100%", or, if this gets in your way, add an 1px img in the div, with the alt, but it won't be seen. zindex may also help if the img is getting in your way and oclude other elements.

good luck, alex

like image 36
alex Avatar answered Oct 19 '22 04:10

alex