{"id":1811,"date":"2015-10-15T13:12:29","date_gmt":"2015-10-15T13:12:29","guid":{"rendered":"http:\/\/cssreset.com\/?p=1811"},"modified":"2015-10-15T13:12:29","modified_gmt":"2015-10-15T13:12:29","slug":"understanding-css-content-property","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/understanding-css-content-property\/","title":{"rendered":"Understanding CSS Content Property"},"content":{"rendered":"<p>The CSS content property allows you to add content or space to a page without having to touch the HTML. CSS content is used with the pseudo selectors <strong>:before<\/strong> or <strong>:after<\/strong>, and won&#8217;t work without them. As long as you remember your pseudo selectors, adding text, images, or even space to a page using CSS content is easy and requires very little code.<\/p>\n<p>The basic syntax is simple. For example, if you wanted an exclamation point to appear after every &lt;p&gt; tag, you would use the <strong>p<\/strong> selector in conjunction with the pseudo selector<strong> :after<\/strong>, and the content (in this case, it would be an exclamation point) would be a parameter of the content property. Here&#8217;s what that would look like:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignleft size-full wp-image-1813\" alt=\"content1\" src=\"https:\/\/cssdeck.com\/blog\/\/wp-content\/uploads\/content1.png\" width=\"144\" height=\"66\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Once you&#8217;ve inserted your content, you can use the pseudo selector to style it just like you&#8217;d style any other HTML element.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignleft size-full wp-image-1817\" alt=\"content3\" src=\"https:\/\/cssdeck.com\/blog\/\/wp-content\/uploads\/content3.png\" width=\"160\" height=\"103\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>You can also use the content property to add images or videos by using the property with a <strong>url\u00a0<\/strong>parameter, which would look like this:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignleft size-full wp-image-1815\" alt=\"content2\" src=\"https:\/\/cssdeck.com\/blog\/\/wp-content\/uploads\/content2.png\" width=\"262\" height=\"58\" srcset=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/content2.png 262w, https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/content2-180x39.png 180w\" sizes=\"(max-width: 262px) 100vw, 262px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Despite the fact that it&#8217;s fairly easy to use, the content property isn&#8217;t without its quirks. The quirk that seems to trip people up most often is having to set a <strong>position: \u00a0absolute<\/strong> to the pseudo selector in order to move the content around at all by giving it margins or padding. Giving a pseudo selector absolute positioning in order to move the content looks like this:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignleft size-full wp-image-1819\" alt=\"content4\" src=\"https:\/\/cssdeck.com\/blog\/\/wp-content\/uploads\/content4.png\" width=\"161\" height=\"126\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>The more comfortable you get with using the CSS content property, the easier it is to manipulate and the more versatile it becomes. Using the content property almost feels like cheating, and in a way it sort of is. It may not ever be the <em>right<\/em> method to insert content into a page, but in certain cases it certainly seems to be the simplest, and ultimately it&#8217;s a really useful tool that any developer should have in their CSS arsenal.<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>The CSS content property allows you to add content or space to a page without having to touch the HTML. CSS content is used with the pseudo selectors :before or :after, and won&#8217;t work without them. As long as you [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/understanding-css-content-property\/\" title=\"Click to read 'Understanding CSS Content Property'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[61,6,7,1],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/1811"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=1811"}],"version-history":[{"count":5,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/1811\/revisions"}],"predecessor-version":[{"id":1821,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/1811\/revisions\/1821"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=1811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=1811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=1811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}