Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML: stop Child elements from inheriting parent's [title] attribute

The issue is that when I declare a title attribute for a 'wrapper' element, the a tool-tip shows up when the cursor falls inside the 'content' element as well. How do I prevent this(inheritance) from happening?

<style> 
  #content{ margin:25px;}
</style>

<div id='wrapper' title='example'>
  <div id='content'>

  </div>
</div>

(I only want the tool-tip to show up between the edges of the 'content' and 'wrapper' elements, instead of in both)

like image 212
whamsicore Avatar asked May 04 '11 10:05

whamsicore


People also ask

How do we force children to inherit CSS properties of parent in react?

Only direct child elements can inherit a CSS property from its parent element using the inherit value if the CSS property is set by the element's parent element. This is to ensure that the CSS property to be inherited is an inheritable property. The div1 has a height set to 100px . div1ChildChild .

What is parent attribute in HTML?

A parent is an element that is directly above and connected to an element in the document tree.


3 Answers

Same problem here.

Found out that specifying title=' ' works for Chrome and FireFox but shows annoying tool-tip with one space in IE. title='' works for IE but completely ignored by Chrome and FireFox thus showing parent's tool-tip.

Didn't figured out how to make in cross-browser :(

like image 156
user1614543 Avatar answered Oct 02 '22 22:10

user1614543


I had the same problem. I found out that you can prevent this by giving the child elements a dummy title title=" ".

like image 21
mightyplow Avatar answered Oct 02 '22 22:10

mightyplow


I don't think this is possible with pure CSS or HTML.

One way to hack this is using client side code.. basic plain JavaScript example:

window.onload = function() {
    var oDiv = document.getElementById("content");
    oDiv.onmouseover = function() {
        this.parentNode.setAttribute("old_title", this.parentNode.title);
        this.parentNode.title = "";
    };
    oDiv.onmouseout = function() {
        this.parentNode.title = this.parentNode.getAttribute("old_title");
    };    
};

This will "clear" the parent div title upon mouse over of the contents, and restore the title when the mouse leave the contents.

Live test case: http://jsfiddle.net/UASPZ/

like image 23
Shadow Wizard Hates Omicron Avatar answered Oct 02 '22 22:10

Shadow Wizard Hates Omicron