It is impossible to evenly divide a div into 6 equal parts

I am facing an issue with my code where it splits a div into six equal parts.

It seems to work fine on desktop browsers, but on Safari/Chrome on iOS, it doesn't display correctly.

You can check the code here

In my desktop browsers, each div has a height of 50px and fills the container perfectly. However, on mobile browsers, the height is only 49px for each div, leaving a space at the bottom of the wrapper as shown by a red line in the fiddle above.

Any thoughts on why this might be happening?

<div class="fretboardWrapper">
    <div class="strings">
        <div class="string" id="one"></div>
        <div class="string" id="two"></div>
        <div class="string" id="three"></div>
        <div class="string" id="four"></div>
        <div class="string" id="five"></div>
        <div class="string" id="six"></div>
    </div>
</div>

body{
    color:white;
}

#one, #three, #five {
    background:blue;
}
#two, #four, #six {
    background:green;
}
.strings {
    height:100%;
    width:100%;
    position:relative;
}
.string {
    z-index:2;
    height:16.666%;
}
.fretboardWrapper {
    position:relative;
    width:100%;
    height:300px;
    background-color:red;
}

<script>
$('#one').text($('#one').height());
$('#two').text($('#two').height());
$('#three').text($('#three').height());
$('#four').text($('#four').height());
$('#five').text($('#five').height());
$('#six').text($('#six').height());
</script>

EDIT

Interestingly, dividing into 5 works without any issues here

Could there be a limit to decimal places when using percentages in Safari mobile?

Answer №1

When I use my desktop browser, it's actually setting the height to 49px, not 50px like you mentioned.

All I had to do was change the height to height:16.999%; (which is about 50px each) and that fixed the problem for me.

Here is the updated fiddle.

Update: After testing in various browsers, Chrome sets it at 50px while Safari sets it at 49px. This difference might be due to how each browser rounds numbers. To ensure cross-browser compatibility, setting the height just slightly above 50px (for example, 16.69%) should work.

This fiddle now works perfectly for me on both Chrome and Safari.

Answer №2

Kindly make the necessary updates

.text {
    z-index:2;
    height:17%;
}

Appreciate your cooperation,

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

Updating a div's border using JavaScript

I recently generated a div element dynamically through code. var Element; Element = document.createElement('div'); My goal now is to modify the right and bottom borders to "#CCCCCC 1px solid". I aim to achieve this without relying on any exte ...

Dompdf is outputting the HTML Bootstrap code as col-sm-x instead of col-lg-x

Currently, I am utilizing Dompdf in my PHP project to generate PDF reports. However, I have encountered an issue where the HTML bootstrap code does not render as expected on the PDF document. Specifically, when viewing the grid on a smaller device, it coll ...

Making sure that the div elements are stacked vertically once the top div expands in size

I am dealing with a situation where I have two divs that showcase a list of elements for the user to interact with via a search bar. This is followed by a "Done" button to finalize their selection. <div class="dropdown col" id="dropdown-s ...

What are some ways to utilize my mouse to launch projectiles at various locations?

Is there a way to make my projectile shoot using my mouse instead of clicking buttons? I want it to be able to shoot at any position x,y without having to click multiple buttons. # Updated projectile class if keys[pygame.K_f]: for bullet ...

What are the best ways to utilize dynamic CSS on a smartphone browser for optimal performance?

Struggling to optimize my web application for mobile devices, I've encountered challenges with consistent display across different browsers. My idea is to utilize device capability detection to adjust widths and font sizes dynamically based on screen ...

Getting tags with text containing specific substring by utilizing CSS selectors

Here is the HTML snippet I am working with: <tr bgcolor="#DEDEDE"> <td> <b>OK:Have idea</b> </td> <td> <b>KO:Write code</b> </td> <td> <b>KO:Ru ...

remain on the multi drop down page for a specified duration

I have created a dropdown menu with a second level drop-down page that is a form. Now, I want the second level drop-down page to stay open longer, so I have used the following JavaScript code: <script> var timer; $(".parent").on("mouseover", functio ...

Retrieve the website address from a string of HTML code

I'm struggling to extract the URL from a given String that contains an HTTP response with an HREF tag. I've managed to identify the start of the links, but I need to stop the string as soon as the HREF tag ends. How can I accomplish this? public ...

What is the best way to position an image next to an input element?

How can I position submit.png next to the input element in my code? <div class="input-box" style="height: 40px; width: 500px;"> <img src="img/delete.png" width="25px" height="25px;" style="position: absolute; right: 0;"> ...

Collect data from website submissions via email

Is it possible to receive the results via email when someone submits their details on my site using a script? My server does not allow .php or .asp files, only .css. How can I achieve this? ...

I'm having trouble with the pull-right feature in Bootstrap -

I am having trouble with the bootstrap class pull-right. Despite applying it, my span is still floating to the left. I am unsure why the pull-right class is not functioning as expected. <!DOCTYPE html> <html lang="cs"> <head> <me ...

Creating sibling classes with tailwind using the map function

Currently, I am combining tailwind, react, and nextjs to develop a website. My goal is to implement the check radio button technique to dynamically display different content on the website without relying on JavaScript. To streamline data management, I am ...

What could be causing my divs to not properly handle overflow with the overflow-y scroll property?

I'm struggling with making my sidebar and content area responsive in terms of height. I want them to adjust to fill the screen appropriately, rather than having a fixed height. The issue arises when I have varying content heights, such as when a page ...

What is the best way to interpret a line break within a string variable in TypeScript?

Realtime Data base contains data with \n to indicate a new paragraph. However, when this data is retrieved and stored in a String variable, the website fails to interpret the \n as a paragraph break: https://i.stack.imgur.com/tKcjf.png This is ...

How can JavaScript be used to display the related value in another drop down list when a user selects an option in one drop down list?

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="Practical_5.View.Registration" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta charset ...

What is the best way to showcase specific rows with Vue.js?

After fetching data from a specific URL, I am looking to display only the 2nd and 4th rows. { "status": "ok", "source": "n", "sortBy": "top", "articles": [ { "author": "Bradford ", "title": "friends.", ...

Guide to obtaining the root directory in order to send AJAX requests to a server

I am currently working on a small Node.js project where the client side will be making multiple AJAX requests to the server. I want the code to be able to work with any webpage, but I realized that the path is relative to the page's location. How can ...

How to retrieve the button value in HTML

One of the HTML components I am working with is a button that looks like this: <button>Add to cart</button> My goal is to retrieve the text within the button, which in this case is "Add to cart." To achieve this, I need to extract this value ...

Please refrain from refreshing the page multiple times in order to receive updated data from the database

Currently, I have created a countdown timer from 00:60 to 00:00. However, once the timer reaches 00:00, I am looking to refresh the page only once in order to retrieve a new value from the database. Does anyone have any suggestions on how to achieve this ...

What is the best way to place an icon in the lower right corner of a design

I have encountered an issue while building the testimonial section below. The problem arises when the amount of text in each block is not the same, causing the quote icon to be displayed improperly in the bottom right corner. Sometimes, it even extends out ...