border-radius on parent div breaks perspective / translateZ on child - html

I followed a tutorial for a css-only scrolling parallax effect, but now I want to put the image inside a circle.
So I...
1) set the parent div ("wrapper") to my chosen dimensions,
2) set the parent to overflow-hidden, (so far so good, the parallax effect still works inside my "clipped" box),
3) ...but when I set a border-radius of any kind, it breaks the parallax effect, freezing the image in place when I scroll.
Here's my pen: https://codepen.io/iiiDaNiii/pen/eEBEyY with the parallax effect working inside a square div called "wrapper." If you try to add a border-radius, it breaks the parallax effect.
.html {
overflow:hidden;
}
.scroll {
right:0px;
overflow-y:auto;
overflow-x:hidden;
position:absolute;
height:100vh;
width:100vw;
-webkit-overflow-scrowling: touch;
-webkit-perspective: 1px;
perspective: 1px;
perspective-origin: 0% 0%;
margins: 0px;
padding: 0px;
top:0px;
}
.wrapper {
background-color:blue;
position:relative;
height:20em;
width:20em;
overflow:hidden;
}
.image {
position:relative;
height:vh;
width:vw;
-webkit- transform: translateZ(-1px) scale(2);
transform: translateZ(-1px) scale(2);
transform-origin: 50% 0;
}
.space{
position:relative;
background-color:white;
height:2000px;
}
Any rad thoughts?
Update / clarification: I want whatever is outside of the circle to be transparent.... so that the parallax-circle-image could sit on top of i.e. another image.

I believe I've found a solution.
I've added a pseudo-class to the .wrapper element and applied a solid box-shadow to it with a border-radius of 5px, which maintains the parallax effect and also gives rounded corners.
So, add the following selector to your css:
.wrapper:before
{
position: absolute;
content: '';
top: 0; left: 0;
right: 0; bottom: 0;
border-radius: 5px;
z-index: 5;
box-shadow: 0 0 0 10px white;
}
I created a live Fiddle here.

Related

Transparent layer over img when hover ++ text

I want to add an transparent layer over my img on a card when I hover over it, I have done that part but I want it to be cut to the img and not cover the footer on the card. If that makes sence?
this is the card with Hover. As u can see on the card, the img just covers like 90% of the card, I want the hover overlay to do the same
Card when not hover IMG
Card when hover IMG
.card {
position:relative;
width: 350px;
height: 335px;
background-size: contain;
background-repeat: no-repeat;
background-color: #fff;
border-radius: 5px;
margin: 30px;
float: left;
}
#card_oslo{
background-image: url(img/oslo.jpg);
}
#card_oslo:hover{
box-shadow: inset 0 0 0 1000px rgba(0,0,0,.7);
transition: .5s;
}
You should use a pseudo-element for this. Use :after or :before and set it as full size also set the parent with position:relative; then change the opacity of the pseudo element on hover.
Working Demo.
.box {
position:relative;
}
.box:after {
content:"";
/* Set the element as full-size */
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
/* Set bg and hide the element + animation */
background-color:#000;
opacity:0;
transition: all 0.5s ease 0s;
}
.box:hover:after {
/* Show the overlay on hover */
opacity:0.5;
}
/* For the demo */
.box {
width:200px;
height:200px;
background-color:red;
}
<div class="box"></div>
You can set the overlay to
position: absolute;
top: 0;
bottom: XXpx;
left: 0;
right: 0;
where XX is the footer height, then it will cover the whole card and leave the bottom x pixels free. You can also use % values instead of px.
If you want the overlay to contain text you need to put it into an extra div that you can then use as overlay.
I made a simplified version here https://jsfiddle.net/0L9fL1pj/
Been looking for a similar solution and since this thread never got a proper answer (neither proposed answer got me where I wanted and I doubt) but I got some important clues here and I thought I'd provide my current solution so anyone who has a similar problem can benefit.
I made a simple demo here: https://jsfiddle.net/Tdesign/2ynuajk0/14/
HTML:
<div id="imgBox2" class="shade">
<img id="img2" src="https://upload.wikimedia.org/wikipedia/commons/9/9a/Gull_portrait_ca_usa.jpg" width="350" height="335" loading="lazy" >
</div>
CSS:
#imgBox2 {
position: relative;
width: 500px;
}
.shade:hover::after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 500px;
background-color: rgba(0,0,0,0.5);
}

Responsive positioning in center

I have a full width background image with some content.
At the end I want to position my buttons in center (vertically and horizontally), but with position:absolute, that doesn't work. You can see it in JSFiddle.
There is some code lines from my CSS
.buttons{
position:relative;
}
.buttons .button-pos{
width:100%;
position:absolute;
margin:auto;
top:0;
bottom:0;
left:0;
right:0;
}
And there is little scheme of that what I want.
1.) Your .buttons div doesn't have a height, so first you need to define a height for it, otherwise there is no vertical centering possibility ( I made it 200px in the fiddle).
2.) To center .button-pos within .buttons, use
.button-pos {
width: 100%;
position:absolute;
top:50%;
left:50%;
transform: translate(-50%, -50%);
}
Here's the fiddle: https://jsfiddle.net/Luo1k7Lt/1/
I make some solution by myself and it works now very well, I decided to center all my content, what was in the header. Only some little changes with screen sizes and it works well
#welcome-header .welcome-content{
width: 80%;
height: 400px;
position: absolute;
margin: auto;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.buttons{
margin-top: 40px;
}
Try this:
.buttons .button-pos {
display: inline-block;
zoom: 1;
}
A simple IE hack is to add display*: inline; in that CSS rule

resizeable centred div tag with fixed position

I'm trying to float a fixed position div tag in the centre of my browser and have it stay centred even when the browser is resized. I can get it centred but it moves to the left when the browser is resized because of the margins used to get it centred.
Is there a CSS trick I can use to make the margin-top & margin-left dynamic? I would also like to have the width of the container set to 90%.
#conntainer {
position:fixed;
width: 17028px; /* would like this to be width: 90%; */
height: 798px;
top: 50%;
left: 50%;
margin-top: -145px;
margin-left: -864px;
z-index: 100;
}
Use this instead:
#conntainer {
position:fixed;
width: 90%;
height: 798px;
top:0;
right:0;
bottom:0;
left:0;
margin:auto;
z-index: 100;
}
jsFiddle example
Use CSS transform instead.
#conntainer {
position:fixed;
width: 90%;
height: 798px;
top: 50%;
left: 50%;
z-index: 100;
transform: translate(-50%, -50%);
}
See proof-of-concept fiddle here: http://jsfiddle.net/teddyrised/vbdCz/
The advantage of this method is that it also centers dynamic heights property... although it appears from your example that you'll be sticking to a fixed height anyway :) (in that case, using auto left/right margins without transform is sufficient).
p/s: You might want to add vendor prefixes (just -webkit-, actually) to the CSS transform property.

how can a div be made a background for another div

