Unique styling tricks for div widths in Chrome

I have created a navigation section with dropdown buttons. I want the width of the divs to adjust based on the text length. In Firefox, everything looks good and works as expected.

However, when I checked the site in Chrome, the navigation section behaved differently. The text was breaking up and the div widths were incorrect. What's strange is that when I hover over the buttons, the div widths start to adjust correctly.

Is this an issue specific to Chrome, or do I need to modify my code differently?

I am using normalize.css in my parent CSS file.

You can view the website here:

HTML:

<nav>
  <ul>
       <li><a class="selected" href="index.html">Home</a></li>
       <li><a href="#">Our services</a>
          <ul>
            <li><a href="painting.html">Painting</a></li>
            <li><a href="total-works.html">Total Works</a></li>
            <li><a href="other.html">Other Works</a></li>
          </ul>
        </li>
        <li><a href="#">About Us</a></li>
        <li><a href="#">Contact</a></li>
   </ul>
</nav>

CSS:

nav{
    float:right;    
    padding-top:68px;
}

nav ul{
    position: relative;
    display: inline-table;
    width:100%;
}

nav ul:after {
        content: ""; clear: both; display: block;
}


nav li{
    float:left;
    list-style-type:none;
    margin-right:2%;
}

nav ul li a{
    display:block;
    width:auto;
    min-width:75px;
    text-align:center;
    background-color:#E9E9E9;
    color:#555555;
    padding:7px 13% 10px;
    border-radius:50px;
    font-family:"Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
    font-size:16px;
    text-decoration:none;
}

nav li a:hover, .selected{
    background-color:#838383;
    color:white;
    text-decoration:none;
}

nav ul ul {
    display: none;
    border-radius: 0px; 
    padding: 0;
    position: absolute; 
    top: 35px;
    width:auto;
    margin-left:0%;
}

nav ul li:hover > ul {
    display: block;
}

nav ul ul li {
    float: none; 
    position: relative;
}
nav ul ul li a {
    color:#555555;
    background-color:#E9E9E9;
    margin-top:3px;
    width:auto;
}   
nav ul ul li a:hover {
    background: #838383;
    color:white;
    text-decoration:none;
}

Answer №1

When using Google Chrome, the following solution is effective:

Check out this jsfiddle example

