Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to hide a text of outside element, but make a text of inside element visible

I have a document where an element of class A is inside an element of class B. For example:

<body>
  <div class="B">
    This is text of class B.
    <div class="A">
      This is text of class A.
    </div>
  </div>
</body>

I want to hide the text of class B, but show the text of class A. How to write a CSS to do this?

I tried:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    .B {
      display: none; 
    }
    
    .A {
      display: inline; 
    }

But it hides A (not surprising: it’s inside B which is not displayed).

I also tried:

    .B {
      visibility: hidden; 
    }
    
    .A {
      visibility: visible; 
    }

It hides B, but it leaves the empty space in place of B. That is not what I want. I want to hide it completely. How to do this?

>Solution :

Paulie_D’s comment of setting the font-size works. Set "B" to zero and "A" to initial.

.A {
    font-size: initial;
}

.B {
    font-size: 0;
}
  <div class="B">
    This is text of class B.
    <div class="A">
      This is text of class A.
    </div>
  </div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading