When the child div reaches a width of 2%, it overlaps with the rounded container, adding a unique touch to

I have a long rectangular container with rounded corners.

Inside the container, there are 3 child divs.

Here is an image demonstrating the setup:

In the illustration above, the first child container (white) and the third one (red) also have rounded corners to match the main container.

The width of the child containers can be adjusted by the user. This means that users have the flexibility to change the widths of all three child containers according to their requirements.

However, when I set the width of the third container to 2%, an issue arises:

The same problem occurs when I do this with the first child container—it overlaps the rounded borders of the main container.

Child container 1 (white) is aligned left while child container 3 (red) is floated right.

I am looking for a solution to prevent this overlapping from occurring.

If needed, I can utilize JS and JQuery for this task.

EDIT: CSS:

.parent {
    border: 1px solid #5B5B5B;
    height: 30px;
    width: 80%;
    right: 0%;
    position: relative;
    margin-right: auto;
    margin-left: auto;
    <? set_radius("25px",true);
    set_box_shadow("1px","1px","#F8F8F8");?>    
    overflow: hidden;
    z-index: 3;
}
    .child_class {
        display: inline-block;
        position: relative;
        width: auto;
        height: 100%;
        margin: 0px;
        border-right-width: 1px;
        border-right-style: solid;
        border-right-color: #5C5C5C;
        box-sizing: border-box;
    }

    #child1 {
        width: 33.33;
        background-repeat: repeat-x;
        background-position: center center;
        <? set_radius("25px",false,false,true,false,true);?>
        float: left;
        background-color: #fff;
    }
    #child2 {
        width: 33.33;
        background-repeat: repeat-x;
        background-position: center center;
        background-color: #0CF;
    }

    #child3 {
        <? set_radius("25px",false,true,false,true,false);?>
        background-repeat: repeat-x;
        background-position: center center;
        width: 33.33;
        float: right;
        background-color: #F00;
    }

HTML:

<div class="parent">
          <div class="child_calss" id="child1"></div><div class="child_calss" id="child2"></div><div class="child_calss" id="child3"></div></div>

Answer №1

If you include this in your CSS:

parent{
    overflow: hidden;
}

You won't have to worry about matching the border-radius on the children anymore.

Modification

I've set up a demonstration on this jsfiddle:

  1. No need for border-radius on the children
  2. overflow: hidden rounds the children when they overlap
  3. Excess background- properties on the children are eliminated
  4. Consistent performance at lower percentages

Update

A quick note on this: If you expect CSS/HTML to handle logic (like preventing the last element from dropping out of the bar), there might be confusion regarding the purpose of CSS and HTML.

I have revised the jsfiddle to offer a solution to this issue. The third child is absolutely positioned at the far right to ensure it remains within the bar.

Update

Lastly, view this bug report in Webkit which does not properly clip the background. Currently, there may not be much that can be done except something along these lines:

<div class="hasBorder hasBorderRadius">
    <div class="hasBorderRadius hasHiddenOverflow">
        <div class="containsContent">
        </div>
    </div>
</div>

Answer №2

Perhaps consider assigning a z-index to ensure a stack order for the elements. Additionally, have you thought about using overflow hidden on the parent container?

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 numerous objects in Node.js using Mongoose populate

My current task involves creating an array of dishes that a logged-in user has selected as their favorite. However, I am facing an issue where instead of having one array of objectIDs for the dishes (e.g. dishes:[123456,5678910]), I am getting two separate ...

What is the best method for positioning 2 buttons at the bottom of a card using Bootstrap?

I need help with adjusting the position of two buttons in my bootstrap design. I would like both buttons to be located at the bottom of the card and have a slight gap between them, perhaps around 5 pixels. Below is the snippet of code: <div class=" ...

The parseFloat function only considers numbers before the decimal point and disregards

I need my function to properly format a number or string into a decimal number with X amount of digits after the decimal point. The issue I'm facing is that when I pass 3.0004 to my function, it returns 3. After reviewing the documentation, I realized ...

Attempting to simultaneously start my node.js server and React .js app, resulting in the error message 'ERR_MODULE_NOT_FOUND'

