Home > Web Front-end > CSS Tutorial > How Can I Hide Text Nodes in a Div Using CSS While Keeping Other Elements Visible?

How Can I Hide Text Nodes in a Div Using CSS While Keeping Other Elements Visible?

Linda Hamilton
Release: 2024-12-07 21:27:13
Original
1033 people have browsed it

How Can I Hide Text Nodes in a Div Using CSS While Keeping Other Elements Visible?

Hiding Element Text Nodes with CSS

You have a div element containing an anchor tag and a text node. You want to hide only the text node without affecting the visibility of the div or the anchor tag. The visibility attribute can be used to achieve this.

CSS Solution

The following CSS code accomplishes your goal:

#closelink {
  visibility: collapse;
}

#closelink a {
  visibility: visible;
}
Copy after login

In this code:

  • #closelink hides the div and its entire contents, including the text node.
  • #closelink a overrides the visibility attribute for the anchor tag within the div, making it visible again.

HTML

Your HTML remains unchanged:

<div>
Copy after login

This CSS solution effectively hides the text node "Click to close" while leaving the div and anchor tag visible.

The above is the detailed content of How Can I Hide Text Nodes in a Div Using CSS While Keeping Other Elements Visible?. 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