Unable to align a 1px element with the primary border

Can you please assist me?

I would like to modify the CSS markup below in order to remove the 1 pixel added extra on the active clicked tab from my UL LI Tabbed Menu. How can this be achieved?

Here is a picture of the issue:

HTML Markup:

<div class="container">
    <ul class="tabs">
        <li><a href="#tab1">Gallery</a></li>
        <li><a href="#tab2">Submit</a></li>
        <li><a href="#tab3">Resources</a></li>
        <li><a href="#tab4">Contact</a></li>
    </ul>
    <div class="tab_container">
        <div id="tab1" class="tab_content">Tab 1 Content</div>
        <div id="tab2" class="tab_content">Tab 2 Content</div>
        <div id="tab3" class="tab_content">Tab 3 Content</div>
        <div id="tab4" class="tab_content">Tab 4 Content</div>
    </div>
</div>

CSS:

.container {width: 500px; margin: 10px auto;}
ul.tabs {
    margin: 0;
    padding: 0;
    float: left;
    list-style: none;
    border-bottom: 1px solid #999;
    border-left: 1px solid #999;
    width: 100%;
    height: 31px;
}
ul.tabs li {
    float: left;
    margin: 0;
    padding: 0;
    height: 30px;
    line-height: 30px;
    border: 1px solid #999;
    border-left: none;
    margin-bottom: 0px;
    background: #e0e0e0;
    overflow: hidden;
    position: relative;
}
ul.tabs li a {
    text-decoration: none;
    color: #000;
    display: block;
    font-size: 1.2em;
    padding: 0 20px;
    outline: none;
}
ul.tabs li a:hover {
    background: #ccc;
}   
html ul.tabs li.active {
    background: #fff;
    border-top: 2px solid rgb(230,139,44);
    border-bottom: 1px solid #FFF;
}
html ul.tabs li.active a:hover  {
    background: #fff;
}
.tab_container {
    border: 1px solid #999;
    border-top: none;
    clear: both;
    float: left; 
    width: 100%;
    background: #fff;
}
.tab_content {
    padding: 20px;
    font-size: 1.2em;
}
.tab_content h2 {
    font-weight: normal;
    padding-bottom: 10px;
    font-size: 1.8em;
}
.tab_content h3 a{
    color: #254588;
}

Answer №1

These two lines (added at the bottom) resolved the issue:

.tabs ul { 
    border-bottom: none;
}
/* There is no need to include `html` in this code snippet. It serves no purpose! */
html .tabs ul li.active {
    border-bottom: none;
}

You can eliminate the need for a complete border below your tabs by allowing your li elements to handle it. Then, just move the 1px border from the bottom to the top by adding it to the border-top property. If you're not using box-sizing: border-box, make sure that all your borders add up to the same width to avoid issues like this.

.container {width: 500px; margin: 10px auto;}
.tabs ul {
    margin: 0;
    padding: 0;
    float: left;
    list-style: none;
    border-bottom: 1px solid #999;
    border-left: 1px solid #999;
    width: 100%;
    height: 31px;

}
.tabs ul li {
    float: left;
    margin: 0;
    padding: 0;
    height: 30px;
    line-height: 30px;
    border: 1px solid #999;
    border-left: none;
    margin-bottom: 0px;
    background: #e0e0e0;
    overflow: hidden;
    position: relative;

}

.tabs ul li a {
    text-decoration: none;
    color: #000;
    display: block;
    font-size: 1.2em;
    padding: 0 20px;
    outline: none;
}
.tabs ul li a:hover {
    background: #ccc;
}   
html .tabs ul li.active {
    background: #fff;
    border-top: 2px solid rgb(230,139,44);
    border-bottom: 1px solid #FFF;
}
html .tabs ul li.active a:hover  {
    background: #fff;

}
.tab_container {
    border: 1px solid #999;
    border-top: none;
    clear: both;
    float: left; 
    width: 100%;
    background: #fff;
}
.tab_content {
    padding: 20px;
    font-size: 1.2em;
}
.tab_content h2 {
    font-weight: normal;
    padding-bottom: 10px;
    font-size: 1.8em;
}
.tab_content h3 a{
    color: #254588;
}

.tabs ul { border-bottom: none; }
html .tabs ul li.active { border-bottom: none; }
<div class="container">

    <ul class="tabs">
        <li class="active"><a href="#tab1">Gallery</a></li>
        <li><a href="#tab2">Submit</a></li>
        <li><a href="#tab3">Resources</a></li>
        <li><a href="#tab4">Contact</a></li>

    </ul>
    <div class="tab_container">
        <div id="tab1" class="tab_content">Tab 1 Content</div>
        <div id="tab2" class="tab_content">Tab 2 Content</div>
        <div id="tab3" class="tab_content">Tab 3 Content</div>
        <div id="tab4" class="tab_content">Tab 4 Content</div>
    </div>
</div>

Answer №2

One possible solution is to adjust the positioning of the content by moving it up by one pixel:

html ul.tabs li.active a {
    position:relative;
    top:-1px;
}

If you'd like to see an example, you can check out this link: https://jsfiddle.net/7adfsmdj/

Answer №3

Adjust the height to 30px in ul.tabs since it was set as 30px in ul.tabs li


ul.tabs {
    margin: 0;
    padding: 0;
    float: left;
    list-style: none;
    border-bottom: 1px solid #999;
    border-left: 1px solid #999;
    width: 100%;
    height: **30px;**

}
ul.tabs li {
    float: left;
    margin: 0;
    padding: 0;
    height: **30px;**
    line-height: 30px;
    border: 1px solid #999;
    border-left: none;
    margin-bottom: 0px;
    background: #e0e0e0;
    overflow: hidden;
    position: relative;

}

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

