Increase the height of items in a top navigation bar in proportion to the height of the logo

Does anyone have a solution for how to make the links inside the div.topbar take up the full height of the container, especially when they are hovered over?

I've extracted this specific feature and shared it [here][1]. I'm not sure if there's a better way to explain it.

div.topbar {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-box-align: baseline;
  -ms-flex-align: baseline;
  align-items: baseline;
  background-color: white;
  border-bottom: 1px solid black;
}

div.topbar #logo {
  background: repeating-linear-gradient(45deg, yellow, black 10px);
  color: white;
  padding: 15px;
  font-size: 2em;
  text-shadow: 3px 3px 3px purple;
}

div.topbar a {
  color: black;
  text-decoration: none;
  font-weight: bold;
  display: inline-block;
  padding: 15px;
}

div.topbar a:hover {
  background-color: #ccc;
  color: green;
}

div.topbar a a:nth-child(3) {
  border-right: none;
}
<header>
  <div class="topbar">

    <a href="#a" id='logo'>jS.tut</a><a href="#b">More Tuts</a><a href="#c">Home</a>
  </div>
</header>

Answer №1

It seems like the challenge you're facing is related to centering text and making the item 100% in height.

In order to achieve this, ensure that your flex items are also set to display flex with align-items: center. It's not necessary to set align items on the container since you want it to stretch. Additionally, there's no need to make your anchors display inline-block as they are already considered flex items due to being children of a flex container where we have set the display to flex. The default flex direction is row, so there's no need to define it again.

To improve readability, I've removed the browser prefixes for you:

div.topbar {
  display: flex;
  background-color: white;
  border-bottom: 1px solid black;
}

div.topbar #logo {
  background: repeating-linear-gradient(45deg, yellow, black 10px);
  color: white;
  padding: 15px;
  font-size: 2em;
  text-shadow: 3px 3px 3px purple;
}

div.topbar a {
  color: black;
  text-decoration: none;
  font-weight: bold;
  padding: 28px 15px 15px 15px;
  display: flex;
  align-items: center;
}

div.topbar a:hover {
  background-color: #ccc;
  color: green;
}

div.topbar a a:nth-child(3) {
  border-right: none;
}
<header>
  <div class="topbar">

    <a href="#a" id='logo'>jS.tut</a><a href="#b">More Tuts</a><a href="#c">Home</a>
  </div>
</header>

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

"Looking for a solution to the ESLint error related to 'no-unused-var' and Google Maps integration. How can I effectively resolve

I'm struggling with what seems to be a simple problem I tried adding /* export myMap */ or /* global myMap */ at the beginning of the script but I keep getting errors Code HTML <h1>My First Google Map</h1> <div id="googleMap" ...

Customize arrow direction in AntDVue ant-collapse using simple CSS styling

Is there a way to customize the arrow directions in ant-collapse vue? I recently faced an issue where I couldn't change the arrow directions without using !important (which I try to avoid). Fortunately, we found a workaround for this problem at my wo ...

Update the numerical data within a td element using jQuery

Is there a way to use jquery to increase numerical values in a <td> element? I've attempted the following method without success. My goal is to update the value of the td cell by clicking a button with the ID "#increaseNum". Here is the HTML st ...

Command line functionality to eliminate comments in HTML minifier

I am interested in utilizing html-minifier to compress my html documents. After executing the command npm install -g html-minifier, I have successfully installed it. However, the command sudo html-minifier rb.html --removeComments did not eliminate comme ...

When the anchor tag is clicked, I'm displaying the DIV for Customer Testimonials, however, the expansion of its height is not

One way to display customer testimonials is by using flexslider to create a horizontal scroll. The testimonials are hidden and only shown when the "view all testimonials" link is clicked, which can be seen in this JSFiddle example: Working : Demo JQuery ...

Problem with Bootstrap container-fluid overlapping with floated element

