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 🙂


  • 3 Votes
    7 Posts
    332 Views

    @phenomlab yes it’s a different theme. The other one was not offering much on editable sidebar. It was like flarum hahah

  • Fixing YouTube videos css

    Solved WordPress
    8
    2 Votes
    8 Posts
    263 Views

    @phenomlab It looks good, but not anymore. I’ve already lost so much time. Now it’s time to move on

  • Footer bar add center text

    Solved Customisation
    41
    8 Votes
    41 Posts
    3k Views

    @phenomlab said in Footer bar add center text:

    div#console-nav-tab

    Ah ok test with bottom: 0px !important; idem

  • hover link effect

    Solved Customisation
    18
    6 Votes
    18 Posts
    608 Views

    @DownPW Looking at the underlying code, class start is being added on hover by jQuery in this function

    document.querySelectorAll(".button-gradient, .button-transparent").forEach((button) => { const style = getComputedStyle(button); const lines = document.createElement("div"); lines.classList.add("lines"); const groupTop = document.createElement("div"); const groupBottom = document.createElement("div"); const svg = createSVG( button.offsetWidth, button.offsetHeight, parseInt(style.borderRadius, 10) ); groupTop.appendChild(svg); groupTop.appendChild(svg.cloneNode(true)); groupTop.appendChild(svg.cloneNode(true)); groupTop.appendChild(svg.cloneNode(true)); groupBottom.appendChild(svg.cloneNode(true)); groupBottom.appendChild(svg.cloneNode(true)); groupBottom.appendChild(svg.cloneNode(true)); groupBottom.appendChild(svg.cloneNode(true)); lines.appendChild(groupTop); lines.appendChild(groupBottom); button.appendChild(lines); button.addEventListener("pointerenter", () => { button.classList.add("start"); }); svg.addEventListener("animationend", () => { button.classList.remove("start"); }); }); })

    The CSS for start is below

    .button-gradient.start .lines svg, .button-transparent.start .lines svg { animation: stroke 0.3s linear; }

    And this is the corresponding keyframe

    @keyframes stroke { 30%, 55% { opacity: 1; } 100% { stroke-dashoffset: 5; opacity: 0; } }

    It’s using both CSS and SVG, so might not be a simple affair to replicate without the SVG files.

  • 1 Votes
    1 Posts
    178 Views
    No one has replied
  • Fontawesome 5

    Unsolved Customisation
    14
    1 Votes
    14 Posts
    681 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
    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.

  • [NODEBB] Welcome Message

    Solved Customisation
    18
    13 Votes
    18 Posts
    2k Views

    For anyone reviewing this post, there’s an updated version here that also includes an sunrise / sun / moon icon depending on the time of day

    https://sudonix.com/topic/233/nodebb-welcome-message-with-logo-footer-change/3?_=1645445273209