Skip to content

CSS border gradients

Blog
  • Some of you might have noticed a feature on this forum that further extends the .highlight class in NodeBB from the default of a different colour border such as border-left: 1px solid blue; to something that looks like the below

    57b892b1-296a-4e42-8f05-e0a08efa2068-image.png

    And, as Sudonix has a number of “swatches” or “themes”, these are also colour coordinated to match. For example

    d0368af2-425b-48bf-ad62-f9df5a5450c8-image.png

    9524e9d0-91d7-41e3-9153-2b27aff26a74-image.png

    There are more - try changing the swatch, and then view the last post in each thread, and you’ll see where and how this is being applied.

    I want this effect!!

    Sure you do 🙂 Here’s how to get it. We are going to be extending the .highlight class of NodeBB and will be leveraging the :before pseudonym class as below.

    .highlight:before {
        content: "";
        position: absolute;
        inset: 0;
        border-radius: 0.375rem;
        padding: 3px;
        background: var(--bs-progress-bar-bg);
        -webkit-mask: linear-gradient(var(--bs-body-bg) 0 0) content-box, linear-gradient(var(--bs-body-bg) 0 0);
        -webkit-mask-composite: xor;
        mask-composite: exclude;
        pointer-events: none;
    }
    

    What does this do?

    In summary, this CSS snippet creates a highlighted effect around an element by using an absolutely positioned pseudo-element with a special mask to create an outline or glowing effect. The actual visual appearance would depend on the colours defined by the --bs-progress-bar-bg (note that this is not a NodeBB variable, but one I’ve defined which this forum uses - you’ll need to factor this into your colour scheme) and --bs-body-bg variables, but the technique is quite clever and allows for flexible styling.

    What does your --bs-progress-bar-bg class look like?

    Here’s an example

    --bs-progress-bar-bg: linear-gradient(45deg, #5E81AC, #88C0D0, #8FBCBB, #A3BE8C, #D08770, #BF616A);
    

    Let’s break down the properties to understand how all of this works…

    • content: ""; - This rule sets an empty content for the pseudo-element. This is necessary for the pseudo-element to be rendered.
    • position: absolute; - This rule positions the pseudo-element absolutely within its containing element.
    • inset: 0; - This shorthand rule sets the top, right, bottom, and left properties to 0, effectively making the pseudo-element cover the entire space of its containing element.
    • border-radius: 0.375rem; - This rule sets the border radius of the pseudo-element to create rounded corners. The value “0.375rem” is equivalent to 6 pixels.
    • padding: 3px; - This rule adds padding of 3 pixels to the pseudo-element.
    • background: var(--bs-progress-bar-bg); - This rule sets the background color of the pseudo-element to the value of the CSS custom property “–bs-progress-bar-bg”. Custom properties are a way to define reusable values in CSS.
    • -webkit-mask: linear-gradient(var(--bs-body-bg) 0 0) content-box, linear-gradient(var(--bs-body-bg) 0 0); - This rule applies two linear gradients as masks to the pseudo-element. These gradients essentially create transparent regions in the pseudo-element, revealing the background color underneath.
    • -webkit-mask-composite: xor; - This rule sets the compositing mode for the masks. The “xor” mode combines the two masks using the XOR (exclusive OR) operation.
    • mask-composite: exclude; - This rule sets the compositing mode for the mask to “exclude”. This means that areas where the mask and the content overlap will be excluded, effectively creating a cutout effect.
    • pointer-events: none; - This rule ensures that the pseudo-element does not respond to pointer events, allowing clicks and other interactions to pass through to the underlying elements.

    Using this approach, it’s possible to extend the capabilities of CSS much further than you probably imagined. Obviously, this isn’t something you’d want to overuse, but it can certainly provide a much needed edge for when you are trying to draw attention to a specific object or element.

    Enjoy.

  • i do it but not working last message highlight.

  • @cagatay said in CSS border gradients:

    i do it but not working last message highlight.

    Can you provide the CSS you used?

  • .highlight:before {
        content: "";
        position: absolute;
        inset: 0;
        border-radius: 0.375rem;
        padding: 3px;
        background: var(--bs-progress-bar-bg);
        -webkit-mask: linear-gradient(var(--bs-body-bg) 0 0) content-box, linear-gradient(var(--bs-body-bg) 0 0);
        -webkit-mask-composite: xor;
        mask-composite: exclude;
        pointer-events: none;
    }
    
    

    this one

  • @cagatay Yes, that’s because you do not have a variable called var(--bs-progress-bar-bg) in your swatch.

    See below for example

    --bs-progress-bar-bg: linear-gradient(45deg, #5E81AC, #88C0D0, #8FBCBB, #A3BE8C, #D08770, #BF616A);
    
  • where i should add this code? in css also?
    added light.css 🙂

  • @cagatay Yes, that works as intended, although you have an extra border being added. To remove that, in your custom CSS, locate the below block

    .page-topic .topic .posts.timeline .timeline-event.highlight, .page-topic .topic .posts.timeline > [component="post/placeholder"].highlight, .page-topic .topic .posts.timeline > [component=post].highlight
    

    and remove it.

  • i deleted nothing changed.

  • @cagatay It has changed as the extra border is no longer present

    23854655-2b10-48cb-a1af-8b4a2ec64833-image.png

  • ah f5 need 🙂


  • Rotating Star Effect

    Solved Let's Build It
    17
    12 Votes
    17 Posts
    473 Views

    @phenomlab thanks a lot for these, both of the below are awesome! ♥

    https://codepen.io/bennettfeely/pen/vYLmYJz

    https://codepen.io/C-L-the-selector/pen/MWZbWBo

  • 1 Votes
    2 Posts
    275 Views

    @Sala This should look better

    .sidenav .navbar-brand { padding-top: 0.5rem; padding-bottom: 0.5rem; }

    e5cec20e-be36-4ee8-9129-fd11ad4656ac-image.png

    You can increase the top and bottom padding by increasing the values above.

  • chat list navbar

    Solved Customisation
    30
    3 Votes
    30 Posts
    2k Views

    No no it’s ok @phenomlab
    I just comment the 2 lines mentionned aboves 😉

  • 5 Votes
    3 Posts
    383 Views

    @phenomlab

    I love it too

    @phenomlab said in Blinking text Effect:

    Has that “broken neon light” look that you see in films.

    It’s exactly that, kind of old neon signs of bar or pubs a bit cyberpunk too 😉

  • Fontawesome 5

    Unsolved Customisation
    14
    1 Votes
    14 Posts
    687 Views

    @pwsincd hi. Just following up on this thread (I know it’s old) but was curious to understand if it’s still an issue or not ?

  • 5 Votes
    4 Posts
    361 Views

    @crazycells love this article. You’re absolutely right about people using colors that are either completely at odds with the scheme on their own site, or have no real concept of theming itself or swatches.

    There’s nothing worse than garish colour on a web site. Nothing more than back button fodder.

  • Avatar on Topic Header

    Solved Customisation
    9
    0 Votes
    9 Posts
    528 Views

    @jac said in Avatar on Topic Header:

    @downpw said in Avatar on Topic Header:

    Great Plugin 🙂

    I make it a bit cleaner via this CSS code:

    /*------------------------------------------------------------------*/ /*---------------- nodebb-plugin-browsing-users -----------------*/ /*------------------------------------------------------------------*/ /*Space between the avatar and the RSS icon */ .topic [component="topic/browsing-users"] { margin-bottom: -5px; padding-left: 10px; } /*Space between avatars*/ .pull-left { float: left!important; padding-right: 5px; }

    Do you have a screenshot of how this looks with the CSS change?

    Just added this change, thanks @DownPW 🙂

  • Bug Navbar CSS

    Solved Customisation
    3
    1 Votes
    3 Posts
    303 Views

    Not better way.

    Thanks.