How do I adjust the ul size to be proportionate to the header?

I have a list with corresponding hyperlinks in my code, and I am trying to make these elements the same size as the header. I attempted adding auto padding and height auto but it did not produce the desired result.

Here is the HTML snippet:

<header id="header" class="header">
      <nav id="nav" class="nav">
         <div id="brand" class="brand">
            <img src="" alt="GEM Logo" />
         </div>
         <ul id="nav__menu" class="nav__menu">
            <li><a href="/company">Company</a></li>
            <li><a href="/solutions">Solutions</a></li>
            <li><a href="/team">Team</a></li>
            <li><a href="/aboutus">About Us</a></li>
            <li><a href="/support">Support</a></li>
         </ul>
      </nav>
   </header>

Furthermore, this is my Sass:

@import "_variables.scss";

.header {
   background-color: $primary-color;
   color: white;
   padding: 20px;

   & a{
      color: white;
      font-weight: bold;
   }
}

.header .nav {
   display: flex;
   justify-content: space-between;

   & .nav__menu {
      display: flex;

      & li {
        margin-right: 15px;
        text-transform:uppercase;
      }

      & li:hover {
         animation: headerLinks;
         animation-duration: 2s;
      }
   }
}

@keyframes headerLinks {
   from {
      border: none;
   }
   to {
      border: 1px solid red;
   }
}

https://i.stack.imgur.com/onzo5.png

The current output is acceptable, however, I need the li element and the a element to match the size of the header. My goal is to create an animation when the user hovers over the element, resulting in a change in background.

Answer №1

If you want the 'li' items to have the same height as the header, it's best not to define padding-top and bottom on '.header'. Your CSS code should be structured like this for the desired effect. You can view a working example here.

 .header {
    background-color: #00f;
    color: white;
    padding: 0 20px;

    & a{
      color: white;
      font-weight: bold;
   }
 }

 .header .nav {
    display: flex;
    justify-content: space-between;

    & .brand {
      padding-top: 20px;
    }
 }

 & .nav__menu {
    display: flex;
    margin: 0;
    padding: 0;

    & li {
      margin-right: 15px;
      padding: 20px 10px;
      text-transform:uppercase;
      list-style: none;
    }

    & li:hover {
       animation: headerLinks;
       animation-duration: 2s;
    }

 }

 @keyframes headerLinks {
     from {
        background-color: transparent;
     }
     to {
        background-color: #0f0;
     }
 }

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

Aligning Divs in a Responsive Browser

In the following illustration, I am facing an issue with my responsive code. I have three sections named square1, 2, and 3, each containing a white div with text on top and an icon positioned absolutely. Everything works fine when the browser width is 920p ...

problem with nivo slider causing content to overflow

My webpage is using nivoslider to display images. However, I am facing an issue where the images are overflowing one by one until the page fully loads. I have tried setting the overflow:hidden property in the CSS but it doesn't seem to correct the pro ...

Utilize the Twitter Bootstrap modal feature to play autoplaying Youtube videos that automatically pause when

Similar Question: How do I halt a video using Javascript on Youtube? I am curious about how I can utilize the modal feature in Twitter Bootstrap to automatically play a Youtube video, and when a user clicks the "close" button, it will cease the video ...

Is it possible to dynamically render css using Express.js?

I have a need to dynamically generate CSS with each request. For example, in my Express.js application, I've set up a route like this: /clients/:clientId/style.css When a matching request is received, I want to retrieve the Client from the reposito ...

How can I implement changing the page background color based on different routes in ReactJS and React Router?

Is there a way to change the background color of the browser when navigating to a new route in ReactJS and React Router? Check out my tips below that I discovered during my experimentation: I have managed to implement this on individual page views using & ...

Ways to display an icon with an underline effect upon hovering over text

I have implemented a CSS effect where hovering over text creates an underline that expands and contracts in size. However, I now want to display an icon alongside the text that appears and disappears along with the underline effect. When I try using displa ...

It is impossible to add a new element between two existing elements that share the same parent

I'm attempting to place an <hr> tag between the first and second .field-container. Because they have the same parent, I thought using element1.parentNode.insertBefore(element2, ...) would be the solution. However, it is not working as expected a ...

Prevent the box from closing automatically after submitting a form using jQuery

Despite my efforts to keep a simple dialog box open after submitting a form, it continues to close. I tried using the preventDefault method in jQuery, but it didn't solve the issue. Below is the code snippet: $(document).ready(function(e) { $(&apo ...

Navigation through dots on a single page

Having an issue with my dot navigation and anchor links placement. I want the anchors to be vertically centered in the middle of the section, regardless of window size. Here's what I'm aiming for : For larger windows : And for smaller windows : ...

My challenges with optimizing positioning in Media Queries for Hover Buttons

After completing the coding for all Smartphone devices, I moved on to working on Tablets. However, I encountered an issue during this process as I am unsure of how to fix it. Here is a preview of my "Section Skills" layout for mobile: View Section on Mobi ...

Struggling with aligning content within a div using CSS grid techniques

I am experimenting with CSS Grid and running into issues with overlaying content. The structure consists of a top-level container defined as a CSS grid (class="container"), followed by a content grid (class="content") that divides into 3 rows (header, labe ...

Position the table at the bottom of the page using CSS

I'm experiencing an issue where my HTML is not rendering correctly. I need to move the table with the ID "footer" to the bottom of the page. Here's the structure of the situation: <div id="container"> <table id="footer"></tabl ...

React - utilize a variable as the value for an HTML element and update it whenever the variable undergoes a change

I'm on a mission to accomplish the following tasks: 1.) Initialize a variable called X with some text content. 2.) Render an HTML paragraph element that displays the text from variable X. 3.) Include an HTML Input field for users to modify the content ...

Curious about how to swap the positions of these two divs?

After wrapping them in divs and adding inline-block to both elements to display them side by side, I'm now exploring options to switch their positions. Specifically, I'd like the right element to be on the left. Any ideas on how to achieve this? ...

JavaScript tool for implementing sorting features on an HTML table

I am facing an issue with my AJAX-loaded table where I need sorting functionality implemented. Despite searching for various JavaScript plugins, none seem to work efficiently due to slow performance or errors. The structure of my HTML table is unique with ...

Is it possible to manipulate a modal within a controller by utilizing a certain attribute in HTML, based on specific conditions (without relying on any bootstrap services), using AngularJS?

Within my application, I have a modal that is triggered by clicking on a button (ng-click) based on certain conditions. Here is the HTML code: <button type="button" class="btn btn-outlined" ng-click="vm.change()" data-modal-target="#add-save-all-alert ...

How can I use absolute positioning and scrolling with an Iframe?

One of the key elements of this website is the implementation of iframes, with only one displayed at a time. However, my current issue revolves around the inability to scroll within these iframes due to their absolute positioning. I have attempted variou ...

Display hidden text upon clicking using React Material UI Typography

I have a situation where I need to display text in Typography rows, but if the text is too long to fit into 2 rows, ellipsis are displayed at the end. However, I would like to show the full text when the user clicks on the element. I am attempting to chang ...

Enabling the upload of .sql files in a file input field

I'm working on a file input field that I want to restrict to only accept XML, SQL, and text files. Here's the code snippet I have implemented so far: <input type="file" name="Input_SQL" id="Input_SQL" value="" accept="text/plain,application/x ...

Displaying multiple div elements when a button is clickedLet multiple divs be

ISSUE Hello there! I'm facing a challenge where I need to display a div when a button is clicked. The issue arises from having multiple divs with the same class, making it difficult for me to target each individual div... Image1 Image2 Desired Outco ...