Steps for designing a navigational bar with tabbed style that is responsive

Upon inspecting the sample code, you may have noticed that the .current class leaves a grey area at the bottom. I am trying to make it white all the way down, but every attempt to increase the size of the li also extends the ul.

I'm facing an issue with overflow hidden because I still want the top offset on the li element.

Is there a way to achieve the effect of having the background color of the .current li extend to the bottom of the ul element?

http://codepen.io/anon/pen/rVrvZv

.site-nav {
    display: block;
}
.site-nav ul {
    background: linear-gradient(0deg, #d0d0d0, #fefefe);
    border-top: #bdbdbd solid 1px;
    border-bottom: #bdbdbd solid 1px;
}
.site-nav ul li {
    display: inline-block;
    width: 16.366666%;
    height: 2.5rem;
    text-align: center;
    line-height: 2.5rem;
    background: linear-gradient(0deg, #d0d0d0, #fefefe);
}
.site-nav ul li:hover {
    background: linear-gradient(0deg, #babcbf, #e1e3e6);
}
.site-nav ul li.current {
    position: relative;
    background: #fff;
    width: 16%;
    border-top: #bdbdbd solid 1px;
    border-left: #bdbdbd solid 1px;
    border-right: #bdbdbd solid 1px;
    top: -5px;
}
.site-nav a {
    font-family: Helvetica, sans-serif;
    color: #616264;
    text-transform: uppercase;
    letter-spacing: .08rem;
    text-shadow: rgb(224, 224, 224) 1px 1px 0px;
    filter: progid:DXImageTransform.Microsoft.Shadow(OffX=1, OffY=1, color=#e0e0e0);
    font-size: .75rem;
}
<div class="site-nav">
    <ul>
        <li><a href="#">one</a></li>
        <li><a href="#">two</a></li>
        <li><a href="#">three</a></li>
        <li class="current"><a href="#">four</a></li>
        <li><a href="#">five</a></li>
        <li><a href="#">six</a></li>
    </ul>
</div>

Answer №1

To enhance the current highlight style, consider applying it to the <a> element instead of the <li>. You may also want to utilize a pseudo element :before to add additional space at the top.

View Demo on JSFIDDLE

.site-nav ul {
    padding: 0;
    margin: 0;
    font-size: 0; /*eliminate inline block gap*/
}
.site-nav ul li {
    background: linear-gradient(#fefefe, #d0d0d0);
    border-top: #bdbdbd solid 1px;
    border-bottom: #bdbdbd solid 1px;
    display: inline-block;
    width: 16.66%;
    height: 2.5rem;
    line-height: 2.5rem;
    text-align: center;
}
.site-nav ul li a {
    display: block;
    font-family: Helvetica, sans-serif;
    font-size: .75rem; /*reset font size*/
    text-transform: uppercase;
    letter-spacing: .08rem;
    text-decoration: none;
    color: #616264;
    text-shadow: rgb(224, 224, 224) 1px 1px 0px;
}
.site-nav ul li a:hover {
    background: linear-gradient(#e1e3e6, #babcbf);
}
.site-nav ul li.current a {
    background: #fff;
    border: #bdbdbd solid 1px;
    border-width: 0 1px;
}
.site-nav ul li.current a:before {
    content: "";
    height: 4px;
    display: block;
}
<div class="site-nav">
    <ul>
        <li><a href="#">one</a></li>
        <li><a href="#">two</a></li>
        <li><a href="#">three</a></li>
        <li class="current"><a href="#">four</a></li>
        <li><a href="#">five</a></li>
        <li><a href="#">six</a></li>
    </ul>
</div>

If compatibility with older versions of Internet Explorer is a concern, refer to this post on how to create CSS3 cross browser linear gradient.

Answer №2

If you want to style the list element, consider adding margin-bottom:-5px; and padding-bottom:5px; to your .current class. Alternatively, follow Pangloss's suggestion of styling the anchor element instead.

.site-nav {
display: block;

}

.site-nav ul {
    background: linear-gradient(0deg, #d0d0d0, #fefefe);
    border-top: #bdbdbd solid 1px;
    border-bottom: #bdbdbd solid 1px;
}

.site-nav ul li {
    display: inline-block;
    width: 16.366666%;
    height: 2.5rem;
    text-align: center;
    line-height: 2.5rem;
    background: linear-gradient(0deg, #d0d0d0, #fefefe);
}
.site-nav ul li:hover {
    background: linear-gradient(0deg, #babcbf, #e1e3e6);
}

.site-nav ul li.current {
    position: relative;
    background: #fff;
    width: 16%;
    border-top: #bdbdbd solid 1px;
    border-left: #bdbdbd solid 1px;
    border-right: #bdbdbd solid 1px;
    top: -5px;
    padding-bottom:5px; /* add this */
    margin-bottom:-5px; /* add this */
}

.site-nav a {
    font-family: Helvetica, sans-serif;
    color: #616264;
    text-transform: uppercase;
    letter-spacing: .08rem;
    text-shadow: rgb(224, 224, 224) 1px 1px 0px;
    filter: progid:DXImageTransform.Microsoft.Shadow(OffX=1, OffY=1, color=#e0e0e0);
    font-size: .75rem;
}
<div class="site-nav">

  <ul>
    <li><a href="#">one</a></li>
    <li><a href="#">two</a></li>
    <li><a href="#">three</a></li>
    <li class="current"><a href="#">four</a></li>
    <li><a href="#">five</a></li>
    <li><a href="#">six</a></li>
  </ul>

</div>

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

Having issues with the basic KnockoutJS binding not functioning as expected

There appears to be an issue with my KnockoutJS script that I'm struggling to pinpoint. Below is the snippet of HTML code: <h2>SendMessage</h2> <div class="form-group" id="messageSender"> <label>Select User Type</l ...

Utilize Bootstrap to display 8 columns side by side on Desktop screens, while on mobile, only display 3 columns

To display logos in 8 columns using Bootstrap 5, I implemented the following code: <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7f1d10100b0c0b0d1e0f3f4a514e514c">[email p ...

AJAX Post Request Function without Form That Does Not Reset

I am currently struggling with understanding the Ajax POST method. I am attempting to make an API request, and since the response has similar parameters, I decided to create a global function that can be used by other HTML/JS pages. However, I am aware tha ...

HTML5 Page Structure Design

As I embark on my journey to create my very first Wordpress theme for my personal blog, I have a few questions regarding the layout. Should I use Grid960? Also, should I put the articles in one section or the opposite? Here is the layout structure I am con ...

Display an image with HTML

My current project involves creating a chrome extension that will display a box over an image when hovered, while also zooming the image to 1.5 times its original size. In my research, I came across a similar example. .zoomin img { height: 200px; wi ...

PHP integration with input forms

Is there a way to have multiple text fields that input data into various sections on a single webpage? If necessary, I could split the content over two pages. I've heard that this may involve using a PHP script, but I'm unsure of the steps to imp ...

Images in gallery slider are excessively large

Hello, this is my very first post on stackoverflow. Please forgive any atypical elements in this post. I have a Django Website with a gallery slider, but I am facing an issue where the images appear way too big. You can view them here: I have dedicated n ...

Trouble with the Rotate <text> feature in Internet Explorer 11 on Windows 10

I am using d3.js to draw SVG with the transform:rotate(180deg) property. It displays perfectly on Chrome, but doesn't work on IE11. I tried changing it to rotateY(180deg), and it works with div elements but not with text elements. Here is my screen an ...

Leveraging CamanJS for canvas filtering

These are my HTML elements: <div class="wrapper"> <nav class="navbar navbar-transparent"> <div class="container-fluid"> <div class="navbar-header"> <span class="btn btn-white btn-file"> ...

My footer is having trouble displaying social media icons properly

I'm new to coding and I'm trying to create a dark footer, dark navbar, and some carousel content. Unfortunately, the social media icons and copyright symbol in my footer are only half visible. How can I resolve this issue? Below is the code snip ...

Enhance Website Functionality with Dynamic Tables and Spreadsheet Features

Currently, I need to incorporate spreadsheet-like functions into a table on my website. Initially, I explored KendoUI but realized it might not be within my budget constraints. Is there a more affordable alternative available? Key features I require inclu ...

Adjusting the cell size to align with the height of another cell in the same row

Within a table row, I have two cells that contain divs and the height varies due to changing content. Is there a way for one cell to take up 100% height to match the other cell? You can see an example here. The goal is for the second cell and its div to ...

Is it possible for me to utilize Bootstrap CSS directly from a CDN instead of including the SASS file in my Node project?

Just a quick inquiry to kick things off. I'm currently developing a node application and considering using SCSS for styling. My question is, if I include the Bootstrap CSS file from a CDN in my index.html, will I be unable to override the variables? ...

Manipulate a table using Jquery's find() method to insert a cell populated with information from an array using before()

My current challenge involves inserting a column of cells with data from an array. Despite attempting to use a for loop, all the cells end up displaying the same data from the array. What I really want is for each new cell to show 'row_header1', ...

Deleting a database table row with a click of a button

I am working with a table structure in my HTML: <table class="table" id="mytable"> <tr> <td>Column 1</td> <td>Column 2</td> <td><button type="submit" class="btn removeButton">Remove</button& ...

What is the best way to implement a custom SVG icon within the Vuetify v-icon component?

Is it possible to utilize the v-icon component in Vuetify to display a custom icon that has been defined as an SVG in a file named my-icon.svg? This SVG file is located within the public/img directory of my project. How can I reference this file inside t ...

Exploring how to set dropdown menu width for Angular2 mat-select options

Currently, I am using the angular2 mat-select control and facing an issue with the width and position of its dropdown list menu. By default, it is wider and overflows the element on both sides by a few pixels. I have not found any option for adjusting the ...

Using HTML5 Canvas with Firefox 4: How to Retrieve Click Coordinates

Lately, I've been diving into creating HTML5 Video and Canvas demos. Initially, my focus was on optimizing them for Chrome, but now I'm shifting my attention to Firefox and Safari as well. One particular demo I'm currently working on involv ...

Looking to implement a feature in Angular 2 where content on a page can be filtered based on a single array property of the user

Feeling lost here. I need to filter books on the page by their specific Category (Philosophy, Classic, Poetry, etc.) when a user clicks a corresponding button. However, I'm new to Angular and coding in general, so I really want to grasp this concept f ...

Solving the issue of Cumulative Layout Shift within a Div

I've been working on fine-tuning my website to eliminate Cumulative Layout Shifts and have addressed most issues. However, Chrome Developer Tools is flagging a specific code block for CLS: <div class="colorlib-services colorlib-bg-white"& ...