Issue with displaying random 1px background image on Chrome browser

I'm facing an issue with the background image not appearing for one of the links in my navbar in Chrome. Specifically, the image doesn't show up between the "Athletics" and "Bowling" links.

Interestingly, the background image displays fine in Firefox and Explorer. I've tried various solutions like adjusting the background-size and image-rendering properties in CSS, but nothing seems to make it work in Chrome.

How can I ensure that all background images are correctly displayed across different browsers?

CSS

ul {
    display: flex;
    list-style: none;
}

ul a {
    background: url(sports-div.png) right bottom no-repeat;
    display: inline-block;
    font-family: sans-serif;
    font-size: 13px;
    padding: 5px;
}

HTML

<ul>
<li><a href="#">Football</a></li>
<li><a href="#">Basketball</a></li>
<li><a href="#">Tennis</a></li>
<li><a href="#">Ice hockey</a></li>
<li><a href="#">Volleyball</a></li>
<li><a href="#">Badminton</a></li>
<li><a href="#">Snooker</a></li>
<li><a href="#">Athletics</a></li>
<li><a href="#">Bowling</a></li>
<li><a href="#">Cycling</a></li>
</ul>

http://jsfiddle.net/zc29b8no/1/

Answer №1

The explanation of the technical details is quite lengthy and dull.

However, in essence, it relates to subpixel rendering.

The dimensions of your anchors are not perfectly defined pixels, causing the browser to estimate what should be rendered in each pixel. Your image with a width of 1px falls on the incorrect side of rounding. To ensure that it appears within the element's background, you need to substitute the right alignment in background-position (which equates to 100%) with calc(100% - 1px):

ul {
display:flex;
list-style:none;
}

ul a {
background:url(https://i.imgur.com/mCra304.png) calc(100% - 1px) bottom no-repeat;
display:inline-block;
font-family:sans-serif;
font-size:13px;
padding:5px;
}
<ul>
<li><a href="#">Football</a></li>
<li><a href="#">Basketball</a></li>
<li><a href="#">Tennis</a></li>
<li><a href="#">Ice hockey</a></li>
<li><a href="#">Volleyball</a></li>
<li><a href="#">Badminton</a></li>
<li><a href="#">Snooker</a></li>
<li><a href="#">Athletics</a></li>
<li><a href="#">Bowling</a></li>
<li><a href="#">Cycling</a></li>
</ul>

An alternative solution could be to increase the width of the image to 2px, but there may still be variability in its 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

Expanding your knowledge of AngularJS: utilizing ng-click to interact with elements

After a user clicks on an element in my app, I have some logic that runs. For example: html <h3 ng-click="showAlert('text')">this is text! (try to click and select)</h3> js $scope.showAlert = function(text) { console.log(' ...

Add a pair of assorted div elements to a shared container

I have two different sections with classes named "red" and "blue". By default, these sections are hidden. I want to duplicate them and display them in a single container named "cont". The red button appends the red section and the blue button appends the b ...

"Utilize Ajax to load PHP content and dynamically refresh a specific div

I have implemented an image uploading system, but now I want to incorporate a feature that allows users to rotate the uploaded images using Ajax. The challenge I'm facing is that if the session variable is lost during a full page update, I need to ens ...

The presence of a display block property within a div contained inside an li element results in extra whitespace

I am presenting the code below: <div class="settingsMenu" style="top: 135px; left: 149px; display: block;"> <ul> <li class="download" onclick="downTemplate('template1')">Download</li> <l ...

Center align Bootstrap 4 dropdown menu

I am attempting to center align my dropdown menu using Bootstrap 4. Following the given example: [ This is the result I am achieving: [ This is the code I have implemented: <div class="container"> <div class="row"> <div class=" ...

How can I reset the mousemove event in jQuery?

I need to create a mechanism where I can move a div by clicking on it, and then click again to stop the div in that position. However, encountering an issue when trying to move the div again as the mousemove event does not get activated. How can this be ...

Express.js problem: Unable to load CSS and JS files from the 'public' directory

Currently, I am working on a web project with Express.js and encountering difficulties in loading CSS and JavaScript files from the 'public' folder. Despite following common practices, it seems that something is amiss. Here is the layout of my pr ...

Using the section :export in the SCSS :root declaration

In the file test.module.scss, I store all my variables for colors, typography, and more. I want to be able to use these variables in my react components. However, the file starts with :root to define the variables: :root{ --color-white: #fff; --color-b ...

Is it possible to showcase a FullCalendar event in full width while being positioned behind other events scheduled for the same time slot?

Is there a way to customize FullCalendar so that concurrent events in the same timeslot are not vertically divided? I have a Google calendar named "time-blocking template" where I want all events to take up 100% of the timeslot width, even if there are ot ...

There seems to be an issue with the SQL syntax. Please refer to the corresponding manual for MySQL

An SQL error has occurred. Please refer to the MySQL server manual for the correct syntax near ' product_code, product_name, product_desc, price FROM products' at line 1 <?php include('include/conn.php'); $per_page = 5; $adjacen ...

Ajax: Why am I receiving an error response instead of a successful one?

It's puzzling why my code is triggering the error function instead of success. The console.log keeps showing me this: Object {readyState: 0, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: f ...

Adjust the size using padding alone

My CSS specifies font size of 14px, line height of 14px, and padding of 7px on the top and bottom. The total should be 28px. When I apply these styles in a div, it results in a height of 28px. However, when applied to a ul li a element, the height becomes ...

The parent navigation bar in HTML and CSS is hogging more space compared to its children

In the midst of my vuejs project, I have encountered an issue relating to the size of elements. Specifically, my header consists of a logo and a navbar. The navbar seems to be extending the size of the header unnecessarily. Upon inspection, I noticed tha ...

The importance of CSS style prioritization

I can't seem to figure out CSS declaration priority. I have an external CSS file with a rule and some inline CSS declarations that are supposed to override it. According to my understanding, inline styles should take precedence over external CSS rules ...

Why does one HTML link function while the other does not?

After creating links that connect two HTML files, I encountered an issue where one link does not work. The situation involves a folder named aiGame containing the aiindex.html file along with ai.js and ai.css. It is worth noting that the index.html file is ...

An individual in a chat App's UserList experiencing issues with incorrect CSS values. Utilizing Jquery and socketio to troubleshoot the problem

Currently, I am testing a new feature in a chat application that includes displaying a user list for those who have joined the chat. The challenge is to change the color of a specific user's name on the list when they get disconnected or leave the cha ...

displaying the identical image from various perspectives

I have an arrow image that I need to display in different angles - top, left, bottom, right. I was considering what would be the best approach: 1: Changing the image direction via CSS and loading the main image <img src="a.png"> <img src="a.png" ...

Accessing an Android device from localhost using a hostname with ever-changing IP addresses

SCENARIO: I am currently running a local webpage on a WAMP server from my computer, which is connected to a wireless network. Additionally, I have an Android tablet also connected to the same network. OBJECTIVE: My goal is to access the local webpage on ...

My Jquery CSS Checkbox is failing to register when it's checked

I have implemented custom checkboxes using a custom CSS checkbox generator. $( ".button" ).click(function() { if(document.getElementById('terms_checkbox').checked) { alert('Checkbox is checked'); } else { alert('Chec ...

Incorrect synchronization in the SVG arrow animation

How come the arrow doesn't start moving at the same time as the line? Is there a synchronization issue? I want the arrow to begin its journey simultaneously with the line. .container{ width:100%; padding:0px; background-color: black; } .squig ...