Utilizing nested LESS statements for styling the :before and :after pseudo-classes

Here is a snippet of LESS code attempting to add a colored background to the :after pseudo-class:

.hexagon:after {
  content: "";
  position: absolute;
  bottom: -50px;
  left: 0;
  width: 0;
  height: 0;
  border-left: 100px solid transparent;
  border-right: 100px solid transparent;
  &.red-light {
    border-top: 50px solid @brand-red-light;
  }
  &.red {
    border-top: 50px solid @brand-red;
  }
  &.red-dark {
    border-top: 50px solid @brand-red-dark;
  }
  &.freen-light {
    border-top: 50px solid @brand-green-light;
  }
  &.green {
    border-top: 50px solid @brand-green;
  }
  &.green-dark {
    border-top: 50px solid @brand-green-dark;
  }
}

The issue lies within the nested LESS statement such as `border-top: 50px solid @brand-red-light`, which does not appear on the screen upon rendering. I have attempted replacing the "&" symbol with ">" but it did not solve the problem. My goal is to create a CSS hexagon.

Answer №1

Your current LESS code is generating the following CSS selectors:

.square:before
.square:before.blue-light
.square:before.blue
.square:before.blue-dark
.square:before.green-light
.square:before.green
.square:before.green-dark

It appears that you intended to create this instead:

.square:before
.square.blue-light:before
.square.blue:before
.square.blue-dark:before
.square.green-light:before
.square.green:before
.square.green-dark:before

To achieve this, adjust your LESS code as follows:

.square {
    &:before {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 100px;
        height: 100px;
        background: #ccc;
    }    
    &.blue-light:before {
        background-color: lightblue;
    }
    &.blue:before {
        background-color: blue;
    }
    &.blue-dark:before {
        background-color: darkblue;
    }
    &.green-light:before {
        background-color: lightgreen;
    }
    &.green:before {
        background-color: green;
    }
    &.green-dark:before {
        background-color: darkgreen;
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using clearfix on every div element is essential to avoid container collapsing

Would it be beneficial to include clearfix in every div element to avoid container collapse issues? Or is it more practical to apply it only to specific classes, like so? <div class="container"> Additional div elements... </div> .containe ...

Utilizing CSS nth-child on dynamically generated HTML in Angular

Ensuring that the columns are floated to the left without large gaps between rows is my current challenge. Here's the HTML structure I'm working with: <div class="row hide-for-small"> <div ng-repeat="module in modules"> ...

Enforcing Height Constraints on Images in HTML/CSS

I'm currently working on a design project and encountering a minor issue. Feel free to take a look at the final design example linked here: In the menu on both sides, you'll notice a small border that runs from top to bottom, matching the heigh ...

The integration of HTML and CSS using ng-bind-html appears to be malfunctioning

<ion-item ng-bind-html="renderHtml(word[key])"> </ion-item> When referring to word[key], it represents: <ul> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul> This is the CSS being u ...

On the PostAd.js page, I am looking to remove the location bar, search bar, and sell button - only keeping the

I am looking to customize the PostAd.js page by displaying only the logo and hiding the location bar, search bar, and sell button. I have included my code below for reference. As a newcomer learning React.js, I am striving to showcase just the logo on the ...

Overlapping dynamic content causing CSS nested scrollbars to clash at full width of 100%

Displayed below is a layout with two nested divs, both featuring automatic vertical scrolling. Is there a CSS technique available to show the inner scrollbar while maintaining the inner div at 100% width? https://i.stack.imgur.com/HSKHH.png div { ba ...

Would adjusting the font sizes of headings be crossing into grey or black hat SEO territory?

Here's the scenario: In this case, the page title is designated as H3, the article title is labeled as H2, and a certain keyword or important sentence is identified as H1 within the content. These elements have custom CSS classes applied to them, cau ...

Adjusting image size according to browser dimensions

I've been struggling to resize a background image on my Square space website dynamically based on the user's browser window size. If the window width drops below a certain point, I want the image to adjust accordingly while maintaining its aspect ...

Center the navigation bar within a division

Kindly take a look at the following link: http://83.212.101.132/betdk/home/two As the user scrolls, the navbar moves to the top thanks to the affix plugin. However, it occupies the entire row with "Home" aligned to the left. What steps should I take ...

How about having a surprise image pop up when you click a button?

I've been working on coding a button that can change the background of my webpage to display a random image. Initially, my code seemed functional, but it was only displaying the last image listed in my series of if/else statements. I suspect that usin ...

Guide on breaking a th tag as a line in a table using CSS

I'm attempting to achieve jQuery datatable-style responsiveness in an Angular table child component. I managed to separate the td and th separately using absolute and relative positions but encountered an issue where the th tag is not breaking at the ...

Tips for structuring a news thread with a staggered approach

On my Drupal 8 website, I have set up a newsfeed. How can I display the news items in staggered rows? I would like the first item to align on the left and the second item to be on the right, repeating this pattern for all subsequent items. Currently, I am ...

Is there a way to automatically adjust the position of a tooltip div based on its location relative to the screen in AngularJS?

I've implemented AngularJs to create a grid with repeated li elements, each displaying a description box when hovered over. However, I am facing an issue where the description box goes off-screen when hovering over items on the right side of the grid. ...

Region Covered by Mouse Over Does Not Extend Across Whole Div

On my website, there is an arrow located on the middle right side that, when hovered over with the mouse, reveals a sidebar. Clicking on each icon in the sidebar further extends it to reveal more content. However, the issue I am facing is that the sidebar ...

The fine balance between a horizontal <img> and a <div> element

Can't seem to get rid of the thin white line between a black image and a div with a black background on a page where the body background is set to white. I've tried setting border: 0 !important among other things, but it just won't go away. ...

Angular 6 and Bootstrap 4 Collaborate for a Dynamic Multi-Level NavBar

(UPDATE: Issue Resolved - I discovered that I needed to include the JavaScript within $(document).ready(function()), which was previously missing. The example below worked perfectly for me.) I am attempting to implement a Multi-Level Navbar with Angular 6 ...

Tips for honing in on a particular card within a list of cards using React

I am currently working with React 17.0.2 and Material UI, and I have a specific requirement to focus on a particular card from a list of cards by clicking on it. (Please refer to the attached picture for clarification). I hope this explanation helps you un ...

Tips for incorporating three background images within one CSS file

Here's a snippet of my navigation code: <? if($page == ""){ ?> <li> <a href="<? echo $site;?>" id="on" style="background-image:url(images/logonav_onright.png) right no-repeat;">Home</a> </li> ...

Utilizing the Grid-A-Licious plugin multiple times within a single webpage

Currently, I am utilizing the Grid-A-Licious plugin for my project. It functions perfectly when used on a single page with one call to the plugin. However, due to my design requirements, I need to implement it within 3 tabs on the same page. Unfortunately, ...

Does text disappear when hovered over in CSS?

Having some trouble getting a text to display on hover over the parent container while adjusting the opacity. Despite trying multiple methods, it just won't show up no matter what I do! Here is my current code: .project{ position: relative; ...