So my problem is with using a css mask to hide a position: fixed; item. Reason being because apparently overflow: hidden; doesn't work. So this actually works swimmingly in all the browsers I've tested it in UNTIL the height of the div containing the mask reaches a specific, seemingly arbitrary, height. ( 1280px on iPad, 2000px in desktop Safari )
I'm totally stumped on this and haven't found anyone with any documentation on this issue. Has anyone worked with css masks at all to maybe have some clues as to why this is the case?
Here's a screencast demoing the bug and the code used to generate it.
https://www.dropbox.com/s/bxzsmkqgll1yeix/Screeny%20Video%20Feb%2010%2C%202014%2C%209.18.28%20PM.mov
And here's a zip with the code used in that demo.
http://cl.ly/Tqy7
Any ideas or proposed solutions?
--- HTML ---
<div class="attn hairline"></div>
<div class="shadow"></div>
<div id="home">
<div class="attn blur"></div>
<div id="content">
<p>Hey, here is some awesome content, stuff you will definitely want to read.</p>
</div>
</div>
--- CSS ---
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%;
width: 100%;
text-align: center;
background-color: #f0f0f0;
}
.attn {
position: fixed;
width: 80%;
height: 100%;
left: 50%;
margin-left: -40%;
background: no-repeat center;
background-size: 100% auto;
}
.hairline {
background-image: url(../img/attn.svg);
}
.blur {
background-image: url(../img/blur.png);
}
.shadow {
position: relative;
height: 20px;
margin-bottom: -20px;
box-shadow: 0px -3px 6px rgba(0,0,0,.1);
top: 100%;
}
#home {
position: relative;
top: 100%;
background: #fff;
mask: url(../img/mask.svg);
-webkit-mask: url(../img/mask.svg);
-o-mask: url(../img/mask.svg);
-ms-mask: url(../img/mask.svg);
/* 1281px will kill the mask on iPad, 2001px will kill it on the desktop */
height: 1280px;
}
#content {
padding: 10% 5%;
}
What I ended up doing was setting a max-height attribute on the masked element until that element got to the top of the browser window. I had the fuzzy image text disappearing at this point anyway so it was a good time to, once the image was gone, remove that max-height attribute. Works great, though I'd still love to solve the original problem someday. I'm guessing its a browser quirk though seeing as how it was so arbitrarily consistent.
Related
I am trying to fit a div inside a shape using mix-blend-mode:screen. Although on large screen it looks good when I use chrome reponsive tool on some screens are shown borders like this is there a way to remove these borders?
Here is my code
.banner-img {
width: 100%;
max-width: 1000px;
height: 100%;
background-size: 100% 100%;
margin-left: -75px;
display: flex;
align-items: center;
position: relative;
background-color: rgba(51,51,51,0.8);
background-blend-mode: overlay;
&::before{
content: "";
position: absolute;
height: 100%;
top: 0;
left: 0;
width: 100%;
background-image: url('../../../Assets/mask.jpg');
background-size: 100% 100%;
border: none;
mix-blend-mode: screen;
}
<div className={`banner-content ${props.styles}`}>
<div className="banner-img" style={{ backgroundImage: `url(${props.img})` }}>
<div className="content">{<props.content />}</div>
</div>
<div className="content">{props.children}</div>
</div>
https://jsfiddle.net/d5rw3zkg/8/
UPDATE: the original 'fix' in this answer hid the border but altered the shape. #Alfred found that changing the height to calc(100% + 1px) rather than 101% fixed the problem - both hiding the border and keeping the correct shape.
Here's the original answer and the surmise as to the reason:
This is not a full answer to the question as I cannot reproduce the problem on any of the devices I have. But I have seen similar problems before where somehow there isn't an exact overlap of two images. This is possibly because of the mismatch between CSS and actual device pixels (which can be several pixels to make up one CSS pixel) but this is just a surmise.
Could you try this experiment? On a device where you can see the problem, also run it with just one setting changed in the SCSS. This is to see whether we can get the mask to stretch just beyond the underlying image so there is no chance of a sliver being left behind.
&::before{
content: "";
position: absolute;
height: 100%;/**CHANGE TO 101% (original answer) now calc(100% + 1px) **/
top: 0;
left: 0;
width: 100%;
background-image: url('../../../Assets/mask.jpg');
background-size: 100% 100%;
border: none;
mix-blend-mode: screen;
}
I am making a profile page and have turned a square image into a circle using the CSS code below:
.circular {
width: 250px;
height: 250px;
background-image: url('./images/profile.jpg');
background-size: cover;
display: block;
border-radius: 125px;
-webkit-border-radius: 125px;
-moz-border-radius: 125px;
margin-left: auto;
margin-right: auto;
margin-top: -150px;
}
However I am struggling to make this responsive within the header portion of my page, any ideas how I could have rounded corners and make the image scale at the same time?
Thanks!
I would suggest like already mentioned to avoid fixed px values and instead use percentages.
Another approach (if applicable in your case) could be the use of screenbased responsive styling like:
#media screen and (min-width:960px) {
.circular {
/* ... */
}
}
#media screen and (min-width:1440px) {
.circular {
/* ... */
}
}
With that you can ensure that you have fixed transition points when you resize your design/image.
You could try something like the following.
Just ensure that the parent container is of reasonable width, because .circular will take all of its width.
.wrap {
width: 400px; /* for example... */
}
.circular {
width: 100%;
padding-bottom: 100%;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
margin-left: auto;
margin-right: auto;
margin-top: -150px;
background-image: url(http://placehold.it/200x200);
background-size: cover;
}
<div class="wrap">
<div class="circular"></div>
</div>
I've wrote a little experiment for a parallax background header using only CSS: http://codepen.io/Kageetai/pen/yIdAq?editors=110
It's works very well in Chrome but in Firefox the header has a strange behaviour, even though Codepen uses -prefix-free. The background images shoves itself on top of the content below and the jumbs after scrolling down a bit.
It uses the technique found here, which I think is very elegant. So I copied most of it and wanted to apply it for a header.
I suppose it has something to do with that part, which mainly makes the parallax happening:
.parallax {
position: relative;
//padding: 25vh 10%;
padding: 0.1px; // strange behaviour with padding 0
min-height: 100vh;
width: 100vw;
box-sizing: border-box;
transform-style: inherit;
background: 50% 50% / cover;
&:before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left:0;
right:0;
background: 50% 50% / cover;
}
}
header {
text-align: center;
color: whitesmoke;
&:before {
background-image: url(http://www.theloftberlin.com/wp-content/uploads/2013/09/2013-berlin.jpg) !important;
transform: translateZ(-1px) scale(2);
z-index:-1;
}
}
And furthermore the fixed navigation isn't fixed at all on Chrome and Firefox.
Anyone any ideas?
Thanks!
Add position:relative to your #wrapper that will fix overlapping of image on the text.
add z-index="2" to .nav
check the codepen here Code pen
I have a CSS problem that only occurs in Google Chrome. Objects set to overflow: hidden are being 'clipped' at the edges when within a horizontally centred container, and only at
odd browser widths, and only on a high-res display.
HTML:
<html><body>
<div id="container">
<div class="sprite"> </div>
</div>
</body></html>
CSS:
#container
{
margin: 0 auto;
max-width: 800px;
-webkit-transform: translate3d(0px,0px,0px);
}
.sprite
{
width: 30px;
height: 30px;
overflow: hidden;
position: relative;
}
.sprite:after
{
content: ' ';
overflow: hidden;
display: block;
width: 30px;
height: 30px;
position: absolute;
top: 0;
left: 0;
background-image: url("/img/sprite#2x.png");
background-position: 0 0;
background-repeat: no-repeat;
-webkit-background-size: 30px 30px;
-moz-background-size: 30px 30px;
-o-background-size: 30px 30px;
background-size: 30px 30px;
}
Now, as I resize the width of the window, at odd window widths the sprite gets clipped either side on my retina display. It does not occur on a standard (1 css pixel to 1 display pixel) display.
This apparent rendering bug does not occur in Safari or Firefox. This is on OS X 10.9.3 running Chrome 35.
Edit: It also happens with a pure CSS circle shape, so doesn't seem related to the use of a background image.
My example was too over-simplified so the problem didn't occur standalone.
It turns out that, via a SASS mixin in my full application, I had the following applied to the panel containing the sprite (edit question to include it)
-webkit-transform: translate3d(0px,0px,0px);
This was there to improve CSS performance with hardware acceleration where available (mainly iOS).
Removing this improves the situation slightly, so it seems less likely to 'clip' the shape when resizing the window.
However removing overflow: hidden from the :after element seems to have solved it entirely.
It is worth noting that this 'clipping' side-effect occurs even with a pure CSS circle, it's not related to background-images (thanks #Rohit).
This seems to be a rendering bug rather than something I'm doing wrong.
Hey now you can try this with out image
Css
#container
{
margin: 0 auto;
}
.sprite
{
width: 30px;
height: 30px;
position: relative;
text-align:center;
line-height:30px;
font-weight:bold;
}
.sprite:after
{
content: ' ';
overflow: hidden;
display: block;
position: absolute;
top: 0;
left: 0;
right:0;
bottom:0;
background:#eecc00;
border-radius:50%;
z-index:-1;
}
HTML
<div id="container">
<div class="sprite">! </div>
</div>
Demo
I have a following HTML/CSS (simplified):
<body>
<style>
body
{
margin: 0px;
padding: 0px;
color: #fff;
background-color: #090909;
text-align: center;
}
#content
{
width: 500px;
margin: 0px auto;
background-color: blue;
}
#header
{
width: 500px;
margin: 0px auto;
background-color: green;
}
#over-div {
background-color: red;
position: absolute;
height: 20px;
width: 100%;
margin: 0px;
top: 0px;
left: 0px;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
filter: alpha(opacity=50);
-khtml-opacity: 0.5;
-moz-opacity: 0.5;
opacity: 0.5;
}
</style>
<div id="over-div">aa</div>
<div id="header">
header
</div>
<div id="content">
content here
</div>
</body>
The idea is to have over-div to cover the upper part of the page completely (but do not keep it fixed there, so it is not visible when user scrolls down the page).
If you zoom-in extremely (Ctrl+ wheel) till the horizontal scrollbar appears, you can see that after scrolling completely to the right, the over-div does not cover the header completely to the right side of window.
I hoped that width:100% would mean "always use 100% width of the body", but it seems it is not true for absolute positioned divs.
Tested browsers: Firefox 3.5, Chrome, IE8 (with and without compatibility mode).
Is there any way to get that div cover 100% width of page?
Yes, add this to the #over-div styling:
min-width:500px;
That ensures that #over-div will be at least as wide as your #header and #content divs