The issue seems to be caused by the padding in the nav ul li a{ CSS rule.

Answer №2

Just like the previous answer mentioned, the culprit here seems to be the 13% padding in this code snippet:

nav ul li a{
    display:block;
    width:auto;
    min-width:75px;
    text-align:center;
    background-color:#E9E9E9;
    color:#555555;
    padding:7px 13% 10px;
    border-radius:50px;
    font-family:"Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
    font-size:16px;
    text-decoration:none;
}

To resolve the issue, consider changing the percentage value to a fixed pixel value and everything should work smoothly. Keep coding!

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

Creating content in HTML that features two div elements centered vertically on a page, with one div aligned to the left and the other aligned to the right

Implementing Bootstrap for styling my HTML page has resulted in the following layout: https://i.sstatic.net/wzsnc.png Currently, both words are positioned at the top of the screen. However, I aim to have them vertically centered. Additionally, they are c ...

Is there a way to display tiff files in Google Chrome?

I've been struggling with this problem for over 48 hours now, tirelessly searching for a solution. The issue lies within an application built using the ext.net framework on the front end. Specifically, I'm encountering difficulties when it comes ...

JavaScript updates the cursor after the completion of the JS function

Here is some code that I have been working with: <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> </head> <body style="background-color:yellow;width ...

Achieving vertical alignment of form controls with labels that wrap in a row using Bootstrap 4

I am facing an issue where input elements in a row with labels above them are causing alignment problems when the screen width is reduced. The longer labels wrap to the next line and push the input element down, increasing the overall height of the row: h ...

Attempting to execute code on a database using PHP and MySQL

Hey there! I am just diving into the world of HTML and PHP, attempting to create a page that can execute an SQL query to transfer data from one table to another. However, I'm facing some difficulties in making it work as I need a user-provided date t ...

What is the best way to organize a complicated array in Javascript?

Struggling with this question for quite some time. I have a nested list with the following structure: Volume1 Chapter4 Chapter3 Section3-6 Section3-1 Volume2... ... I am looking to create a sorting function to organize volumes, ch ...

An illustration of HTML frames

Is this method effective? <html> <body> <center> <frameset rows="50%,50%"> <frame src="images.html"> <frameset> <form action="abc.html"> <input type="submit" name="abc page" value="abc page"> </form> & ...

Steps to make the placeholder in an MUI TextField component move to the top of the box instead of staying within the border:

I'm working on styling a text field in MUI to achieve the look shown in the image below: https://i.sstatic.net/JHhpf.png However, my current implementation looks like this: https://i.sstatic.net/5N7hH.png Currently, when I click inside the text fi ...

CSS image replacement; won't render properly

I'm currently working on implementing a hover image swap effect for my website gallery. The CSS code I have so far is below. While the original images in my HTML file are displaying correctly, the hover functionality is not working as expected. CSS: ...

Creating a seamless video texture loop using PixiJS

I have successfully loaded a video texture and rendered it using pixi. // initialize a new pixi stage var stage = new PIXI.Stage(0x66FF99); // create a renderer instance var renderer = PIXI.autoDetectRenderer(window.innerWidth, window.inner ...

What is the best way to align elements within a row/column layout in Angular Material when working with divs?

To set up two div blocks in a row, I'm utilizing the code below: <div layout="column" layout-gt-xs="row" layout-align="center center" id="row"> <div id="a">a</div> <div id="b">b</div> </div> The CSS for this ...

The overflow:hidden property does not completely conceal the parent div when it has a border-radius applied

I've noticed some residual overflow in my simple layout that becomes quite apparent when setting a border radius. The expected behavior is for the white div class='inner' to fully cover the red div class='outer'. However, there see ...

Tips for handling a JSON payload retrieved through a POST request

I'm currently working on a button that triggers a POST call to retrieve a json response from the server. My goal is to display this json response in a new (chrome) browser tab. Here's what I have so far using Angular: $http.post(url, data) .t ...

Creating an interactive R Shiny application with custom CSS styling and a modal

I am encountering an issue when trying to incorporate a modal dialog with a specific CSS style within a R Shiny app. Individually, I can successfully implement a modal dialog without the CSS style and apply the CSS style without any issues. However, when a ...

Is there a Page Views tracker in sinatra?

Help needed with implementing a page views counter using Sinatra and Ruby. I attempted using the @@ variables, but they keep resetting to zero every time the page is reloaded... Here's an example: Appreciate any advice! ...

What is the best way to add a square bracket into an HTML list item?

My goal is to incorporate square brackets, a semicolon, and parentheses into an HTML list: <li>Carrie "...always miss[es] the ball, even in kickball, fall[s] on her face in Modern Dance... run[s] into the net during volleyball; wear[s] stockings ...

Using form.submit() alongside preventDefault() will not yield the desired outcome

My login form needs to either close the lightbox or update the error box based on the success of the login attempt. I suspect the issue lies with the onclick="formhash(this.form, this.form.password);" which is a JavaScript function that hashes a passwor ...

Is there a faster method for adding and removing classes on a table?

I have a sizeable table containing 27 columns and anywhere from 5 to 100 rows. To switch between a simple view showing the first 5 columns and an expert view showing all 27 columns, I have implemented a mode switch (checkbox). Currently, I am using the fo ...

activating the web element located using Selenium in Java

What is the best way to click on a webelement based on the data-key in the class _3d5d? Specifically, if a user inputs the value 2002, an error message should inform the user "no such year, please enter again" and allow for a re-entry of the value. If the ...

Disabling buttons in a Fiori UI5 application using HTML: A step-by-step guide

I don't have much experience with scripting languages. I am attempting to hide buttons within a SAP Fiori app by using the "Inspect element" tool in the Mozilla browser. When I delete the HTML code, the button disappears, but I would like to accomplis ...