The original idea was to have one div with this style:
background-color:rgba(0,0,0,0.7);
However, I discovered that rgba is only supported by newer browsers
I was wondering how could I make a "rgba"-background using a div with this style:
display:block;
height:100%;
width:100%;
background-color: #000;
opacity:0.6;
When I left it at this, this div did not show... :(
Is there a better way to do this?
I assume you want to use the inner div to be a background color for the outer div since you are looking for the most cross-browser background opacity.
<div class="outer">
<div class="inner"></div>
</div>
Based on this article from CSS-Tricks: http://css-tricks.com/snippets/css/cross-browser-opacity/ and the implementation you are looking for you want to use this css:
.outer {
border: 1px solid #000;
width: 300px;
height: 300px;
position: relative;
}
.inner {
background-color: green;
width: 100%;
height: 100%;
position: absolute;
/* IE 8 */
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
/* IE 5-7 */
filter: alpha(opacity=50);
/* Netscape */
-moz-opacity: 0.5;
/* Safari 1.x */
-khtml-opacity: 0.5;
/* Good browsers */
opacity: 0.5;
}
The inner div has absolute position because if you don't any content you place inside the outer div will be affected by or affect the background inner div.
Here is a working fiddle: http://jsfiddle.net/X8Asy/
You can also replace the width and height with:
top: 0;
bottom: 0;
left: 0;
right: 0;
but width and height is fewer properties.
You can make the div visible by setting an actual width and height, not 100%:
width: 500px;
height: 500px;
background-color: #000;
opacity: 0.6;
Online demo: http://jsfiddle.net/nEw2E/

How to place image behind another image that has a transparent background

I have a rounded square box image that has a red strip that runs along the left side and has a transparent background (the white bit) which I created in photoshop. I would like to place an image behind this box. I have tried setting the position:absolute and z-index: -1; however, it places the image behind everything. Is there a way I can achieve this with just the CSS? P.S. I have searched for solutions but the ones I have come across did not seem to help me at all.
CSS:
#boxes img {
border:1px solid;
margin:4px 0 0 0px;
padding:0;
position: absolute;
width: 359px;
height: 218px;
z-index: -1 ;
-moz-border-radius-topright:5px;
-moz-border-radius-topleft:5px;
-moz-border-radius-bottomright:5px;
-moz-border-radius-bottomleft:5px;
-webkit-border-top-right-radius:5px;
-webkit-border-top-left-radius:5px;
-webkit-border-bottom-right-radius:5px;
-webkit-border-bottom-left-radius:5px;
}
#boxes .box {
width:370px;
height:241px;
float:left;
background-image:url(../imgs/box_front.png);
background-repeat:no-repeat;
background-color:#FFF;
margin:80px 30px 0 0;
}
You can't reliably set z-index without setting position on your elements; the stacking is also relative to the elements' containers, so if everything is at root level the image with a negative z-index will disappear behind the page. (Personally, I try and avoid negative z-index values whenever possible.)
#boxes {
position: relative;
}
#boxes img {
border:1px solid;
margin:4px 0 0 0px;
padding:0;
position: absolute;
width: 359px;
height: 218px;
z-index: 1 ;
-moz-border-radius-topright:5px;
-moz-border-radius-topleft:5px;
-moz-border-radius-bottomright:5px;
-moz-border-radius-bottomleft:5px;
-webkit-border-top-right-radius:5px;
-webkit-border-top-left-radius:5px;
-webkit-border-bottom-right-radius:5px;
-webkit-border-bottom-left-radius:5px;
}
#boxes .box {
width:370px;
height:241px;
float:left;
background-image:url(../imgs/box_front.png);
background-repeat:no-repeat;
background-color:#FFF;
margin:80px 30px 0 0;
position: relative;
z-index: 2;
}
EDIT:
The problem is that your HTML is structured so the red stripe is the background image of the container that you're loading the image into. As this also has a background-color, the image is being lost behind it.
A better way of doing this would be to use HTML/CSS' natural document flow - i.e. the later the element appears in the HTML, the 'higher' it is in the natural z-index. This'll mean you don't have to specify z-index values, but you will need to add a presentational div to your code (unless you want to monkey around with :after pseudo-elements):
Each grey box will need to look like this:
<div class="grey box">
<h3>Stationary</h3>
<span class="border"> </span><img src="http://placekitten.com/g/361/220"><div class="innerBox"> </div>
</div>
... and your CSS will need to change. Remove the background from the .box styles, and add this to your CSS:
#boxes .innerBox {
position: absolute;
left: 0;
top: 0;
width:370px;
height:241px;
background-image:url(http://i754.photobucket.com/albums/xx182/rache_R/box_front_zps196242cf.png);
background-repeat:no-repeat;
}
You can then remove the z-index from #boxes .box, and because the innerBox div appears after the image in your markup, it will naturally appear higher than your image.
If you can't add any extra HTML to your markup template, you could repurpose the border divs, which don't seem to be doing much:
#boxes .border
{
border:none;
z-index:1;
cursor:pointer;
position: absolute;
left: 0;
top: 0;
width:370px;
height:241px;
background-image:url(http://i754.photobucket.com/albums/xx182/rache_R/box_front_zps196242cf.png);
background-repeat:no-repeat;
}
You'll need to update your images too:
#boxes img {
/* other declarations */
position: absolute;
left: 4px;
top: 0;
/* other declarations */
}
... and make sure your #boxes .box style has position: relative; set.
That should do you: http://jsfiddle.net/mr3Fq/4/