Home > Web Front-end > JS Tutorial > How Can I Hide Untagged Text in HTML Using CSS?

How Can I Hide Untagged Text in HTML Using CSS?

Susan Sarandon
Release: 2024-12-14 02:51:13
Original
413 people have browsed it

How Can I Hide Untagged Text in HTML Using CSS?

Hiding Untagged Text in HTML

In HTML, it's possible to hide text fragments that aren't enclosed by any HTML tags. This text, often referred to as "plain text," can present a challenge to hide using conventional methods.

JavaScipt or CSS?

As the user mentioned, wrapping the text in a div or other tags is impractical. Therefore, alternative methods such as JavaScript or CSS need to be explored.

CSS Hacking

One effective CSS hack for hiding plain text involves manipulating the font size:

.entry {
  font-size: 0;
}
.entry * {
  font-size: initial;
}
Copy after login

By setting the font size of the container div to zero, all elements within that container will also have a font size of zero, effectively hiding them. However, to restore the visibility of the tagged elements, the second CSS rule sets the font size back to its initial value, thus ensuring that only the untagged text remains hidden.

Example:

<div class="entry">
  <p class="page-header"><strong>Enter</strong></p>
  <p>something here</p>
  Enter (this will be hidden !!)
  <div class="subhead">another text here</div>
</div>
Copy after login

By applying the CSS hack to this HTML, the "Enter" text after the "p" tag will be effectively hidden, while the other text within the container will be unaffected.

The above is the detailed content of How Can I Hide Untagged Text in HTML Using 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