Add HTML Tag Inside CSS Content Property

CSS content property: is it possible to insert HTML instead of Text?

Unfortunately, this is not possible. Per the spec:

Generated content does not alter the document tree. In particular, it is not fed back to the document language processor (e.g., for reparsing).

In other words, for string values this means the value is always treated literally. It is never interpreted as markup, regardless of the document language in use.

As an example, using the given CSS with the following HTML:

<h1 class="header">Title</h1>

... will result in the following output:

<a href="#top">Back</a>Title

Add HTML tag inside CSS Content property

This is impossible. You cannot generate markup from CSS.

It should also be unnecessary - stick your background image / icon font / whatever in the generated pseudo-element you have already.

CSS Content to add HTML tags

A similar effect can be achieved:

#br:after {
content: "";
display: block;
}

http://jsfiddle.net/2j4JD/

How to inserted HTML tag from pseudo-element content:

You can't inject HTML elements using the content property of CSS pseudo-elements; you can, however, set them to display: block and (as seems to be required in your question, though not your demonstrated/attempted code) use height and background-color to emulate an <hr />:

article::before {
content: '';
display: block;
margin: 1em 0;
height: 5px;
background-color: #f00;
}

article::before {

content: '';

display: block;

margin: 1em 0;

height: 5px;

background-color: #f00;

}
<article>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</article>

<article>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</article>

Is it possible to insert an HTML tag from pseudo-element content using CSS?

As said by @rounin you can't insert html in the generated content.

But hr is just an element with its custom CSS styling.

You can recreate the styling for your generated content

article::before {

content: "";

border: 1px inset;

box-sizing: border-box;

color: gray;

display: block;

height: 2px;

margin: 0.5em auto;

}
<article>

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Doloremque nihil odit impedit ipsam et ducimus.</article>

<article>

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Enim deleniti!

</article>

Adding HTML entities using CSS content

You have to use the escaped unicode :

Like

.breadcrumbs a:before {
content: '\0000a0';
}

More info on : http://www.evotech.net/blog/2007/04/named-html-entities-in-numeric-order/

Add css elements inside content

you won't be able to insert other things than text-element with css

BUT, what you want to do can be achieved this way :

.textblockquote:before{
color:green; /* <-- apply the styling you want */
content: "\0022"; /* <-- escaped unicode for 'quote' */
}

In the meantime, your question has already been answered (30 months ago): Using :before and :after CSS selector to insert Html

Look : Sample Image

How to use CSS 'content' property with the 'option' tag?

Unfortunately, pseudo-elements don't work for image, input, select options.

One option is to wrap select inside and div and use :before content

<body>
<div>
<select>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
</div>
</body>

CSS:

div::before{
content:"Name: "
}

https://codepen.io/nagasai/pen/PRwreg

Other option is to use javascript or jQuery to add content "Name:"



Related Topics



Leave a reply



Submit