Home > Web Front-end > CSS Tutorial > Can a Child Div Be Visible While Its Parent Div Is Hidden?

Can a Child Div Be Visible While Its Parent Div Is Hidden?

Susan Sarandon
Release: 2024-12-08 04:37:17
Original
925 people have browsed it

Can a Child Div Be Visible While Its Parent Div Is Hidden?

Displaying Child Div Inside a Hidden Parent Div

Can a child div be displayed while its parent remains hidden? While it may seem counterintuitive, this scenario is achievable.

Consider the following HTML code:

<style>
  .Main-Div {
    display: none;
  }
</style>

<div class="Main-Div">
  This is some Text..
  This is some Text..
  <div class="Inner-Div'">
    <a href="#"><img src="/image/pic.jpg"></a>
  </div>
  This is some Text..
  This is some Text..
</div>
Copy after login

By default, the 'Main-Div' class is hidden using 'display: none;' in CSS. However, the goal is to show the 'Inner-Div' class within this hidden parent.

To accomplish this, it's necessary to control visibility rather than display. CSS can be utilized as follows:

.parent>.child {
  visibility: visible;
}

.parent {
  visibility: hidden;
  width: 0;
  height: 0;
  margin: 0;
  padding: 0;
}
Copy after login

Here, the 'visibility' style is set to 'visible' for the child div, while the parent div's 'visibility' is set to 'hidden'. Additionally, the parent div's width and height are defined as zero to minimize its presence. By doing this, the child div becomes visible within the hidden parent div.

For a complete example, refer to the following JSFiddle: http://jsfiddle.net/pread13/h955D/153/.

The above is the detailed content of Can a Child Div Be Visible While Its Parent Div Is Hidden?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template