Home >Web Front-end >CSS Tutorial >How Can I Hide Un-tagged Text in HTML Using Only CSS?

How Can I Hide Un-tagged Text in HTML Using Only CSS?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-25 06:14:16374browse

How Can I Hide Un-tagged Text in HTML Using Only CSS?

Hiding Text without HTML Tags in HTML

A user encounters a challenge where a particular section of text within an HTML document is not enclosed by any HTML tags. The goal is to hide this text without wrapping it in a div or other HTML element.

CSS Solution

The recommended approach involves a CSS hack that utilizes font-size:

.entry {
  font-size: 0;
}

.entry * {
  font-size: initial;
}

When applied to the given HTML code, this CSS effectively hides the desired text while preserving the visibility of the other elements:

<div class="entry">
  <p class="page-header">

By setting the font size of the ".entry" class to 0, all its child elements are hidden. The second rule then selectively sets the font size back to its initial value, restoring the visibility of the desired elements within the ".entry" container.

The above is the detailed content of How Can I Hide Un-tagged Text in HTML Using Only CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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