Loop through HTML elements in CSS and apply style - css

I have 4 cards (extendible to N cards) in a stack that I want to show in a stacked effect using HTML and CSS.
Desired Output:
I have the following code so far, but need some help tweaking the CSS to show the stacked effect for all 4 cards instead of 2 cards.
body {
background-color: #e8eaed;
}
.stack {
width: 500px;
height: 500px;
position: absolute;
}
.card {
width: 80%;
min-height: 40%;
background-color: white;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: grid;
justify-content: center;
align-items: center;
border-radius: 5px;
font-family: sans-serif;
font-size: 10rem;
color: #00000080;
box-shadow: 0 5px 15px 0 #00000040, 0 5px 5px 0#00000020;
transition: transform 200ms;
}
.card:nth-last-child(1) {
--y: calc(-50% + 15px);
transform: translate(-50%, var(--y)) scale(1.05);
}
<div class="stack">
<div class="card" style="--i:1">1</div>
<div class="card" style="--i:2">2</div>
<div class="card" style="--i:3">3</div>
<div class="card" style="--i:4">4</div>
</div>

You are using the CSS Custom Property --y in your styles and the custom property --i in your markup.
I've made some edits to your styles, to demonstrate how you can achieve the effect you describe.
Working Example:
body {
background-color: #e8eaed;
}
.stack {
width: 500px;
height: 500px;
position: absolute;
}
.card {
width: 80%;
min-height: 40%;
background-color: white;
position: absolute;
top: 100px;
left: 100px;
transform: translate(-50%, -50%);
display: grid;
justify-content: center;
align-items: center;
border-radius: 5px;
font-family: sans-serif;
font-size: 10rem;
color: #00000080;
box-shadow: 0 5px 15px 0 #00000040, 0 5px 5px 0#00000020;
transition: transform 200ms;
}
.card {
transform: translateY(calc((var(--y) * 20px) - 50%)) scale(calc(1.0 + var(--y) * 0.05));
}
<div class="stack">
<div class="card" style="--y:1">1</div>
<div class="card" style="--y:2">2</div>
<div class="card" style="--y:3">3</div>
<div class="card" style="--y:4">4</div>
</div>

Related

Are there any way to change color of part of a string?

