Skip to content Skip to sidebar Skip to footer

Display Html Child Element When Parent Element Is Display:none

Is there any mechanism to display a child element when its parent element is display: none? The situation is a validation error on a hidden tab. I want to surface the error message

Solution 1:

No this isn't possible. display:none hides the element, and thus any child elements will not be displayed.

EDIT:

This might be along the lines of what you want, if you're able to switch from using display to visibility.

.hide {visibility: hidden;}
.reshow {visibility: visible;}

Using this method you can hide the contents of the parent element but show the specific <li> you want. The only caveat is the parent markup will still take up screen real estate. Just won't be shown to the user. That may or may not break the layout you're looking for.

http://jsfiddle.net/vLYnk/2/

Solution 2:

No, this is not possible. You could instead move the child element out of its hidden parent and insert it somewhere else in the markup (e.g. via JavaScript).

Solution 3:

For specific situations you can use this either:

.hidden-container *{display:none;}
.hidden-container.show-again{display:block}

That will keep .hidden-container displayed, but everything except .show-again container will have display property set to none.

jsFiddle

EDIT:

note, that it'll reset all display properties in childs of .hidden-container if declared after their styles.

Solution 4:

You could instead of using display: none; to hide your element move it out of the viewport via position: relative/absolute; and left: -9999em; Than give the visible child a position: relative; and left: 9999em;

The downfall of this solution is, that the "reshown" element is out of the element flow if you used position: absolute. (Not occupying the space it needs and not pushing down following elements) Or that you occupy more space than is actually needed, when using position: relative.

http://jsfiddle.net/vLYnk/3/

Solution 5:

Just add .hide:

font-size: 0;
margin: 0;
padding: 0;

It will not occupy the space just as display none

Post a Comment for "Display Html Child Element When Parent Element Is Display:none"