What's new

Welcome to the forum 👋, Visitor

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

[TIPS] ::before and ::after content

Koyyiko

New member
Joined
Aug 22, 2022
Messages
17
Reaction score
0
HTML Coins
0
Many of the elements on your website will be redundant. For example, you might have a standard font size for the H2 element throughout the page or even the website. To avoid repetitive code, we utilize CSS and apply the style in a single place. However, developers are hardly pleased with a single element. They come up with creative methods to make each element stand out. This results in unique designs, as shown below.

H2 element throughout


Another example of such a design is shown below.

Another example of such a design is shown below.


Hard coding these styling elements (read and stylish quotes) repeatedly on each element is not a good practice. Even if someone wants to change the color of the quotes, it is tough to make the changes on hundreds of quotes you already designed.

Putting something before or after any element in HTML is taken care of by :: before and ::after pseudo-elements of CSS.

Let’s say I want to put the location in front of all the news headlines and a “read more” text after the content. I can proceed in the following direction:

Code:
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Absolute Numbers</title>
  </head>
  <style>
    #texas::before {
      content: "texas";
      font-size: 12px;
      color: orange;
    }
 
    #washington::before {
      content: "washington";
      font-size: 12px;
      color: orange;
    }
 
    .news::after {
      content : "Read More...";
      color: red;
    }
  </style>
  <body>
 
    <h2 id="texas">XYZ to hold a new event in texas </h2>
    <p class="news"> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
 
    <h2 id="washington">XYZ to hold a new event in texas </h2>
    <p class="news"> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
 
 
  </body>
</html>


The output, when rendered on the LambdaTest platform on a VM, looks as follows:

The output


Notice how the location appears “before” the main heading and a “Read More…” sign “after” it. As I have done above, you can also style these components with the font size and color properties.
 

Theme customization system

You can customize some areas of the forum theme from this menu.

  • Wide/Narrow view

    You can control a structure that you can use to use your theme wide or narrow.

    Grid view forum list

    You can control the layout of the forum list in a grid or ordinary listing style structure.

    Picture grid mode

    You can control the structure where you can open/close images in the grid forum list.

    Close sidebar

    You can get rid of the crowded view in the forum by closing the sidebar.

    Fixed sidebar

    You can make it more useful and easier to access by pinning the sidebar.

    Close radius

    You can use the radius at the corners of the blocks according to your taste by closing/opening it.

  • Choose the color combination that reflects your taste
    Background images
    Color gradient backgrounds
Back