I'am beginner at frontend, and got some design-layout to train. Designer expects that on hover part of string or even letter will change color Example
I thought about CSS 'clip', but doubt
I change the snippet. Play with font-size.
body {
margin: 0;
padding: 0;
}
.wrapper {
position: absolute;
width: 100vw;
height: 50vh;
top: 50%;
transform: translateY(-50%);
font-size: 3em;
font-weight: bold;
font-family: sans-serif;
background-color: red;
}
.wrapper1 {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
clip-path: inset(0 50% 0 0);
background-color: blue;
display: flex;
justify-content: center;
align-items: center;
}
.wrapper2 {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
clip-path: inset(0 0 0 50%);
background-color: green;
display: flex;
justify-content: center;
align-items: center;
}
<div class="wrapper">
<div class="wrapper1">Hello World!</div>
<div class="wrapper2">Hello World!</div>
</div>
As G-Cyrillus has pointed out, background-clip with value text can be used, it will 'cut out' characters from the background.
In this simple snippet the background is half white, half black and the blue/white background is supplied in a pseudo before element.
Note that the property requires a -webkit- prefix in some browsers.
* {
margin: 0;
}
div::before {
background-image: linear-gradient(to right, blue 0 50%, white 50% 100%);
content: '';
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
div {
position: relative;
width: 100vw;
height: 500px;
font-size: 50px;
text-align: center;
rmix-blend-mode: difference;
rcolor: white;
-webkit-background-clip: text;
background-clip: text;
color: transparent;
background-image: linear-gradient(to right, white 0 50%, black 50% 100%);
}
<div>Hello how are you?</div>
So, Thanks for your help, A Haworth , G-Cyrillus! I think, I've found the solution. I experimented with background-clip:text, but in my case it was excess, but I used mix-blend-mode, thanks. I've found an article Taming Blend Modes: difference and exclusion, where explained filter:invert(1). Tried to show in snippet. When hover the cell part of title change color to white. But color of title and hovering background should be the same.My realized layout from designer
.block {
width: 100%;
height: 200px;
padding-top: 10px;
position: relative;
filter: invert(1);
}
h1 {
position: relative;
color: #091C91;
text-align:center;
font-size: 2rem;
z-index: 5;
mix-blend-mode:difference;
filter: invert(1);
}
.list {
display: flex;
justify-content: center;
border: 1px solid red;
height: 130px;
width: 100%;
position: absolute;
top: 0;
left: 0;
}
.column {
color: white;
flex: 0 1 25%;
border: 1px solid black;
filter: invert(1);
}
.column:hover {
background: #091C91;
}
<div class="block">
<h1>Snippet for Inverting colores</h1>
<div class="list">
<div class="column">Column 1</div>
<div class="column">Column 2</div>
<div class="column">Column 3</div>
<div class="column">Column 4</div>
</div>
</div>

Hover event not working with biggest z-index

I have a gallery item with some image in its body. It has to display MORE link in the center of the body when I hover over gallery item (which works just fine) and display 0.5 opacity when I hover over MORE link. Even though z-index is bigger than parent's, for some reason :hover event simply does not fire. Any clue on how to fix this? My cursor: pointer also does not work.
HTML:
<div class="gallery _flex-between">
<div class="gallery__item gallery-item _flex-column-center">
<div class="gallery-item__body">
<div class="gallery-item__more-container">
<a class="gallery-item-more">More →</a>
</div>
<img src="/resources/projects/1.jpg" alt="" class="gallery__img">
</div>
<div class="gallery-item__footer">
Everlasting Summer
</div>
</div>
</div>
CSS:
._absolute-cover {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.gallery {
margin-top: 4em;
width: 90%;
}
.gallery-item__footer {
font-size: 1.6rem;
margin-top: 1em;
width: 100%;
border: 1px solid black;
text-align: center;
border-radius: 35px;
padding: .5em 0;
letter-spacing: 2px;
background-color: white;
transition: background-color .3s, color .3s;
}
.gallery__item {
position: relative;
width: 30%;
max-width: 600px;
}
.gallery-item__more-container {
display: flex;
align-items: center;
justify-content: center;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0);
transition: background-color .3s;
border-radius: 35px;
z-index: 2;
}
.gallery-item__link {
position: absolute;
width: 100%;
height: 100%;
cursor: default;
z-index: 4;
}
.gallery-item-more {
position: relative;
z-index: 1000000000;
width: 50%;
background-color: rgba(255, 255, 255, 1);
opacity: 0;
transition: background-color .3s;
color: black;
font-weight: bold;
letter-spacing: 1px;
padding: 1em 0;
border-radius: 35px;
text-align: center;
cursor: pointer;
}
.gallery-item-more:hover {
background-color: rgba(255, 255, 255, .5);
}
.gallery-item__link:hover ~ .gallery-item__footer {
background-color: black;
color: white;
}
.gallery-item__link:hover ~ .gallery-item__body .gallery-item__more-container {
background-color: rgba(0,0,0,0.8);
}
.gallery-item__link:hover ~ .gallery-item__body .gallery-item-more {
opacity: 1;
}
.gallery-item__body {
width: 100%;
position: relative;
}
._flex-column-center {
display: flex;
flex-direction: column;
align-items: center;
}
.gallery__img {
object-position: top;
height: 25vw;
width: 100%;
border-radius: 35px;
}
Move the image before the more-button and it should work: Codepen
<div class="gallery _flex-between">
<div class="gallery__item gallery-item _flex-column-center">
<div class="gallery-item__body">
<img src="/resources/projects/1.jpg" alt="" class="gallery__img">
<div class="gallery-item__more-container">
<a class="gallery-item-more">More →</a>
</div>
</div>
<div class="gallery-item__footer">
Everlasting Summer
</div>
</div>
</div>

CSS| Are 3D Absolute Items always on top of every other item?

so i have an issue, i am developing a website and i'm playing around with 3 dimensional cards. so the problem i run in is basically, no matter which z-index i give the div that should be above it, the card is still always in front. Is this an normal behavior or am i missing something? Thank you really much :)
Heres the HTML:
<div class="project">
<div class="project-title">
<h1>someproject</h1>
</div>
<div class="project-scene">
<div class="project-card">
<div class="project-face project-front">
</div>
<div class="project-face project-back">
<p>blablabla</p>
<img src="../assets/solarflarepi-presentation.gif">
<p>
blablabla
</p>
</div>
</div>
</div>
</div>
And here is the css:
.project{
border: white solid 0.3em;
border-radius: 1em;
margin-bottom: 1em;
margin-left: 1em;
flex: 1;
align-items: center;
}
.project-card{
background-color: transparent;
width: 25em;
height: 26em;
position: relative;
transition: transform 0.5s;
transform-style: preserve-3d;
}
.project-scene{
perspective: 1000px;
}
.project-scene:hover .project-card{
transform: rotateY(180deg);
}
.project-face{
position: absolute;
backface-visibility: hidden;
z-index: 0; /* The Div which should be above it has 5 */
}
.project-back .project-card{
background-color: black;
}
.project-front{
background-color: white;
width: 100%;
height: 100%;
}
.project-back{
background-color: black;
width: 100%;
height: 100%;
transform: rotateY(180deg);
}
.project-title{
background-color: white;
color: black;
}
.project-title h1{
margin: 0;
padding: 0em 0.5em 0em 0.5em;
font-weight: normal;
text-align: center;
}
.project-back img{
width: 25em;
}
In this case z-index do not fix your problem, you must use transform: translateZ(5);
like this:
enter image description here

Position Element in front of another object Using CSS

I'm new in CSS and this time I want to position my object in front of slider, So I read about that and I know Slider should have position: relative and my other object with position: absolute
Desire result:
So I do it, but it does not work, also the object is not responsive, how can I fix that? I prepare an example of how it works.
#main-slider {
width: 100%;
height: 528px;
/* border-radius: 0% 0% 50% 50% / 0% 0% 20% 20%; */
border-bottom-right-radius: 50% 25%;
border-bottom-left-radius: 50% 25%;
position: relative;
}
.badge {
background-color: #fff;
border-radius: 30px;
box-shadow: 0 15px 35px 0 rgba(42,51,83,.12), 0 5px 15px rgba(0,0,0,.06);
width: 17%;
position: absolute;
}
.text {
padding: 0.5rem 0.25rem 0.5rem 1rem;
}
.link {
border-radius: inherit;
display: inline-block;
background-color: red;
padding: 0.5rem 1rem;
color: #F9F9EC;
width: 57%;
}
<section>
<div>
<img id="main-slider" src="https://via.placeholder.com/1365x528?text=Slider">
<div class="badge">
<span class="text">Contact us</span>
<a class="link">
(555) <strong>123 4567</strong>
</a>
</div>
</div>
</section>
Regards
You can do this adding a class called .wrapper to this and using display: flex and justify content center. Also need a margin top: 0.5em to your .badge
Read more about flex boxes here
Run snippet below.
#main-slider {
width: 100%;
height: 528px;
/* border-radius: 0% 0% 50% 50% / 0% 0% 20% 20%; */
border-bottom-right-radius: 50% 25%;
border-bottom-left-radius: 50% 25%;
position: relative;
}
.badge {
background-color: #fff;
border-radius: 30px;
box-shadow: 0 15px 35px 0 rgba(42, 51, 83, .12), 0 5px 15px rgba(0, 0, 0, .06);
position: absolute;
margin-top: 0.5em;
}
.text {}
.link {
border-radius: inherit;
display: inline-block;
background-color: red;
padding: 0.5rem 1rem;
color: #F9F9EC;
}
.wrapper {
display: flex;
justify-content: center;
align-items: flex-end;
}
<section>
<div class="wrapper">
<img id="main-slider" src="https://via.placeholder.com/1365x528?text=Slider">
<div class="badge">
<span class="text">Contact us</span>
<a class="link">(555) <strong>123 4567</strong></a>
</div>
</div>
</section>

