If I have parent and child divs and I set text-decoration:underline
on the parent, this will apply to the text content of the child div. If however I set the child div to have position:absolute
or position:fixed
, the text decoration is no longer inherited.
I looked at the spec, but I didn't see anything describing this. Also most places, e.g. MDN, describe text-decoration
and text-decoration-line
as not inherited, which makes me wonder why it ever works. That said, this behaviour seems to be consistent throughout all browsers so I assume that I'm missing something.
See the code snippet below where you can use the buttons to change the position css of the child div:
var positions = ['static','relative','fixed', 'absolute']
for(idx in positions){
$('#buttons').append($('<input/>').prop('type','button').prop('value',positions[idx]))
}
$('input').click(function(){
$('#child').css('position',this.value);
})
#parent{
text-decoration:underline;
}
#buttons{
position:absolute;
top:30px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="parent">
<div id="child">
Sample
</div>
</div>
<div id="buttons"/>