Webkit browsers do not properly clip content with rounded corners when using position:relative

In webkit browsers like Chrome, rounded corners do not properly cut off content when using position:relative;

Check out this demonstration.

Here is the HTML:

<div class="outer">
    <div class="inner">
    </div>
<div>

And here is the CSS:

.outer {
    background:yellow;
  border:solid 1px black;
    position:relative;/* When set, rounded corners fail to contain content */
    overflow:hidden;

   -moz-border-radius: 12px;
    border-radius: 12px;   
}
.inner {
    background:red;
    height:50px;
}

If anyone knows of a solution, please share. Thank you!

Answer №1

span.outer{
    position:relative;
}

div.outer {
    background:yellow;
    border:solid 1px black;    
    overflow:hidden;    
    -moz-border-radius: 12px;
    border-radius: 12px;   
}

.inner {
    background:red;
    height:50px;
}
<span class="outer">
    <div class="outer">
        <div class="inner">
        </div>
    </div>
</span>

Original JSFiddle: http://jsfiddle.net/USd5s/

I dislike adding extra DOM elements, but a simple wrapper can easily solve this issue. Feel free to use any element or CSS approach of your preference, I personally like using span and specific CSS styling. Alternatively, a div with class="wrap" would also work effectively.

Answer №2

If you want to make it appear in three dimensions, you can use the following code:

-webkit-transform: translateZ(0);   
-moz-transform: translateZ(0);   
transform: translateZ(0);    

Answer №3

To achieve the desired effect, ensure that the inner border radius matches that of the outer border.

.inner {
    -moz-border-radius: inherit;
    -webkit-border-radius: inherit;
    border-radius: inherit;
}

Also, remember to cater to the webkit users as well! :]

Answer №4

In a recent project, I encountered a similar issue that I was able to resolve with a simple adjustment to the CSS code.

Instead of specifying position as relative, I changed it to inherit:

.box {
    background: yellow;
    border: solid 1px black;
    position: inherit;
    overflow: hidden;
    border-radius: 12px;   
}

By making this change, the problem was resolved efficiently and effectively.

Answer №5

If you want to make the inner div look more appealing, you can apply the same border-radius as the outer div: https://example.com

<div class="outer">
    <div class="inner">
    </div>
<div>

<style type="text/css>
.outer {
    background:blue;
    border:dashed 1px gray;
    position:absolute;/* This will prevent content from being obscured by rounded corners */
    overflow:hidden;

    -webkit-border-radius: 15px;
    border-radius: 15px;   
}
.inner {
    background:green;
    height:60px;
    -webkit-border-radius: 15px;
    border-radius: 15px;   
}
</style>

Answer №6

From what I recall, there was a suggestion to attach the container to another object in order to address this issue. While I can't say for certain, that could be worth considering.

Answer №7

Paul mentioned a glitch in webkit, but don't worry - there's a workaround by adjusting margins on the inner div.

Answer №8

To achieve the desired effect for .inner, consider using the following CSS:

.inner {
    background: blue;
    height: 60px;
    position: absolute;
    top: 3px;
    left: 15px;
    right: 15px;
    bottom: 3px;
}

Adjust the values of bottom and top to ensure the correct height is achieved. Without modifications, the class would only be one pixel in height. This approach will effectively set the margins at the border radius, preventing anything from touching the edges.

Another option is to create an image with transparent space inside (as shown in the checkered area), surrounded by a solid color matching the background around .outer. Use border images or absolute positioning to place it in the corners, setting a high z-index. As you scroll, the filled part of the corner will conceal any content underneath.

Answer №9

Check out this link for the solution to your issue.

#wrapper {
    margin-top:250px;
    width: 300px; 
    height: 300px;
    border-radius: 100px;
    overflow: hidden;
    position: absolute; /* this breaks the overflow:hidden in Chrome/Opera */
    -webkit-mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC); /* this fixes the overflow:hidden in Chrome/Opera */
}

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

Customize Appearance: Overlay Images with Display Properties

I have created a unique slideshow that overlays multiple images using JavaScript to change their opacity and attributes. You can view the slideshow here: Upon inspection (using firebug), I noticed an issue with how the images are displayed. When the displ ...

Can a stroke in an SVG image be created using a gradient color?

Is it possible to create a gradient in the stroke color of these two lines, currently set to #389967, within this SVG? .chart-three svg .circle-foreground { stroke: #389967; stroke-dasharray: 494.55px 549.5px; stroke-dashoffset: 494.55px; stroke- ...

Ways to prevent styles from being overridden by those specified in JavaScript

Some elements on my page have their style dynamically changed by JavaScript. However, I want one of them to maintain its static style without being overridden. Is there a way to specify that the style of this particular element should not be altered? Than ...

