Possible Chrome Bug Affecting CSS Margin Issue?

Wondering if there might be a bug lurking in Chrome or if my CSS needs some tweaking. The issue at hand is that even though I've set a CSS declaration on .blockmenu li with margin: 2% !important, Chrome doesn't seem to be interpreting the percentages correctly.

To take a closer look, check out the JS fiddle link - http://jsfiddle.net/T3bWE/17/

The CSS code snippet is as follows:

.blockmenu ul {
    padding: 0px !important;
    margin: 0px !important;
}
.blockmenu li {
    padding: 0px !important;
    margin: 2% !important;
    list-style: none;
    list-style-position: inside;
    display: block;
    position: relative;
    width: 25%;
    float: left;
    display: table;
}
.blockmenu li a {
    height: 150px;
    margin: 10px;
    display: block;
    text-align: center;
    color: #fff;
    display:table-cell;
    vertical-align:middle;
}
.blockmenu li:nth-child(3n-2) a {
    background: #e31937;
}
.blockmenu li:nth-child(3n-1) a {
    background: #002f5f;
}
.blockmenu li:nth-child(3n) a {
    background: #dcdcdd;
    color: #58595b;
}

The HTML markup looks like this:

<div class="blockmenu">
    <ul>
        <li><a href="#!">item 1</a>
        </li>
        <li><a href="#!">item 2</a>
        </li>
        <li><a href="#!">item 3</a>
        </li>
        <li><a href="#!">item 4</a>
        </li>
        <li><a href="#!">item 5item 5item 5<br>item 5item 5</a>
        </li>
    </ul>
</div>

Just wondering if Chrome's playing tricks or if I missed something in the CSS, because it seems to display fine in other browsers. When looking at the development tools, the left margin shows differing values like 5.641, 4.234, 2.828, 1.453 in Chrome, whereas Firefox maintains consistency at 5.641.

Here's a screenshot from Chrome:

And here's one from Firefox:

Answer №1

.blockmenu ul li {
    padding: 0px !important;
    margin: 2% !important;
    list-style: none;
    width: 25%;
    display: table-cell;
    float: left;
}
.blockmenu li a {
    height: 150px;
    margin: 10px;
    width: 25%;
    text-align: center;
    color: #fff;
    display: table-cell;
    vertical-align:middle;
}

A correction was made to eliminate duplicate/incorrect display styles, and a width declaration was added for the .blockmenu li a element.

To confirm that the changes are effective, I have created a copy of your fiddle here: http://jsfiddle.net/f3sGr/

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

Centering loaders within elements of an unordered list

I am working on a navbar that uses Bootstrap 3 and AngularJS. Within this navbar, I have an unordered list with li elements. Below is a snippet of my navbar: https://i.stack.imgur.com/o75Lp.png This is the code for my navbar: <div class="navbar-head ...

What strategies can be implemented to minimize the impact of HTML code on just one specific div (or any other chosen element)?

<div> <b> some example </div> different content This will make the "different content" bold. Is there a way to restrict the impact of <b> only to the <div> element? I have tried looking for JavaScript solutions online but did ...

Issue retrieving text from a webelement using Selenium in Python

In my Python/Selenium code, I have the following snippet: try: main = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, "main")) ) print(main.text) except: driver.quit() I was expecting a print statement ...

Custom Jquery function is failing to position divs correctly within ajax-loaded content

I recently coded a custom function that efficiently positions absolute divs within a container by calculating top positions and heights: $.fn.gridB = function() { var o = $(this); //UPDATED from var o = $(this[0]); o.each(function() { var ...

Is there a way to alter the appearance of an HTML element without an ID using a JavaScript function?

I have a specific goal in mind, but I'm struggling to articulate it concisely. Despite conducting extensive research, none of the suggested solutions seem applicable in my case. Objective: I aim to change the background color of a div based on the da ...

Looking to incorporate two @return statements in a Sass function

I have a very straightforward Sass function that converts a pixel value to a rem value: @function to-rem($pxval) { @return #{$pxval / $base-font-size}rem; } For example, using to-rem(24) would output 1.5rem. However, I recently ran into an issue whe ...

Creating a slider with a large central image and just three slides that automatically transition

I am trying to create a slider that includes: 3 different images 3 different text captions A button that opens a modal dialog similar to Bootstrap, with each slide's button displaying unique text in the modal The slider should automatically slide Fo ...

Styling Rules for WebKit Browsers

Is there a method to apply a particular CSS style for a div based on whether the user is accessing the page from a Chrome browser on a Desktop or an Android device? .myDIV{ [if CHROME???] width: 280px; [if ANDROID???] width: 100%; } Seeking guidance on ...

having each individual div function on its own accord

Is there a more efficient way to make HTML and CSS function independently without duplicating the code multiple times and changing IDs or class names? Currently, only the top male and female button works when clicked. I am looking for a CSS-only solution t ...

JavaScript code for submitting form input values

Recently, I encountered an issue on my PHP page where I handle password change requests. I am struggling to implement a Javascript function that checks if the new password contains at least one special character before proceeding to update the database fie ...

Send image data in base64 format to server using AJAX to save

My goal is to store a base64 image on a php server using the webcam-easy library (https://github.com/bensonruan/webcam-easy). I added a button to the index.html file of the demo: <button id="upload" onClick="postData()" style=" ...

Javascript code successfully executed using ajax

Using ajax, I have successfully implemented the 'addScript' function to add a js file to the loaded page. The following code snippet works perfectly: addScript('SlimBox/js/mootools.js'); However, I am encountering an issue when trying ...

Maintain the chosen option after submitting the form

I have a survey. One of the pages is designed like this: <form method="POST"> <input type="hidden" value="true" id="x" name="x"> <table> <b>How important were the topics for your current and/or future business?</b> ...

Exploring jQuery's ability to retrieve CSS values

Is there a way to use jQuery to read a specific CSS value from a class? The situation is as follows: HTML: <div class="box"></div> CSS: .box { margin-top: 100px; } I want to determine if the .box class has a margin-top of 100px in order t ...

How to create a thumbnail hover effect with CSS3 and javascript, overcoming the z-axis issue

Currently, I am working on creating a set of thumbnails that enlarge when hovered over. The initial setup achieves the zoom effect using CSS3 transform:scale and ease-in-out. However, the issue is that the enlarged images overlap each other due to sharing ...

jquery sequential fade effect

I am trying to make each div fade in one by one. Visit this link for reference <div id="w"> <div class="one"></div> <div class="two"></div> <div class="three"></div> </div> $(function() { $(&a ...

Double-click required to toggle button

Here is the code snippet for controlling an LED using a web page. The script, linked to Python, effectively controls the LED. However, there is an issue where the button toggles to the right side (ON position) only after a double click. Upon first click ...

When scrolling a semi-parallax effect in a resized window, I notice a calming presence of empty white

I recently acquired a WordPress website from its previous owner, and I'm encountering an issue with the parallax section at the top. It seems to be scrolling at a slightly slower pace than the rest of the page. I've tried adjusting the width and ...

Adjust the dimensions of the embed code to specify a width and height

Looking to integrate Appreplica on my website for embedding content, but struggling with the length of the embedded window. My Tweets seem to extend beyond the page boundaries. ...

Is it possible for a div nested within another div to still occupy space on the page despite being set

<html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $("select#choosebook").change(function(){ $(".title").slideDown(" ...