Extending a border-bottom or underline to create a unique text highlight

I'm struggling to extend the border-bottom of this element to match the mockup. It currently only goes under the text part.

How can I make it so that it extends to cover the entire box or underline half of the nav bar?

This is what it should look like: (https://i.sstatic.net/fLeaH.png)

Here's the HTML:

<nav class="nav">
            <ul class="nav__list">
                <li class="nav__item nav__logo"><img src="./assets/logo/Logo-bandsite.svg"></li>
                <li class="nav__item nav__links">
                        <a class="nav__link nav__link--bio" href="./index.html">Biography</a>
                        <a class="nav__link nav__link--shows" href="">Shows</a>
                </li>
            </ul>
        </nav>

And here's the SCSS:

.nav {
            &__list {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 5rem;
            padding-top: 1.3rem;
        }

            &__logo {
                padding-bottom: 1.2rem;
            }

            &__links {
                width: 100%;
                display: flex;
                justify-content: space-around;
            }

            &__link--bio {
                font-weight: $bold;
                box-sizing: border-box;
                padding-bottom: 1rem;
                border-bottom: 3px solid $primary-white;
                border-width: 100%;
                display: block;
            }
}

Currently, this is the result I'm getting: (https://i.sstatic.net/bf1vQ.png)

I also attempted putting the <a> in a div and applying the border there, but it yielded the same outcome. Thank you in advance.

Answer №1

Insert this CSS rule:

.nav__links > * {
  width: 50%;
  text-align: center;
}

By applying this rule, the links will expand to 50% of their parent element's width and adjust the bottom border accordingly. Without it, the links would only be as wide as their text content, with additional space created by the justify-content: space-around; property but not inherent to the link elements themselves.

body {
  background: #555;
}

.nav__list {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 5rem;
  padding-top: 1.3rem;
}

.nav__logo {
  padding-bottom: 1.2rem;
}

.nav__links {
  width: 100%;
  display: flex;
  justify-content: space-around;
}

.nav__links>* {
  width: 50%;
  text-align: center;
}

.nav__link--bio {
  font-weight: bold;
  box-sizing: border-box;
  padding-bottom: 1rem;
  border-bottom: 3px solid white;
  border-width: 100%;
  display: block;
}
<nav class="nav">
  <ul class="nav__list">
    <li class="nav__item nav__logo"><img src="./assets/logo/Logo-bandsite.svg"></li>
    <li class="nav__item nav__links">
      <a class="nav__link nav__link--bio" href="./index.html">Biography</a>
      <a class="nav__link nav__link--shows" href="">Shows</a>
    </li>
  </ul>
</nav>

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

Dynamically resizing a property in the DOM with Angular

Could someone help me with an issue I'm having regarding resizing items on the screen in Angular when the browser window size changes? Here is my code snippet: // TS File height: number = 2.5; objHeight:number; screenHeight:number = window.innerHeig ...

Next.js production mode prevents CSS from loading properly

Issue Upon building and launching a production build of our application, the CSS fails to load. Inspecting the devtools reveals a multitude of errors and warnings: https://i.sstatic.net/R07q3.png Possible Causes The problems do not occur when running th ...

What is the best method for adding multiple favicons to Nextjs 13 using the generateMetaData() function located in the app

Currently, I am working on a project called next@13 which resides in the app directory. Most of the information available online pertains to NextJS versions that are older than 13. I have set up metadata generation in my file named layout.tsx. The favicon ...

Issue with different domains causes GET requests to be changed to OPTIONS requests

In my recent request and response interaction, I encountered an issue with the Access Allow Control Origin being set to *. Remote Address:xx.xxx.xxx.xxx:xx Request URL:http://api-test.example.com/api/v1/sample Request Method:OPTIONS Status Code:405 Method ...

Tips for preserving checkbox state?

I am currently working on a web application project for a clinic and laboratory, specifically focusing on sending tests. I have implemented the code below to select the test category first, followed by the test name related to that category. However, when ...

Switch up the background image when hovering over it

Could the proportions of the image be contributing to the issue at hand? #menu { background: black; width: 100%; height: 45px; } #menu ul { text-decoration: none; list-style-type: none; } #menu li { text-decoration: none; display: inline; font-size: ...

I noticed that the single quote (') has been converted to ' How can I correct this issue?

How can I handle the conversion of " ' " to ' in a Dictionary when sent to Django Template? I attempted using the replace function without success. Dictionary_passed = {"-" : "100", "GERMANY" : "1500"} The HTML template output shows: {&#39; ...

Struggling to interact with a field within an HTML/CSS LESS document

I have encountered an issue with my website where I am unable to click on certain fields or buttons within the Login fieldset. Strangely, I can only interact with the fields and buttons located within the Register fieldset. The CSS for my website is writt ...

Elevate the vertical dimension of a <ul> using a TAB

I'm currently working on developing a visually appealing page that will feature 4 tabs. I used https://codepen.io/axelaredz/pen/ipome for the tab navigation, which I think looks fantastic. However, I am facing an issue where I need each section under ...

Utilizing Material-UI for CSS styling in a live environment

My application has a 'dashboard' feature that utilizes material-ui. Within this dashboard, other apps are called and rendered. While this setup functioned smoothly during development, I encountered issues once switching to a production build. The ...

I'm having trouble getting my text values to line up next to my slider bar

I've been troubleshooting this issue for a couple of hours now. (My CSS skills are not the best) Currently, I have two jQuery sliders with values. My goal is to position "Rooms: 0" and "Bathrooms: 0" right next to their respective slider bars. . ...

Retrieve the auto-filled input data and store it in a hidden input using Vue.js

I recently started using for autocompletion in my Vue project. While it performs well, I am facing an issue where the value inside the 'input' field is not getting posted to the form when submitted. As a workaround, I have resorted to creating ...

How to centrally align tabs in Material-UI AppBar using ReactJS

I'm developing a React Application using Material-UI and facing difficulty in centering the 3 tabs within the blue AppBar. Currently, they are aligned to the left like this: (unable to embed images at the moment, apologies) This is the code snippet ...

Interact with multiple divs using Jquery .click

I have created a single page with multiple anchors, each containing unique content that pops up when clicked. The functionality is working well, but I am facing an issue where clicking on a different anchor repeats the same content as the first anchor. I w ...

Retrieve the selected value from a dropdown menu in HTML and PHP on the same

Seeking guidance on HTML select form. I have 5 select forms arranged as illustrated in the image below. https://i.sstatic.net/uNHHB.png The chosen value from the first select form determines the options displayed in the subsequent select form. These opt ...

What is the best method for calculating income and expenses within a JavaScript expense tracker?

I'm facing an issue where I can't add the value of a checked radio button to an object in a different function. Even though there are no errors, nothing gets added. My project involves creating an expense tracker, and adding either income or exp ...

Scrolling down to a specific list item and pausing when the li element is in the middle of the

Hello everyone, I'm currently working on creating a carousel. I have used list items with images inside and am using scroll to navigate to a specific list item. However, when clicking on a thumbnail (let's say the 2nd one), it scrolls to the imag ...

Is it possible to convert a webpage into an image file using PHP?

Is there a way to save a webpage as an image file or capture a snapshot of a webpage using PHP, similar to how the Firefox extension Fireshot does? ...

Truncate text on a dynamic button positioned above a fluid container

Looking for a CSS-only solution to manage text within an image-defined box? The challenge is to place a button in the center if the text is shorter than the image, or cut it with ellipsis if longer. Also, the text should not exceed the box width. Any ideas ...

Ways to update the background hue for negative variables?

If the value of totalNetworkScore is negative, I want to update the background color of a styled div to red. ...