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 🙂


  • 6 Votes
    15 Posts
    707 Views

    No no, I said that in the sense that he told me it was simple ^^
    I was able to see that this was not the case by targeting the elements he had advised me.

  • 9 Votes
    32 Posts
    3k Views

    @DownPW said in Bottom footer navbar button extend:

    Oh my god, it’s beautiful mark

    I liked this design so much, I’ve implemented it here. I intend to do a lot more with the footer in due course, so hiding it makes a lot of sense. Thanks @DownPW for the idea and initial concept ♥

  • 1 Votes
    1 Posts
    178 Views
    No one has replied
  • 3 Votes
    2 Posts
    555 Views

    @pwsincd welcome to sudonix, and thanks for the comments. What your looking for is here

    https://sudonix.com/topic/195/nodebb-welcome-message/3?_=1648295651358

  • 5 Votes
    4 Posts
    356 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.

  • 0 Votes
    7 Posts
    728 Views

    @downpw ooops. Forgot that. Thanks for adding.

  • Avatar on Topic Header

    Solved Customisation
    9
    0 Votes
    9 Posts
    527 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 🙂

  • NodeBB Design help

    Solved Customisation
    8
    2 Votes
    8 Posts
    829 Views

    @riekmedia I’ve applied some new CSS to your site. Can you reload the page and try again ?

    For the record, this is what I added

    #footer { background: #2d343e; border-top: 4px solid #2d343e; font-size: 0.9em; margin-top: 70px; padding: 80px 0 0; position: relative; clear: both; bottom: 0; left: 0; right: 0; z-index: 1000; margin-left: -15px; margin-right: -338px; }

    The /categories page seems a bit messed up, so looking at that currently

    EDIT - issued some override CSS in the CATEGORIES widget

    <!--- CSS fix for overspill on /categories page - DO NOT DELETE --> <style> #footer { margin-right: -45px; } </style>

    That should resolve the /categories issue.