I am struggling with the layout of my card body, which includes a floating logo and rows enclosed in a container-fluid. While everything looks great in Chrome, I am facing alignment issues in Edge and Firefox. I have considered using absolute positioning ...

Implementing yadcf and a fixed column filter in a Bootstrap datatable

I am currently utilizing Bootstrap DataTable in conjunction with the Yadcf filter plugin. The filter is functioning correctly for a regular table, however, when I have a fixed column with a Select2 dropdown, it does not render properly. The dropdown is hid ...

Tips for Organizing a Vast Array of Repetitive "Nth-Of-Type" CSS Selectors

Imagine an array of vibrant highlights, all controlled through CSS. Is there a way to condense this extensive block of CSS code while achieving the same result? In simpler terms, is it possible to reduce the repetition in the code by using only CSS when ...

What is the best way to activate the cube portfolio using custom jquery?

Is there a way to activate the Cube portfolio filter using custom JQuery? see image here For instance: In my Cube portfolio slider, I have over 20 projects featuring different technologies. When I slide the div, I want the filter to be activated based on ...

Creating a custom Jquery function to generate a Div element instead of a Textbox in your web application

I need assistance with a jquery function that retrieves data from a JSON PHP MySQL setup. The retrieved results are currently displayed in textboxes. function showData(wine) { $('#Id').val(wine.id); $('#question').val(wine.question ...

Tips for positioning an image at the center of a div element

How can I properly center an image in the middle of a div? <div class="main"> <img...> </div> In the code snippet below, the image is centered, but not perfectly in the middle. https://jsfiddle.net/web_garaux/tng7db0k/ ...

Is there a way to adjust the color of the checkbox?

After creating a show/hide toggle checkbox for a password input, I ran into an issue with changing the background color when it is checked. Our current code base includes a custom styled checkbox, but it lacks the ng-model needed for this particular featur ...

Guide on connecting a URL with a generated ID to the <a href> element

I am currently working on building my own portfolio website using Django. The main idea behind this project is to create posts showcasing the websites that I have developed. These posts will be featured on a page titled "Projects," where viewers can click ...

Simple Design: Main Navigation Bar Positioned to the Right Side of the Master Page

I must admit, styling is not my strong suit and I could use some help. On my CSS page, I need the MasterPage Navigation bar to be on the left side. However, when I click on a link to go to a different page, I want the content to show up in the middle while ...

Troubleshooting a Responsive DIV with Hover Effects in CSS

I am encountering an issue with the mobile version of a responsive website that I am constructing. The green "info" DIV seen at the top left corner in the full-screen version needs to be relocated and placed at the bottom of the screen, just above the foo ...

The Function(JS) is specifically designed to only function within the topmost div or quote

Currently, I am facing an issue with a function I have implemented. This function adds a blur effect to words in a Blockquote when the page is loaded. However, I need this function to work for all Blockquotes and different divs on the page, not just the to ...

Challenge of Bootstrap 5 navigation bar not collapsing

Issue with responsive navigation bar not collapsing All necessary libraries already included <div class="collapse navbar-collapse justify-content-end" id="navbarSupportedContent"> <ul class="navbar-nav mb-2 mb-lg-0&qu ...

Looking to extract latitude and longitude data using an Autocomplete Address Form

I am currently attempting to utilize Google Maps autocomplete feature in order to save latitude and longitude. Unfortunately, I am encountering difficulties in making this functionality work as intended. Given that I am unfamiliar with the Google Maps API, ...

Relocate the form element from its current position inside the form, and insert it into a different div

I have a sidebar on my website with a search/filter form. I am attempting to relocate one of the elements (a sort order dropdown) from this form, outside the form using CSS/JS and display it inside a div on the right side. Is it possible to do this without ...

Click event dynamically bound to list items

I have a web application built with Durandal and Knockout. Here is the HTML code snippet: <ul id="header"> </ul> In a JavaScript function, I am dynamically adding a list item as follows: $("#header).append('<li id="btn"><a hre ...