What could be causing the flexbox code to not take effect and the text to refuse wrapping?

I've been utilizing flexbox to style my content, and it worked seamlessly on the first three divs. However, when I attempted to apply the same styling to the fourth one, it didn't quite work out as planned. Despite trying options like flex-wrap t ...

Is <form> tag causing code deletion after an ajax request?

I'm working on a form that looks like this: <form> <input class="form-control" id="searchField" type="text"> <button type="submit" id="searchUserButton">SEARCH BUTTON</button> </form> When I click on SEARCH BUT ...

Leveraging Flexbox and flexGrow in conjunction with Textfield

I am looking to use Flexbox to separate my components on the screen in a way that positions them correctly. I have 3 rows with textfields that need specific ratios related to the full width: row 1 : 2, 1, 1 row 2 : 1, 1 row 3 : 1, 1, 2 I attempted to ach ...

Ensuring the accuracy of checkboxes in a loop through verification

How can I ensure that at least one checkbox is selected before allowing the user to move on to the next page using JavaScript with a form structure like this? echo "<form method=\"POST\" action=\"confirm.php\">"; $query = mysqli_ ...

Creating a CSS template for organizing sidebar and footer divisions on a webpage

I am facing an issue with the layout of my website. I have a container that is positioned relatively and houses various divs for header, sidebar, main-content, and footer. The problem lies with the sidebar and footer components. The sidebar has been posit ...

Adding classes to a div in a sequential animation using jQuery: A step-by-step guide

I'm aiming to create an animated effect using jQuery that replicates the motion in this GIF. I experimented with CSS3 animation keyframes, but the result was not as clean and polished as I would like. If there is a simpler way to achieve this effect u ...

Integrating a Find Pano functionality into a Kolor Panotour

I used a program called Kolor to create a panorama. Now, I am attempting to integrate the "find pano" feature, which involves searching through the panoramic images for display purposes. I have come across an HTML file that contains the search functionalit ...

dynamic text overlay on a bootstrap carousel

Having limited knowledge in html and css, I am using a bootstrap carousel slider with text. I am trying to change the color of the box randomly. https://i.sstatic.net/TozUP.jpg Here is the code that I am currently using: <ol class="carousel-indicato ...

Is there a way to toggle the visibility of the angular material toolbar at regular intervals?

I'm currently experimenting with the CSS animation feature to display and conceal the angular material toolbar in this demonstration. Inside the application component, the hide attribute is toggled at intervals as shown below: hide:boolean = false ...

Saving the name and corresponding value of a selected option element into separate fields using Angular framework

I have implemented the following code to generate a select field. The ngModel is successfully updating the value, but I am also looking to capture the name of the selected option and store it in a different field. Is there a solution to achieve this? ( & ...

having difficulty adjusting the background color of a div that is positioned absolutely

Hey there! I am new to the world of html/css and working on my very first webpage. I'm facing an issue with setting the background color for a div with the class inner. Currently, it is displaying the background color set in the banner-bottom class. ...

discovering the category for the .click function

After retrieving a list of book objects from a JSON object, I am in the process of displaying them on an HTML page by creating buttons with titles. The goal is to alert the URL of the book when a button is clicked. However, I am facing an issue with access ...

Obtain textNames and colorNames data from a locally stored nested JSON file

I am currently working with a data.json file to fetch and display data in my HTML. Here is the code snippet of my Component: tooltip: any; tooltipColor: any; ngOnInit() { this.DataFactory.getLimitedData(this.widgetData).subscribe(data => { this ...

Tips on preventing the constant shifting of my webpage div elements when resizing the browser

Whenever I resize my webpage browser, the 3 text input boxes move and overlap, causing the page layout to become messy. View of The Browser in full screen (normal) View of The Browser when it's smaller (not normal) As a beginner programmer, I have ...

Displaying the Indian Rupee symbol in PHP

I'm attempting to show the Indian rupee symbol using HTML code ₹ The HTML code is being echoed in PHP and everything seems to be working fine, except that the rupee symbol is not showing up. I've tested using other currency symbols and the ...

Issue with Flask form submission in a specific scenario but functioning correctly in a different context

I'm currently working on a flask website, and I'm facing an issue with the SubmitField not functioning when I click it. I tried a similar method with a smaller form and it worked, but for this specific case, it's not working. routes.py from ...

Conquering Bootstrap 3's Image Gallery Customizations

I am currently working with Bootstrap 3 RC1 and struggling to set up the image gallery properly. Issue 1 - The ul is adding unnecessary padding-left or margin-left. What do I need to do to eliminate this? Issue 2 - Each li is extending across the contain ...