Is there a way to make a Bootstrap grid with four columns span across two rows in the second column?

How can I create a Bootstrap grid with four columns where the second column spans two rows? Hello, I am looking for help to achieve a portfolio grid layout with 4 columns (refer image here) and have the second column span 2 rows. I plan to include images ...

Modal Pop-ups Failing to Open on Subsequent Attempts

My table consists of buttons on the right-hand side for a menu. The first button in the menu is supposed to open a modal box upon clicking. However, the first buttons in the subsequent rows do not function as expected and fail to open the modal. Refer to t ...

Incorrect Calculation of CSS Grid Container Width in Firefox

When using this CSS Grid code, there is a difference in behavior between Chrome and IE compared to Firefox. https://codepen.io/inkOrange/pen/XGzeMo This layout is intended to scroll horizontally when the content overflows beyond the fixed container size o ...

Issues arise when trying to manage HTML received as a response from a server in plain text

I have a scenario where I am dynamically generating an HTML table on the server side using Java and then sending it to the client as JSON data. The response looks something like this: <table class="table"></table><thead class="thead-dark"&g ...

How can I navigate to an anchor using hover?

I'm unsure if I can accomplish this task using just CSS and HTML or if I need to incorporate Javascript because my research did not yield much information on the subject. I have not attempted anything yet as I am uncertain about the approach I should ...

The sidebar's background is cut off before reaching the bottom when scrolling

I have been working on creating a sidebar that includes a background image with a transparent overlay. However, I encountered an issue where the overlay background does not stretch all the way to the bottom when the scroll bar becomes visible. Despite sett ...

Create a full-width slider using Materialize CSS framework

When using materializecss to create a slider, I encountered an issue where the image is full width but not full height, causing scrollbars to appear. What changes can I make to ensure the slider fills out my screen without any scrollbars? Additionally, I ...

Trouble displaying certain HTML code and its output on the browser?

I am in the process of developing a user profile page. I have designed a form with various fields, but the code within the section is not displaying correctly in the browser. I attempted to inspect the elements, but the code within that section remains inv ...

Creating a jquery DataTable from HTML generated by angular $sce can be done by following these steps

I have created an Angular controller that takes data and generates an HTML table from it. The generated table is being displayed on the page. Now, I want to apply jQuery data tables using that scope variable. The variable contains the HTML code of the tabl ...

Extract all class elements from HTML code and save them to a text file using PHP

Is there a way to extract all span elements with the class "msgsource" from my website's HTML code and then save it as a .txt file for downloading? I tried using the following code, but it only downloads an empty text file: <?php // Grabbing conte ...

Is there a way to display the output of jQuery in an input box rather than a span?

I need to display the result of this function in an input box instead of a span tag because I plan to utilize the result in the following form. function checkChange(){ $.ajax({ url: "ordercalculate.php", data: $('form').seria ...

Aligning a sprite at the center of a div background

My button has a unique design where it consists of a sprite set as the background image of a div. The sprite sheet is laid out horizontally, and I have also scaled down the source image to fit the div. .button { background: url(sprite.png); backgr ...

Leveraging icons with Bootstrap 4.5

I am currently exploring how to incorporate Bootstrap 4.5 icons using CSS. Do you have any examples of code that could guide me on how to achieve this? I am specifically interested in understanding the required CSS declarations that would allow me to use t ...

JavaScript code to retrieve an image from an <img> tag's source URL that only allows a single request and is tainted due to cross-origin restrictions

I have an image displayed in the HTML DOM. https://i.stack.imgur.com/oRgvF.png This particular image (the one with a green border) is contained within an img tag and has a URL as its source. I attempted to fetch this image using the fetch method, but enc ...

Transferring Text from Word to Expression using Copy and Paste

Whenever I try to copy and paste content from a Word document into Expressions Web, I encounter some strange behavior. Often, the top line gets placed in one <span> tag while the rest ends up in another <span> tag, causing a slight gap between ...

Tips for animating the box-shadow effect using jQuery

Can anyone provide insight on how to animate the box-shadow of multiple elements? I have reviewed previous threads such as this one, but found outdated and non-working solutions. Additionally, I came across the jquery box-animation plugin, which is limit ...

I am having trouble properly positioning an icon next to its corresponding text within a menu item

I'm a newcomer to the world of HTML5 + CSS3 and I'm having trouble with aligning menus, text, and icons within the menu. Here's the issue: Each line of the menu consists of an icon and a text description. The problem is that they are too clo ...

Troubleshooting issue with RadioButton check change not updating in onPost event in ASP.Net project utilizing Bootstrap HTML and C

Having created two radio buttons, grouped them together, and applied bootstrap classes for styling; I am encountering an issue where the values of the radio buttons are not updating when clicked and submitted. Interestingly, the checkboxes on the same form ...

Tips on styling HTML using a query value in string format

When using ASP.NET razor and SQL Server 2008 R2, I have a local variable declared in the following manner: var tsmMtd = db.QueryValue(" SELECT b.Name, SUM(subtotal) totalSUM FROM DR_TRANS a INNER JOIN Staff b ON a.Salesno = b.Staffno WHER ...

Ways to center vertically aligned buttons within cards in a React application with Material-UI

I've encountered an issue with my ReactJS project using material-ui. I created 3 cards, each with a paragraph of varying lengths. This caused the buttons to be misaligned vertically in each card, as the position differs due to paragraph size differenc ...