Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I replace the text in an <h1> from a CSS file without using a <span> tag?

Here's what happening:

For my computer science class we're working on a project where we can only modify the CSS. I think it'd be super cool to change the content of the elements when you plug in my CSS file. Since I can't add a tag, I dont know how else can I do this. Here's what I have:

<div>

  <h1>Is the makerspace door open?</h1>

</div>

<div>


  <p id="switch_txt">Checking...</p>

</div>


</body>


I've tried using ::before and ::after pseudo selectors but these selectors can't place elements in the content property. Any advice would be much appreciated.

like image 311
Will Pearson Avatar asked Nov 12 '14 14:11

Will Pearson


People also ask

How do you overwrite text in CSS?

The text “Old Text” needs to be hidden first and a new text has to be positioned exactly where the old text was. To do so, we change the visibility of this text using CSS to hidden first. Then we add a new text at the exact same position, using the pseudo elements and corresponding explicit positioning.

How do I remove text from an element in CSS?

By using text-indent: -999px; or a similar method, the text is still there — just not visually there. Use display:none , and the text is gone.

How do I put text on the same line in CSS?

The best way to use is white-space: nowrap; This will align the text to one line.


1 Answers

The pseudo element is a good approach to visually replace text or insert an image.

text-indent can be useful added to a float context for the pseudo element to hide any dom inline or inline-block content(such as text or image).

Example:

HTML test

<h1>show me something else</h1>

CSS test

h1 {
  text-indent:-9999px;
}
h1:before {
  text-indent:0;
  content:'Here is something else !';
  float:left;
} 
like image 88
G-Cyrillus Avatar answered Sep 18 '22 15:09

G-Cyrillus