1

I'm wondering it if is possible to display text on a HTML page from a CSS file.

For example for a web host instead of having 100MB display on a plan upon 4 pages and not having to edit each one but the CSS itself.

For example:

CSS
100MB

and than in text

Our plan has {text from css displays here}

Thanks

4 Answers 4

6

You can use the :after pseudoselector. Suppose your "our plan has" part has an ID planid, and your HTML looks like this:

<div id = "planid">Our plan has</div>

Then you can do this in the CSS:

#planid:after {
    content: ' 100MB'; /*what the element will contain*/
    display: inline; /*it's inline*/
    /*more styling*/
}

The :after selector creates a pseudo-element after the selected element. To create one before it, use the :before selector.

Little demo: little link.

Sign up to request clarification or add additional context in comments.

Comments

3

Used to after before properties

yes do this as like this

HTML

<div>Hello</div>

Css

    div:after{
content:'100mb';
}

live demo

more info

2 Comments

What HTML tag do i use? Do i use <div id="ram"> i tried using that and it doesn't seem to display the content
you can chose any id or class as like this <div class="ram">Hello</div> and css ram:after used check to my updated answer
2

you can do this using pseudo elements like :after - http://jsfiddle.net/spacebeers/LQy7T/

.your_class:after {
    content: "YOUR TEXT";
    color: red;
    background: blue;
    display: inline;
}​

Comments

2

CSS is not designed to do that kind of work, it's for organizing styles and not for managing contents.
What you need is a variable to store your value and then show it many times. So you need PHP, JS, Ruby, Java or your favourite language.

4 Comments

The statement is mostly correct, but not an answer to the question; it should have been posted as a comment.
I would of use PHP however PHP is a little on the slow side and the idea is having a site fast as possible. Also the above answer works with CSS.
@JukkaK.Korpela Yes, it's not an answer to a question, but a solution to a problem. IMO it has much more educational value. (And don't let people use a microscope as a hammer.)
I think advising against bad practices and pointing in the good direction is the best we can do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.