Home > Web Front-end > CSS Tutorial > How to Show a Child Div While Hiding Its Parent Div in CSS?

How to Show a Child Div While Hiding Its Parent Div in CSS?

Linda Hamilton
Release: 2024-12-02 14:03:11
Original
809 people have browsed it

How to Show a Child Div While Hiding Its Parent Div in CSS?

How to Display a Child Div while Hiding Its Parent Div

Hiding a parent div while maintaining visibility of its child elements can be achieved through CSS manipulation. Here's how:

Step 1: Hide the Parent Div

.Main-Div {
  display: none;
}
Copy after login

This CSS rule hides the parent div with the class "Main-Div."

Step 2: Make the Child Div Visible

.Main-Div > .Inner-Div {
  visibility: visible;
}
Copy after login

This rule targets the child div (".Inner-Div") within the hidden parent div and makes it visible.

Full Example

Combining these rules, the resulting CSS and HTML code is:

.Main-Div {
  display: none;
}

.Main-Div > .Inner-Div {
  visibility: visible;
}
Copy after login
<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 applying this technique, you can selectively display child elements even if their parent div is hidden.

The above is the detailed content of How to Show a Child Div While Hiding Its Parent Div in CSS?. 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