Sideway rotate text with background

Hello I'm trying to make something like this with css Image Link.
I've tried transform: skew(0deg, -35deg); and transform: rotate(-45deg); but the background color isn't as the image.
you can try this
.container{
border: 1px solid black;
margin: 40px;
height: 400px;
position: relative;
overflow: hidden;
}
.rotated{
background: maroon;
color: white;
transform: rotate(45deg);
text-align: center;
width: 100px;
position: absolute;
right: -25px;
top: 15px;
}
<div class="container">
<div class="rotated">TEXT</div>
</div>
You can use this css approach for this
.card {
width:300px;
height: 300px;
position: relative;
background: #ddd;
overflow: hidden;
}
.tag {
position: absolute;
top:5px;
right:-24px;
background: #990000;
padding: 5px 30px;
text-align: center;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
color: #fff;
font-size: 14px;
}
<div class="card">
<div class="tag">New</div>
</div>
Well, I tested this only in chrome. I hope this can serve as a starting point for you.
https://jsfiddle.net/pablodarde/af5c9x78/
.container {
display: flex;
justify-content: center;
align-items: center;
width: 380px;
height: 380px;
background: linear-gradient(#D4EDFF, #fff);
}
.inner {
width: 300px;
height: 300px;
background: #fff;
box-shadow: 0 0 2px rgba(0,0,0,.1);
}
.holder-tag {
position: relative;
width: 0;
height: 0;
left: 300px;
}
.holder-tag .tag {
position: absolute;
right: -30px;
top: 20px;
border-bottom: 20px solid #900;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
height: 10px;
width: 90px;
transform: rotate(45deg);
}
.holder-tag span {
position: absolute;
right: -18px;
top: 25px;
width: 110px;
line-height: 1px;
color: #fff;
font: normal 14px Arial, Verdana;
text-align: center;
padding: 5px 0 0 0;
box-sizing: border-box;
transform: rotate(45deg);
}
.content {
width: 80%;
padding: 10px;
}
<div class="container">
<div class="inner">
<div class="holder-tag">
<div class="tag"></div>
<span>new</span>
</div>
<div class="content">
<p>
You can write text here without worrying about space.
</p>
</div>
</div>
</div>

Resources