I am getting some residual overflow from my simple layout below. Though minimal, the effect is quite obvious and happens only where I set a border radius. The expected behavior is to have the div class='inner', the white, fully cover div class='outer', the red. However there clearly seems to be residual overflows from both ends of the div.
Example:
.outer {
background-color: red;
width: 500px;
height: 50px;
position: relative;
overflow: hidden;
border-radius: 5rem;
}
.inner {
background: white;
width: 100%;
height: 100%;
position: absolute;
}
<div class="outer">
<div class="inner"></div>
</div>
I am using this as part of a loading bar effect where inner translates as part of an animation during a media play. I have read a couple other problems that involve adding properties like z-index and adding masks but does not work for me. Also read issues with webkit, but have not found anything that works in the case above.
Edit
For clearer illustration refer below:-
Overflow hidden is being used so that when inner translates, any overflow is hidden out of the parent div. I am unsure if there are any other ways I can use. Below is an example of having the x-axis translate at 10%. I am trying to achieve the overflow effect without any bleeding from the edges around where border radius is applied.
Translate starts at 0% which is the same as the example above.
This issue was also reported - Issue 491574: border-radius bleeds background-color
And similar to the question - CSS border radius background colour bleed but the use case of overflow does not apply to my case.
.outer {
background-color: red;
width: 500px;
height: 50px;
position: relative;
border-radius: 5rem;
overflow: hidden;
}
.inner {
background: white;
width: 100%;
height: 100%;
position: absolute;
transform: translateX(10%);
}
<div class="outer">
<div class="inner"></div>
</div>
The code above though not in exact flavor is embedded in an app written in ReactJS and I am facing this issue both in Chrome and Mozilla.
The answer I suggested as a duplicate mentions:
The fix would be on a case by case basis... it would be matter of rearranging the elements such that they are a top and bottom rather than a parent and child.
So here is your case fix. You have to have the background red color into a child of the container element... And the progressbar on top of it. Now that the container doesn't have any background color, nothing can bleed due to the anti-aliasing.
Additionnally, if you apply the same border-radius to the "background" div... And a 1px white border... The magic is made.
Below, I animated the width of the .progress-bar on an interval to simulate you react state based animation.
// Simulating an animation... Just for this demo.
let outer = document.querySelector(".outer")
let progress = document.querySelector(".progress-bar")
let outerWidth = outer.getBoundingClientRect().width
let progressWidth = progress.getBoundingClientRect().width
let interval = setInterval(function(){
progressWidth = progress.getBoundingClientRect().width
progress.style.width = progressWidth + 10 + "px"
if(progressWidth > outerWidth) clearInterval(interval)
},500)
.outer {
background-color: transparent;
width: 500px;
height: 50px;
position: relative;
border-radius: 5rem;
overflow: hidden;
}
.progress-background {
background: red;
width: calc(100% - 2px); /* to compensate the white border space */
height: calc(100% - 2px); /* to compensate the white border space */
position: absolute;
border-radius: 5rem; /* Same radius than the container */
border: 1px solid white; /* white border */
}
.progress-bar {
background: white;
width: 0;
height: 100%;
position: absolute;
transition: width 1s; /* Just to have the animation a bit smooter */
}
<div class="outer">
<div class="progress-background"></div>
<div class="progress-bar"></div>
</div>
Related
I'm having issues with an overlay div that is not fully covering the div under it. I have to say that on desktop view, this works fine and there is no bleed showing through.
This issue I was experiencing is only happening when I view the results on a tablet or a tablet simulation in my browser. The images or div behind is bleeding through by a very fine 0.5 or 1px.
I have tried pretty much everything and am not getting anywhere.
To make sure it wasn't something from the rest of the site I have set up a blank html file with two divs to mimic the exact same problem and it has resulted in the same result so I give up!
So this is a div 500px x 500px with a black background. (position: relative).
I've then set a white div with absolute position over it with width and height set to 100% and enough z-index for it to appear in front of it.
As you can see there is a thin line of the underlying black div showing through around the edge.
Can anyone shed any light on what could be causing this?
Here is a link to the dummy page:
https://dev.gecko.media/test.html
If you open the link with the inspector too and change the background colour of the background div to red you can see it changes so this indicated it is not a border.
<div class="background">
<div class="overlay"></div>
</div>
.background {
width: 500px;
height: 500px;
background: black;
position: relative;
}
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99;
background: white;
}
Edit
This doesn't seem like the most elegant way of fixing this issue but it works:
.overlay {
position: absolute;
top: 0;
left: 0;
width: calc(100% + 2px);
height: calc(100% + 2px);
z-index: 1;
background: white;
margin-top: -1px ! important;
margin-left: -1px ! important;
}
Hello You just need to add one line css for parent div of overlay like...
.background {
width: 500px;
height: 500px;
background: black;
position: relative;
backface-visibility: hidden;
}
This question already has answers here:
Can I create a div with a Curved bottom?
(5 answers)
Closed 1 year ago.
I am trying to make a half circle on the screen over which I can put buttons and other things just like AdminBro top blue color circle but a little bit smaller. I did it like this:
.navbar {
position: relative;
overflow: hidden;
}
.eclipse {
position: absolute;
width: 200vw;
height: 200vw;
left: -50vw;
top: -180vw;
background-color: #41B3A3;
border-radius: 100vw;
}
<div id="root">
<div class="navbar">
<div class="eclipse"></div>
</div>
</div>
As you can see this is a react application. The thing is I am not getting the desired result please tell me why?
There's an easier way to this. You can simply use clip-path property of CSS.
Create a div element with a background color below body tag and give it an absolute position and full width and height. Then use clip-path to create a create clipping path.
HTML
<div class="ellipse"></div>
CSS
.div {
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background: cyan;
clip-path: ellipse(80% 50% at 50% 5%);
}
You can play around with the values. Also this clip-path generator is a useful tool.
I am not quite sure if I understand your question, but if you just want to make a half circle, try this:
.half-circle {
width: 200px;
height: 100px; /* needs to be half of the width */
border: 10px solid black;
border-bottom: none;
background: green;
border-radius: 110px 110px 0 0;
}
Note, how the border-radius is 100px (height) + border-width (10px). If you don't need a border the border-radius of the top two corners is just equal to your height.
How can I extend background color outside div?
My code:
.content-right{
background-color: blue;
padding: 40px;
position: relative;
}
.content-right:after{
position: absolute;
top: 0;
right: calc(1px - 100%);
width: 100%;
height: 100%;
background-color: red;
content: "";
}
jsfiddle
The problem is that I'm getting scroll (horizontal) and I don't want that... What I want is that red part to be extended after that black so it reaches the edge of the screen on any resolution but without scrolling... If I add overflow: hidden, it doesn't solve the problem.
Any ideas?
Thanks.
Move the pseudo to the left, and make the width of this 1000px.
Set a shadow on it to the right, with 1000px offset, and color red
.main{
background-color: #000;
height: 500px;
}
.content-right{
background-color: blue;
padding: 10px;
position: relative;
height: 100px;
}
.content-right:after{
position: absolute;
top: 0;
right: 0px;
width: 1000px;
height: 100%;
background-color: transparent;
box-shadow: 1000px 0px red;
content: "";
z-index: -1;
}
fiddle
Note: now the pseudo element will be probably outside of bounds, but to the left. Elements going outside of bounds to the left or upper side do not generate scrollbars.
On the other side, the shadow extends to the right. But the shadow is not taking into account when computing the layout, so this won't generate scrollbars either.
Quick Fix, but essentially I made the document have a overflow-x value of hidden so it will NEVER produce a horizontal scroll bar. If this is a problem, I can try to think of a better solution, but this is what I have so far.
JSFiddle: https://jsfiddle.net/m4f4x3bt/3/
html, body{
overflow-x: hidden;
}
I'm attempting to build a progress bar, fairly simple. I have a bar nested inside a tray. The tray has overflow: hidden and border-radius set on it.
Here's the jsFiddle demonstrating the problem.
As you can see in the image, there is a jagged artifact on the left side of the progress bar. It appears the anti-aliased edge of the parent progress bar (dark background) is bleeding out. The desired behavior is that the bar/fill element is used for anti-aliasing the progress bar.
A brief solution I tried was absolutely positioning the inner div, but the progress bar needs to be able to animate from 0 to 1%, and that looks off without the overflow: hidden clipping.
I see this artifact both Chrome and Firefox so I don't immediately suspect it's a bug in Webkit.
I would also note this bug also affects Bootstrap's progress bars, but when the tray is a light color and the background is a light color, the artifact is much harder to spot.
Adding an extra wrapper helps mitigate your issues with 0 & 1%:
http://jsfiddle.net/p197qfcj/11/
HTML
<div class="outer-tray">
<div class="tray">
<div class="fill"></div>
</div>
</div>
CSS
body {
background: #ccc;
}
.tray {
/* overflow: hidden; */
height: 20px;
background: #000;
border-radius: 50px;
height: 30px;
width: 100%;
border: none solid transparent;
background-color: black;
}
.fill {
background: #fff;
width: 10%;
border-radius: 100px;
left: -1px;
position: relative;
float: left;
box-sizing: border-box;
border: 1px solid white;
top: -1px;
height: 32px;
}
.outer-tray {
overflow: hidden;
border-radius: 100px;
overflow: hidden;
display: block;
}
EDIT:
The only way I can think of is if you removed the overflow and applied a lower border-radius around the gray-progress which will slightly overlap the black.
http://jsfiddle.net/p197qfcj/7/
.tray {
height: 20px;
background: #000;
border-radius: 100px;
height:30px;
width:90%;
}
.fill {
background:#eee;
width:10%;
height:100%;
border-radius: 12px; /* still occurs without this! */
}
Please excuse me if this question has been answered before, but I couldn't find an answer when searching.
Essentially what I'm trying to do is to create a header bar which is 107px high and spans 100% width of the page with a split in colour 50% (50% the left is white, 50% on the right is green) along its width. I have been able to accomplish this using CSS gradients, however I work in the education sector and schools seem to be reluctant to use anything but legacy versions of IE and so, inevitably, it doesn't work properly.
Is there anyway to do this which is IE friendly or is there any kind of work around that can give me the same or similar results?
Thanks in advance!
You have a couple of options:
Use a background image (5px high, really wide, left half is white, right half is green) - it'll cost you less than 100 bytes.
Why not use two divs (floated left, both 50% width)?
Here is the HTML:
<div class="header">
<div style="background: white;">
white bg
</div>
<div style="background: green;">
green bg
</div>
</div>
Here is the CSS:
.header { overflow: hidden; height: 107px; border: 1px solid #000;}
.header div { float: left; width: 50%; height: 100%;}
http://jsfiddle.net/PUWCh/
Like this? http://jsfiddle.net/2gGdD/
I'm using pseudo selectors (works back to IE8) to create each half and layer them behind the div with a negative z-index so you can place content on top of them.
.header {
height: 107px;
position: relative;
width: 100%;
}
.header:before,
.header:after {
content: '';
height: 100%;
position: absolute;
width: 50%;
z-index: -1;
}
.header:before {
background: red;
left: 0;
}
.header:after {
background: blue;
right: 0;
}