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 :
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
Opera and Custom Cursor in CSS
What Is That Thing Between CSS "Selectors" Called
Rounding Numbers in SASS and Adjusting the Amount of Decimals
How to Revert Back to Normal After Display:None for Table Row
CSS Menu - Keep Parent Hovered While Focus on Submenu
How to Suppress Certain CSS Errors in Aptana Studio 3
Create CSS for Internet Explorer Only
Differencebetween the Selectors ".Class.Class" and ".Class .Class"
Make an Item Stick to the Bottom Using Flex in React-Native
Are There Any CSS Standards That I Should Follow While Writing My First Stylesheet
How to Add a Company Logo to Shinydashboard Header (Not Mainpanel or Mainheader)
Input[Type=Number] Placeholder Color in Ff29+
Inherited Text-Decoration Style
How to Use Transform-Origin in Conjunction with Svgs
CSS Overlapping Elements & Opacity Issue