When utilizing a hexadecimal notation for the background color, the lower border may vanish

While attempting to add a 1px solid border around an anchor tag with a dark background color in hexadecimal format, I discovered that the bottom border was not showing up!

After investigating for a while, I realized that the issue was caused by the background color being expressed in hexadecimal. It seems that in this scenario, the browser starts rendering the background 1px lower than it should, causing the background color to overlap the bottom border. If the background color is darker than the border color, the bottom border appears to "disappear."

To demonstrate this behavior, I created a fiddle:

HTML
<a href="#" id="a1">ANCHOR1</a>
<br>
<a href="#" id="a2">ANCHOR2</a>
<br>
<a href="#" id="a3">ANCHOR3</a>
<br>
<a href="#" id="a4">ANCHOR4</a>

CSS
a {
text-decoration:none;
}
a, div {
width:95%;
padding-left:5%;
display:block;
border:1px solid red;
}

#a2, #d2 {
background-color:yellow;
}

#a3, #d3 {
background-color:#00ffb6;
}

#a4, #d4 {
color:white;
background-color:#1769b6;;
}
  1. element without background color: border displays correctly all around it
  2. element with named color background: border still visible all around
  3. element with light hexadecimal background color: border shows but background renders 1px lower, overlapping the bottom border
  4. element with dark hexadecimal background color: bottom border appears to vanish

I tested this on Mac El Capitain 10.11.6 using:

  • Firefox 51.0.1
  • Chrome 56.0.2924.8
  • Safari 10.0.3

All browsers exhibited the same behavior.

Any suggestions on how to achieve a full 1px solid border around an element with a hexadecimal background?

The problem is not specific to the anchor tag, as demonstrated in the fiddle where the same styles were applied to divs.

https://i.sstatic.net/0Ox3D.jpg

Answer №1

My solution involved using the CSS property

background-clip: padding-box;

along with setting a slightly larger border-bottom-width

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

Trouble with Javascript slideshow: Incorrect display and malfunctioning

Struggling with implementing a slideshow banner on my webpage, despite following the W3 tutorial. Here is the code I am currently using: HTML: <div class="slide-content" style="max-width:1000px"> <img class="slidepic" src="testheadphoto.jpg" st ...

How can I correctly focus on 'highlight' events using the tab key on an HTML element?

I'm struggling to figure out the event that is triggered when an element gains focus through tab navigation. I want all buttons in the codepen provided to expand to full size when tabbed over. https://codepen.io/anon/pen/YopBaz Currently, I have achi ...

What could be causing disparities in the padding of certain table cells compared to others?

If you're interested, I created a photo gallery over at Take a look around and feel free to download any wallpapers that catch your eye! The issue I'm encountering is with the padding of the columns - specifically, the first and last columns ha ...

Utilizing the Material Design card div element, however the elements inside the card are not properly aligned in the center

I'm attempting to include the align="center" attribute to this Material Design Lite card: <main class="mdl-layout__content" align="center"> <div class="mdl-cell mdl-card mdl-shadow--4dp portfolio-card"> <div class="mdl-card__title"&g ...

Using CSS to overlay a fixed element with a specific z-index

HTML: <div class="wrap"> <div class="fixed"></div> </div> <div class="cover"></div> CSS: .cover{z-index: 10;} .wrap{position: relative; z-index: 1;} .fixed{position: fixed; display: block; z-index: 1;} Example: ...

Learn how to incorporate a vertical divider pipe into your website using Bootstrap

Hello, I'm having trouble adding a separator between nav-links that actually works. I tried adding the following code snippet: nav-link:after { content:"|"; } But unfortunately, it's either not working at all or appearing on the left side of th ...

How to align a child element in the center when the parent is not centered or taking up the full width

I am currently working on building a layout with Bootstrap 4.6, and I am facing an issue with centering the header, columns/cards, and buttons on the page width while the parent container is left-aligned and not full width. Additionally, I need help with ...

Is it possible to align a CSS table row with its corresponding table header even when the table row is deeply nested within the table structure?

I am looking to keep the structure of my HTML code consistent and unaltered. However, this has resulted in a form tag being nested inside a table row before the table cells can begin. The information I need to display is tabulated data, which makes CSS t ...

Ways to avoid scrolling on a fixed element

Here is the HTML setup I have... body .top .content The issue I am facing is that when scrolling reaches the end of the ul in the .top element, the background starts to scroll. This can be quite disorienting and makes the site slow on tablets. Even ...

Encountered a parsing error while attempting to include the navigation bar page

<?php echo <<< END <!DOCTYPE html> <!-- --> <html> <head> <title>Nav</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0 ...

Printing Multiple Pages Using JavaScript and Cascading Style Sheets

Encountering difficulties displaying page numbers when printing multiple multipage reports Here is the provided HTML Format : <style type="text/css> body { counter-reset: report 1 page 0; } td.footer:after { counter-increment: page; content ...

Removing a background by linking a CSS file

Issue Resolved: I have found the solution. The problem was that the css document still contained html tags. Thank you to everyone who provided assistance. While designing a website using css, I encountered a situation where the site worked perfectly when ...

Conflicting Media Queries causing issues

Seeking assistance on media queries for my website. It currently has two responsive viewports: max-width: 414 px (iPhone) and max-width: 770px (iPad) While the style tags are in the correct order in the css document, the cascading nature is causing my ...

What is the best way to add several icons at once?

Is there a way to insert multiple star icons directly below the review text? I attempted to use pseudo elements to add the icons, but I could only insert one icon when I actually need to include multiple icons. Here is what I have tried so far: .review:: ...

What is the best way to calculate the number of squares required to completely fill a browser window in real-time?

I am creating a unique design with colorful squares to cover the entire browser window (for example, 20px by 20px repeated both horizontally and vertically). Each square corresponds to one of 100 different colors, which links to a relevant blog post about ...

A Guide to Configuring jQuery UI Slider with Three Distinct Colors

I'm currently implementing the UI Slider on my website. However, I would like to customize the slider with three different colors: Handle Color Previous portion of Handle Next portion of Handle I want it to look something like this: Currently, I h ...

What is the reason for the presence of white space surrounding the div element

In the td element, I have four nested div elements. However, there seems to be a small margin or space created between them that I cannot figure out how to remove. If this spacing is due to the behavior of the inline-block, then how can I override it? ...

Struggling to align text input within a label element

I'm struggling with centering the text on Bootstrap radio buttons that I am customizing. I have tried adjusting the margin, align-content, vertical-align, and text-align properties but the text still won't vertically center. Any suggestions? Her ...

The CSS focus-within and hover properties are not functioning as expected

How can I make the search tags visible (the buttons above the text input field) when the search bar below them is clicked? I've tried using :hover, :focus, and :focus-within, but none of them seem to be working. Can someone help me figure out the issu ...

What is the source of this additional space?

To view my Codepen project, check out this link: http://codepen.io/leongaban/pen/aFJfs I have noticed that the spacing issue is related to the .email-tip-icon and the tip-message classes. When I remove them, the extra space disappears. Even though both th ...