The ::before and ::after pseudo-elements in CSS allow you to insert content before or after the content of an element, respectively. These pseudo-elements are often used to add decorative or structural elements to an element without needing to modify the actual HTML content.
::before Pseudo-element:
::after Pseudo-element:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Before After Pseudo-elements</title> <style> p::before { content: url("images/face.png"); } p::after { content: url("images/dog.png"); } span::before { content: "$"; } </style> </head> <body> <h1>Before & after Pseudo-elements</h1> <p>I Love Dogs</p> <h5>Total Amount <span>500</span></h5> </body> </html>
The CSS code you provided uses the ::before and ::after pseudo-elements to insert content before and after specified elements.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Before After Pseudo-elements</title> <style> @import url("https://fonts.googleapis.com/css?family=Roboto+Condensed:400,700"); *, *:before, *:after { box-sizing: border-box; } body { font-family: "Roboto Condensed"; text-align: center; padding: 30px 0; } h1 { font-size: 60px; line-height: 1; color: rgb(50, 50, 50); } h1.title { display: inline-block; position: relative; } h1.title::before, h1.title::after { content: ""; display: block; width: 60px; height: 60px; position: absolute; top: 0; border-top: solid 30px transparent; border-bottom: solid 30px transparent; } h1.title::before { left: -70px; border-right: solid 60px rgb(255, 150, 50); } h1.title::after { right: -70px; border-left: solid 60px rgb(255, 150, 50); } </style> </head> <body> <h1 class="title">Before & after Pseudo-elements</h1> </body> </html>
CSS box-sizing property for all elements, including pseudo-elements (*:before and *:after), to border-box. This ensures that when you set the width or height of an element, it includes padding and borders within those dimensions, simplifying layout calculations.
Header Title Decoration (Before and After):
After Pseudo-element (Right Side):
Both ::before and ::after pseudo-elements are versatile and can be used to enhance the appearance of elements by adding icons, text, or other decorative elements without modifying the actual HTML content. They are also commonly used for creating custom bullets for lists or adding quotes to blockquotes, among other creative uses.
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions