.box {
width: 300px;
height: 30px;
display: flex;
justify-content: center;
flex-direction: column;
}
.block1 {
width: 10%;
height: inherit;
background: black;
position: absolute;
animation: boxincrease 2s cubic-bezier(0.74, 0.86, 0.4, 0.92) forwards;
}
#keyframes boxincrease {
0% {
width: 10%;
left: 0;
}
50% {
width: 100%;
left: 0;
}
100% {
width: 0%;
left: 100%;
}
}
<div class="nameintro">
<div class="box">
<div class="block1"></div>
<h1>XYZ<span>.</span></h1>
</div>
<div class="role">
<div class="block2"></div>
<p>AMATEUR ARTIST</p>
</div>
</div>
I want to change the width of the black block as it is covering the whole width of the page i want it to cover only the part where xyz written.
I want to make something like this without using scss.
https://www.youtube.com/watch?v=7d2XsPSjjjI
You need to set the "box" width to fit content so that it doesn't exceed the text and set the position relative to it.
.box {
width: fit-content;
height: 30px;
display: flex;
justify-content: center;
flex-direction: column;
position: relative;
}
.block1 {
height: inherit;
background: black;
position: absolute;
animation: boxincrease 2s cubic-bezier(0.74, 0.86, 0.4, 0.92) forwards;
}
#keyframes boxincrease {
0% {
width: 10%;
left: 0;
}
50% {
width: 100%;
left: 0;
}
100% {
width: 0%;
left: 100%;
}
}
<div class="nameintro">
<div class="box">
<div class="block1"></div>
<h1>XYZ<span>.</span></h1>
</div>
<div class="role">
<div class="block2"></div>
<p>AMATEUR ARTIST</p>
</div>
</div>
Adjust the values in your keyframe,
.box {
width: 300px;
height: 30px;
display: flex;
justify-content: center;
flex-direction: column;
}
.block1 {
width: 10%;
height: inherit;
background: black;
position: absolute;
animation: boxincrease 0.8s cubic-bezier(0.74, 0.86, 0.4, 0.92) forwards;
}
#keyframes boxincrease {
0% {
width: 10%;
left: 0;
}
50% {
width: 15%;
left: 0;
}
100% {
width: 0%;
left: 15%;
}
}
<div class="nameintro">
<div class="box">
<div class="block1"></div>
<h1>XYZ<span>.</span></h1>
</div>
<div class="role">
<div class="block2"></div>
<p>AMATEUR ARTIST</p>
</div>
</div>
I would use a grid and put the blocks in the same grid column example;
.nameintro {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-auto-rows: minmax(30px, auto);
}
.box {
display: grid;
justify-content: center;
grid-template-columns: 300px;
grid-auto-rows: minmax(30px, auto);
}
.one {
grid-column: 1 / 1;
grid-row: 1;
}
.two {
grid-column: 1 / 1;
grid-row: 1;
align-self: center;
justify-self: center;
}
.role {
grid-column: 2 / 2
}
.block1 {
background-color: black;
animation: boxincrease 2s cubic-bezier(0.74, 0.86, 0.4, 0.92) forwards;
}
#keyframes boxincrease {
0% {
width: 10%;
left: 0;
}
50% {
width: 100%;
left: 0;
}
100% {
width: 0%;
left: 100%;
}
}
<div class="nameintro">
<div class="box">
<div class="one block1"></div>
<h1 class="two">XYZ<span>.</span></h1>
</div>
<div class="role">
<div class="block2"></div>
<p>AMATEUR ARTIST</p>
</div>
</div>
Related
I'm trying to create a landing page where it shows 2 logos. On hover a background image should appear on the left hand side of the page but should fill from top to bottom. At the moment it's only filling the div container of the logo. I'm not that good at coding and got help with creating these codes.
Code Below
body {
background-color: white;
}
.container {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.row {
display: flex;
width: 80%;
}
.left-logo,
.right-logo {
width: 50%;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.left-logo img,
.right-logo img {
opacity: 0;
transition: opacity 5s;
}
.left-bg,
.right-bg {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-size: cover;
background-position: center;
opacity: 0;
transition: opacity 0.5s;
}
.left-logo:hover .left-bg {
opacity: 1;
background-image: url(images/bg-left.png);
}
.right-logo:hover .right-bg {
opacity: 1;
background-image: url(images/bg-right.png);
}
.left-logo img,
.right-logo img {
opacity: 1;
}
<body>
<div class="container">
<div class="row">
<div class="left-logo">
<img src="images/logo-left.png" alt="Left Logo">
<div class="left-bg"></div>
</div>
<div class="right-logo">
<img src="images/logo-right.png" alt="Right Logo">
<div class="right-bg"></div>
</div>
</div>
</div>
</body>
Tried to put the image in the css code where left-bg is but still didn't work.
Try adding height: 100vh; and width: 100%; to the .row class and margin:0; to the body tag as follows:
body {
background-color: white;
margin: 0;
}
.container {
width: 100%;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.row {
display: flex;
width: 100%;
height: 100vh;
}
.left-logo, .right-logo {
width: 50%;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.left-logo img, .right-logo img {
opacity: 0;
transition: opacity 5s;
}
.left-bg, .right-bg {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-size: cover;
background-position: center;
opacity: 0;
transition: opacity 0.5s;
}
.left-logo:hover .left-bg {
opacity: 1;
background-image: url(https://lumiere-a.akamaihd.net/v1/images/sa_pixar_virtualbg_coco_16x9_9ccd7110.jpeg);
}
.right-logo:hover .right-bg {
opacity: 1;
background-image: url(https://lumiere-a.akamaihd.net/v1/images/sa_pixar_virtualbg_coco_16x9_9ccd7110.jpeg);
}
.left-logo img, .right-logo img {
opacity: 1;
}
<head>
<title>Landing Page</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="left-logo">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSOyCtPSy5vZ6NNKe6nmW5aEAWDfv2R3bV72g&usqp=CAU" alt="Left Logo">
<div class="left-bg"></div>
</div>
<div class="right-logo">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSOyCtPSy5vZ6NNKe6nmW5aEAWDfv2R3bV72g&usqp=CAU" alt="Right Logo">
<div class="right-bg"></div>
</div>
</div>
</div>
</body>
On mouse hover, animated span tags beneath an img work fine when the img isn't using object-fit: contain like below:
body {
height: 100%;
width: 100%;
margin: 0
}
.container {
max-width: 600px;
position: relative;
text-align: center;
width: 100%;
}
.product {
position: relative;
width: 150px;
}
img.content {
background: white;
height: auto;
margin: 8%;
position: relative;
width: 84%;
vertical-align: middle;
z-index: 5000;
}
.product:hover .effect-1,
.product:hover .effect-2 {
display: block;
}
.effect-1,
.effect-2 {
border-radius: 30%;
display: none;
mix-blend-mode: multiply;
height: 84%;
opacity: 1;
position: absolute;
width: 84%;
z-index: 3000;
}
.effect-1 {
animation: rotate 1.8s linear infinite;
background: cyan;
}
.effect-2 {
animation: rotate 1.2s linear reverse infinite;
background: #e7a9ff;
}
.placeholder {
width: 84%;
height: auto;
visibility: hidden;
}
#keyframes rotate {
0% {
top: 0;
left: 8%;
}
25% {
top: 8%;
left: 0%;
}
50% {
top: 16%;
left: 8%;
}
75% {
top: 8%;
left: 16%;
}
100% {
top: 0;
left: 8%;
}
}
<body>
<div class="container">
<p>Hover image please</p>
<div class="product">
<img class="content" src="http://www.petsworld.in/blog/wp-content/uploads/2014/09/Golden-Retriever-Puppies-in-basket.jpg">
<span class="effect-1"><img class="placeholder" src="http://www.petsworld.in/blog/wp-content/uploads/2014/09/Golden-Retriever-Puppies-in-basket.jpg"></span>
<span class="effect-2"><img class="placeholder" src="http://www.petsworld.in/blog/wp-content/uploads/2014/09/Golden-Retriever-Puppies-in-basket.jpg"></span>
</div>
</div>
</body>
But when the img is using object-fit: contain the animated spans take up the entire area:
body {
height: 100%;
margin: 0;
}
.container {
max-width: 600px;
position: relative;
text-align: center;
width: 100%;
height: 100%;
min-height: 700px;
}
.product {
height: 100%;
position: absolute;
}
.content {
background: white;
margin: 8%;
position: relative;
width: 84%;
height: 100%;
vertical-align: middle;
z-index: 5000;
object-fit: contain;
}
.product:hover .effect-1,
.product:hover .effect-2 {
display: block;
}
.effect-1,
.effect-2 {
border-radius: 30%;
display: none;
mix-blend-mode: multiply;
height: 84%;
opacity: 1;
position: absolute;
width: 84%;
z-index: 3000;
}
.effect-1 {
animation: rotate 1.8s linear infinite;
background: cyan;
}
.effect-2 {
animation: rotate 1.2s linear reverse infinite;
background: #e7a9ff;
}
.placeholder {
width: 84%;
height: auto;
visibility: hidden;
}
#keyframes rotate {
0% {
top: 0;
left: 8%;
}
25% {
top: 8%;
left: 0%;
}
50% {
top: 16%;
left: 8%;
}
75% {
top: 8%;
left: 16%;
}
100% {
top: 0;
left: 8%;
}
}
<body>
<div class="container">
<div class="product">
<span class="effect-1"><img class="placeholder" src="http://www.petsworld.in/blog/wp-content/uploads/2014/09/Golden-Retriever-Puppies-in-basket.jpg"></span>
<span class="effect-2"><img class="placeholder" src="http://www.petsworld.in/blog/wp-content/uploads/2014/09/Golden-Retriever-Puppies-in-basket.jpg"></span>
<img class="content" src="http://www.petsworld.in/blog/wp-content/uploads/2014/09/Golden-Retriever-Puppies-in-basket.jpg">
</div>
</div>
</body>
How do you make these hover effects apply only to the area around the image (not the entire area) when using object-fit: contain? The image must remain vertically centered using object-fit.
Is this what you wanted? The image is centered between the animated divs.
The reason why your image is larger in the second example you've given is because you've changed your CSS there. You've changed the height/width values of .container, .product etc, so the children elements are showing up larger, because they inherit these values.
I've changed max-width and min-height in .container to reduce the overall size. And the width of .content should be less than the width of the effect divs
html {
width: 100%;
height: 100%;
}
body {
width: 100%;
height: 100%;
margin: 0;
}
.container {
max-width: 300px;
/* This is new */
position: relative;
text-align: center;
width: 100%;
height: 100%;
min-height: 300px;
/* This is new */
}
.product {
height: 100%;
position: absolute;
display: flex;
flex-direction: column;
justify-content: center;
}
.content {
display: flex;
align-self: center;
background: white;
margin: 0 auto;
position: relative;
width: 65%;
/* This is new */
object-fit: contain;
/* This is new */
}
.product:hover .effect-1,
.product:hover .effect-2 {
display: flex;
}
.effects {
position: absolute;
}
.effect-1,
.effect-2 {
border-radius: 30%;
display: flex;
mix-blend-mode: multiply;
height: 84%;
opacity: 1;
position: absolute;
width: 84%;
z-index: 3000;
visibility: visible;
}
.effect-1 {
animation: rotate 1.8s linear infinite;
background: cyan;
}
.effect-2 {
animation: rotate 1.2s linear reverse infinite;
background: #e7a9ff;
}
.placeholder {
width: 84%;
height: auto;
visibility: hidden;
object-fit: contain;
display: flex;
margin: 0 auto;
align-self: center;
position: relative;
}
#keyframes rotate {
0% {
top: 0;
left: 8%;
}
25% {
top: 8%;
left: 0%;
}
50% {
top: 16%;
left: 8%;
}
75% {
top: 8%;
left: 16%;
}
100% {
top: 0;
left: 8%;
}
}
<body>
<div class="container">
<div class="product">
<span class="effects">
<img class="placeholder" src="http://www.petsworld.in/blog/wp-content/uploads/2014/09/Golden-Retriever-Puppies-in-basket.jpg">
<span class="effect-1"></span>
<span class="effect-2"></span>
</span>
<img class="content" src="http://www.petsworld.in/blog/wp-content/uploads/2014/09/Golden-Retriever-Puppies-in-basket.jpg">
</div>
</div>
</body>
I want to place the css animation so it only shows partially on the page.
My problem is that it keeps expanding the page.
I have tried using overflow hidden on .ripple-background but this doesn't work. I have also tried using clip but I don't think this is the right solution unless I am using it wrong.
Can anyone shed some light for me please!
.ripple-background {
position: sticky;
z-index: -1;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 1fr;
justify-items: center;
align-items: center;
height: 610px;
width: 610px;
margin-left: 60%;
margin-top: 50vh;
}
.circle {
position: absolute;
border-radius: 50%;
background: white;
animation: ripple 25s infinite;
box-shadow: 0px 0px 1px 0px #b1b1b1;
}
.small {
width: 100px;
height: 100px;
}
.medium {
width: 200px;
height: 200px;
}
.large {
width: 300px;
height: 300px;
}
.xlarge {
width: 400px;
height: 400px;
}
.xxlarge {
background-color: grey;
width: 500px;
height: 500px;
}
.shade1 {
opacity: 1;
}
.shade2 {
opacity: 0.5;
}
.shade3 {
opacity: 0.7;
}
.shade4 {
opacity: 0.8;
}
.shade5 {
opacity: 0.9;
}
#keyframes ripple {
0% {
transform: scale(0.8);
}
50% {
transform: scale(1.2);
}
100% {
transform: scale(0.8);
}
}
<!-- Animation -->
<div class="ripple-background">
<div class="circle xxlarge shade1"></div>
<div class="circle xlarge shade2"></div>
<div class="circle large shade3"></div>
<div class="circle medium shade4"></div>
<div class="circle small shade5"></div>
</div>
<!-- Animation END-->
For overflow hidden to work, you need it to be on a parent container, with the content inside of it that you want to hide.
Below, I've created a wrapper and set it to be the size of the page.
* {
padding:0;
margin:0;
}
#wrapper {
width: 100vw;
height: 100vh;
overflow:hidden;
}
.ripple-background {
position: sticky;
z-index: -1;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 1fr;
justify-items: center;
align-items: center;
height: 610px;
width: 610px;
margin-left: 60%;
margin-top: 50vh;
}
.circle {
position: absolute;
border-radius: 50%;
background: white;
animation: ripple 25s infinite;
box-shadow: 0px 0px 1px 0px #b1b1b1;
}
.small {
width: 100px;
height: 100px;
}
.medium {
width: 200px;
height: 200px;
}
.large {
width: 300px;
height: 300px;
}
.xlarge {
width: 400px;
height: 400px;
}
.xxlarge {
background-color: grey;
width: 500px;
height: 500px;
}
.shade1 {
opacity: 1;
}
.shade2 {
opacity: 0.5;
}
.shade3 {
opacity: 0.7;
}
.shade4 {
opacity: 0.8;
}
.shade5 {
opacity: 0.9;
}
#keyframes ripple {
0% {
transform: scale(0.8);
}
50% {
transform: scale(1.2);
}
100% {
transform: scale(0.8);
}
}
<!-- Animation -->
<div id='wrapper'>
<div class="ripple-background">
<div class="circle xxlarge shade1"></div>
<div class="circle xlarge shade2"></div>
<div class="circle large shade3"></div>
<div class="circle medium shade4"></div>
<div class="circle small shade5"></div>
</div>
</div>
<!-- Animation END-->
This question already has answers here:
CSS vertical alignment of inline/inline-block elements
(4 answers)
Closed 2 years ago.
So I have this:
Then I add text:
.front {
background: #e0e0e0;
width: 100%;
height: 200px;
border: 5px solid black;
}
#keyframes animateonload {
0% {
top: 0;
left: 200px;
background: #80ed9d;
}
25% {
top: 200px;
left: 200px;
background: #9f80ed;
}
50% {
top: -101px;
left: -900px;
background: #eda380;
}
75% {
top: 900px;
left: 200px;
background: #3e6b66;
}
100% {
top: 450px;
left: 100px;
background: #ccfa8c;
}
}
body {
animation-name: animateonload;
animation-duration: 5s;
animation-iteration-count: 1;
position: relative;
width: 100%;
height: auto;
}
.divver3 {
width: 33%;
height: 600px;
background: #faa68c;
font-size: 20px;
display: inline-block;
grid-column: 3;
grid-row: 1;
}
.divver2 {
width: 33%;
height: 600px;
background: #faa68c;
font-size: 20px;
display: inline-block;
grid-column: 2;
grid-row: 1;
}
.divver1 {
width: 33%;
height: 600px;
background: #faa68c;
font-size: 20px;
display: inline-block;
grid-column: 1;
grid-row: 1;
}
.div {
width: 100%;
height: auto;
}
.divver1 h1 {
text-align: center;
margin: 0;
}
<div class="div">
<div class="divver1">
<h1> Price option 1 </h1>
</div>
<div class="divver2">
</div>
<div class="divver3">
</div>
</div>
</div>
So why does my thing do this when I add text to the box? I have no answer, and how can this do this?
Is this just a flaw in my code in the .divver?
The code contains the full grid layout, and correct <div> positioning so why hasn't this worked?
Is it that I need padding/margins? Or does the width need to vary each box? Please help me.
Thank you,
Ring Games
display: inline-block will, by default, vertically align elements according to their baseline.
When they're empty, the baseline is just the bottom of the element.
But when you add some text, the baseline is the baseline of that text. Notice how the bottom of the text is now aligned to the bottom of the other elements.
In this case you may be better off with display: grid;, display: flex; or maybe even column-count: 3; to achieve your layout, but if you're stuck with what you've got then adding vertical-align: top; should do the trick.
Try making your position absolute like this:
.front {
background: #e0e0e0;
width: 100%;
height: 200px;
border: 5px solid black;
}
#keyframes animateonload {
0% {top: 0; left: 200px; background: #80ed9d;}
25% {top: 200px; left: 200px; background: #9f80ed;}
50% {top: -101px; left: -900px; background: #eda380;}
75% {top: 900px; left: 200px; background: #3e6b66;}
100% {top: 450px; left: 100px; background: #ccfa8c;}
}
body {
animation-name: animateonload;
animation-duration: 5s;
animation-iteration-count: 1;
position: relative;
width: 100%;
height: auto;
}
.divver3 {
width: 33%;
height: 600px;
background: #faa68c;
font-size: 20px;
display: inline-block;
grid-column: 3;
grid-row: 1;
}
.divver2 {
width: 33%;
height: 600px;
background: #faa68c;
font-size: 20px;
display: inline-block;
grid-column: 2;
grid-row: 1;
}
.divver1 {
width: 33%;
height: 600px;
background: #faa68c;
font-size: 20px;
display: inline-block;
grid-column: 1;
grid-row: 1;
position: absolute;
}
.div {
width: 100%;
height: auto;
}
.divver1 h1 {
text-align: center;
margin: 0;
}
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title> Ring Games - Official Site</title>
</head>
<body>
<div class="div">
<div class="divver1">
<h1>this is some text</h1>
</div>
<div class="divver2">
</div>
<div class="divver3">
</div>
</div>
</body>
</html>
Assuming the red box represents my webpages container, and items B,C,D are outside the container. Is it possible to have the items (A,B,C,D...) auto scroll left to right like a carousel using just CSS?
I'm seen examples online on how to do this with images but not with DIVs full of text with a set width?
.container {
margin: 0 auto;
width: 800px;
background: red;
padding: 36px;
box-sizing: border-box;
}
.items {
display: flex;
}
.item {
box-sizing: border-box;
margin-left: 72px;
margin-right: 72px;
padding: 36px;
position: relative;
width: 200px;
min-width: 200px;
background: #efefef;
text-align: center;
border-radius: 4px;
}
<div class="container">
<div class="items">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
</div>
</div>
Here's a way to do it.
.container {
margin: 0 auto;
background: red;
box-sizing: border-box;
overflow-x: hidden;
}
.items {
min-height: 200px;
position: relative;
}
.item {
box-sizing: border-box;
padding: 36px;
position: absolute;
width: 30%;
background: #efefef;
text-align: center;
border-radius: 4px;
top: 50%; left: 50%;
transform: translate(-50%, -50%);
animation: slide-item 4s infinite;
animation-timing-function: cubic-bezier(.4, 0, .2, 1);
opacity: 0;
}
.item:nth-child(2) { animation-delay: 1s; }
.item:nth-child(3) { animation-delay: 2s; }
.item:nth-child(4) { animation-delay: 3s; }
#keyframes slide-item {
0% { left: 150%; opacity: 1; }
36% { left: 50%; opacity: 1; }
72% { left: -50%; opacity: 1; }
100% { left: -50%; }
}
<div class="container">
<div class="items">
<div class="item">A</div>
<div class="item">B</div>
<div class="item">C</div>
<div class="item">D</div>
</div>
</div>