Currently facing issues while setting up a server for an ecommerce site being built in React. Attempting to run both the React app and the server simultaneously using npm run dev, but encountering various errors that persist even after attempted fixes foun ...

Show the tabulated outcomes of entries in a MySQL database and present them using ChartJs

My goal is to show the total number of rows stored in a MySQL Database and present these numbers using ChartJs. However, I am encountering issues with displaying the values correctly when retrieving data from my PHP Script. PHP Code Snippet for Counting R ...

Tips for aligning an HTML button with a hyperlink

<form method="get" action=https://www.wwf.de/spenden-helfen/allgemeine-spende> <button type="submit">Donate Now</button> I am facing an issue where the button is appearing randomly on my website, but I need it to ...

Notifying the ajax response

I've been struggling to retrieve and read the ajax response in codeigniter. I have tried multiple methods like stringify and console.log, but so far without success. The following is the controller function where the ajax request is sent: function f ...

Implementing AJAX to populate a dropdown list: A step-by-step guide

I have a question about populating options in a select dropdown using AJAX. Can you spot any errors in my code? Below is the snippet from my View: $(function() { $.getJSON("Animes/GetCategories", null, function(data) { var options = '&a ...

When I hit pause on the main window, the countdown timer on another window will also update

I am working on a project that involves two windows - one with an admin panel to control the countdown timer and another window where the user can see the timer. I want the changes made in the admin panel, like pausing or adjusting the time, to reflect in ...

What is the method for identifying the points where two faces of two bufferGeometryBox objects intersect?

I am currently working on a 3D configurator project. In this project, a cube is initially displayed on the scene. When a side of the cube is clicked, a rectangle is supposed to appear. However, the issue I am facing is that upon clicking the same side of t ...

Ways to automatically scroll the page to the top when new content is loaded on a Single Page Application

I've recently integrated the Single Page Application Plugin in my website built with octoberCMS and also included smooth-scrollbar.js. While most things are working smoothly, there's one issue I'm facing - smooth-scrollbar doesn't auto ...

Vue.js fails to properly display mustache expressions

My vue.js code doesn't seem to be making any changes on my website. How can I resolve this issue? const selector = new Vue({ el: '#example', data: { question: 'How did the event go?', selectorValue: '', b ...

Troubulation with AngularJS: Why aren't my directives loading?

After working on my webpage Danieboy.github.io for some time, I took a 2-month break and returned to optimize it with the assistance of Dareboost. Making small changes like optimizing images and switching raw.github.com to rawgit.com, I thought everything ...

Navbar alignment issue: justify-content-between not functioning properly

The justify-content-between property is not functioning as expected for the navbar. I need the navigation list to expand and cover the entire space with equal spacing between the items. <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-boots ...

Leveraging the power of HTML validation while silencing the constant flood of messages

I want to keep the HTML validation in place but disable only the error message that prompts users to fill out required fields. Users should still not be able to submit the form without filling in a text field, but I don't want the standard "Please fil ...

Responsive header for filtering columns in a jQuery DataTable

I have attempted to implement Bootstrap jQuery data table column filter in the header http://jsfiddle.net/80umxrxe/122/ The design of the 2nd row column filter in the thead is not functioning properly in a responsive window. I aim to conceal it similar t ...

Angular 2 module that is loaded lazily - service does not follow singleton pattern

After successfully implementing lazy loading modules into my application, I have ensured that the app.module.ts is properly configured. @NgModule({ declarations: [ AppComponent, HeaderComponent, HomeComponent ], imports: [ BrowserMod ...

Is there a way to enable text selection on a jQuery draggable div?

I utilized jQuery to make a specific div draggable, but I've encountered an issue. Inside this draggable box, there is some important text that I need to be able to copy and paste. However, whenever I click on the box, it triggers the dragging action ...

URL not passing on variable

Here is the code I have for a basic 'change email' script. I'm currently struggling to get it working and can't figure out what's wrong. <?php if (isset($_GET['u'])) { $u = $_GET['u']; } if (isset($_POS ...

Angular static dropdown option

<input [formControl]="twitterHandle" id="twitterHandle" placeholder="twitterHandle"> Fetching the input value from the Twitter handle input field using the following code: twitterHandle = new FormControl(); this.twitterHandle.value; Similarly, if ...