good day, i am trying to center my icon and text when i hover an image. my problem is that they dont seem to center themselves. ill show both my html and css. also, i am using bootstrap 4. i tried to center both the icon and text using the "overlay" and "overlay-text" tag but both are suspended at the top. any help would be appreciated.
Code:
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #f08300;
}
.container:hover .overlay {
opacity: 1;
}
.overlay-text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
.spacer {
margin: 20px 0px 20px 0px;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-12 text-align-center">
<h2 class="bold_font">BROWSE OUR CARDS</h2><br>
</div>
<div class="col-md-4 col-xs-12">
<img class="img-responsive" src="img/_stock_mwc_beauty.jpg">
<div class="overlay">
<img src="img/icon-beauty-white.png" class="img-responsive center-block card-icon-sm">
<div class="spacer overlay-text">BEAUTY</div>
</div>
</div>
<div class="col-md-4 col-xs-12">
<img class="img-responsive" src="img/_stock_mwc_health.jpg">
</div>
<div class="col-md-4 col-xs-12">
<img class="img-responsive" src="img/_stock_mwc_wellness.jpg">
</div>
</div>
</div>
You are on the right track, Wrap the content of what you want to show on the overlay and add CSS to that and adjust the images and text accordingly.
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #f08300;
}
.container:hover .overlay {
opacity: 1;
}
.overlay-content {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
.spacer {
margin: 20px 0px 20px 0px;
}
<div class="container">
<div class="row">
<div class="col-md-12 text-align-center">
<h2 class="bold_font">BROWSE OUR CARDS</h2><br>
</div>
<div class="col-md-4 col-xs-12">
<img class="img-responsive" src="img/_stock_mwc_beauty.jpg">
<div class="overlay">
<div class="overlay-content">
<img src="img/icon-beauty-white.png" class="img-responsive center-block card-icon-sm">
<div class="spacer overlay-text">BEAUTY</div>
</div>
</div>
</div>
<div class="col-md-4 col-xs-12">
<img class="img-responsive" src="img/_stock_mwc_health.jpg">
</div>
<div class="col-md-4 col-xs-12">
<img class="img-responsive" src="img/_stock_mwc_wellness.jpg">
</div>
</div>
</div>
Try to using flexboxes for a container and wrap icon and icon-text to div with class e.g. .icon-wrapper:
.overlay {
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #f08300;
}
.overlay-text {
color: white;
font-size: 20px;
text-align: center;
}
.icon-wrapper {
display: flex;
flex-direction: column;
align-items: center;
}
You could wrap the image content together in a relative element and remove absolute position from the text.
something like this: http://jsfiddle.net/tus0kdcq/
update: http://jsfiddle.net/jimmyLi/kruz6eqn
pls try this css:
<style>
.overlay{
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
}
</style>
Related
I have some issue about achieving this. I put the the back ground image in multiple divs, but it's not quite working. Image is repeating on fixed when I make the screen smaller or bigger. when I change it to absolute then every div having an image to itself.
Is it possible to fix these problem?
here it's fiddle:
header {
position: relative;
height: 100vh;
padding: 75px;
}
header div.container {
position: absolute;
z-index: 1;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 350px;
height: 425px;
display: flex;
overflow: hidden;
}
header div.container .context {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
/*
= cols
=== */
header
.container
.col {
width: 50%;
height: 425px;
}
header
.container
.col
.image {
height: 100%;
height: 50%;
background-image: url("https://i.imgur.com/jtZfhST.png");
background-attachment: fixed;
background-position: top left;
}
header
.container
#col-left {
position: relative;
z-index: 2;
top: 12.5px;
}
header
.container
#col-left
.image1, .image3 {
margin-right: 2px;
}
header
.container
.col
.image1, .image2 {
margin-bottom: 2px;
}
header
.container
#col-right {
position: relative;
z-index: 2;
bottom: 12.5px;
}
<header>
<div class="container">
<div class="col" id="col-left">
<div class="image image1"></div>
<div class="image image3"></div>
</div>
<div class="col" id="col-right">
<div class="image image2"></div>
<div class="image image4"></div>
</div>
</div>
</header>
Is this what you're looking for?
.split {
background-image: url(https://images.unsplash.com/photo-1568955773021-d347deaffa1a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1289&q=80);
background-attachment: fixed;
width: 30%;
height: 300px;
margin: 0 10px 10px 0;
display: inline-block;
background-size: cover;
background-position: center;
}
.container {
margin: 10px 0 0 10px;
}
<div class="container">
<div class="row">
<div class="split"></div>
<div class="split"></div>
<div class="split"></div>
</div>
<div class="row">
<div class="split"></div>
<div class="split"></div>
<div class="split"></div>
</div>
</div>
I've built a card flip effect that seems to work on Safari Mobile regarding the "flip" aspect of the effect. However, the card is not displaying the correct image upon flipping. I'm using the effect as a "Before and After", using separate images on each side of the card. I'll post my code. Thank you.
.beforeafter {
margin: 10px auto;
text-align: center;
}
.card-container {
cursor: pointer;
height: 300px;
perspective: 600;
position: relative;
width: 300px;
display: inline-block;
}
.clientcard {
height: 100%;
position: absolute;
transform-style: preserve-3d;
transition: all .5s ease-in-out;
width: 100%;
}
.clientcard:hover {
transform: rotateY(180deg);
-webkit-transform: -webkit-translateY(180deg);
}
.clientcard .side {
backface-visibility: hidden;
border-radius: 2px;
height: 100%;
position: absolute;
overflow: hidden;
width: 100%;
}
.clientcard .back {
background: #eaeaed;
color: #0087cc;
line-height: 150px;
text-align: center;
transform: rotateY(180deg);
}
<div class="beforeafter">
<div class="card-container">
<div class="clientcard">
<div class="side"><img src="img/sean1.JPG"></div>
<div class="side back"><img src="img/sean1copy.JPG"></div>
</div>
</div>
<div class="card-container">
<div class="clientcard">
<div class="side"><img src="img/sean2.JPG"></div>
<div class="side back"><img src="img/sean2copy.JPG"></div>
</div>
</div>
<div class="card-container">
<div class="clientcard">
<div class="side"><img src="img/sean3copy.jpg"></div>
<div class="side back"><img src="img/sean3.jpg"></div>
</div>
</div>
<div class="card-container">
<div class="clientcard">
<div class="side"><img src="img/gwork.jpg"></div>
<div class="side back"><img src="img/alana2.jpeg"></div>
</div>
</div>
</div>
I believe you want to rotate on the Y axis in the negitive -180deg. I improved your code a bit and don't mind the shitty format it was translated from sass and if you want another card with flip copy and past that code
.card {
perspective: 150rem;
-moz-perspective: 150rem;
position: relative;
height: 52rem; }
.card_side {
height: 52rem;
transition: all 2s ease;
position: absolute;
top: 0;
left: 0;
width: 100%;
backface-visibility: hidden;
}
.card_side-front {
background-color: blue;
}
.card_side-back {
transform: rotateY(180deg);
}
.card_side-back-1 {
background-image: linear-gradient(to right bottom, #ffb900, #ff7730);
}
.card:hover .card_side-front {
transform: rotateY(-180deg);
}
.card:hover .card_side-back {
transform: rotateY(0);
}
.card_picture-1 {
background-color: blue;
}
<div class="row">
<div class="col-1-of-3">
<div class="card">
<div class="card_side card_side-front">
<h4 class="card_heading">
<span class="card_heading-span card_heading-span-1">card front text</span>
</h4>
</div>
<div class="card_side card_side-back card_side card_side-back-1">
<div class="card_cta">
<div class="card_price-box">
<p class="card_price-only">back text</p>
</div>
</div>
</div>
</div>
</div>
Hi I have a design i'm trying to recreate using html and css
and this is what i have been able to create so far
this is my html structure
1:
my current html structure looks like with the round borders . when i try to position the inner div at the edges of the round border as in the design the
inner div images get cut. please can you help me fix this
thanks
<div id="container">
<div id="tshirt">image</div>
<div id="tshirt">image</div>
<div id="bag">image</div>
</div>
This should get you started.
.outercircle {
height: 500px;
width: 500px;
border-radius: 100%;
border: 2px dashed purple;
margin: 10% auto;
position: relative;
}
.item {
padding: 10px;
background: purple;
position: absolute;
transition: background .2s;
}
.item img {
border-radius: 100%;
}
.item-1 {
top: 50%;
left: -50px;
transform: translateY(-50%);
}
.item-2 {
top: 50%;
right: -50px;
transform: translateY(-50%);
}
.item-3 {
left: 50%;
top: -50px;
transform: translateX(-50%);
}
.item-4 {
left: 50%;
bottom: -50px;
transform: translateX(-50%);
}
.item:hover {
background: black;
}
<div class="outercircle">
<div class="item item-1">
<img src="http://placehold.it/100x100" alt="" />
</div>
<div class="item item-2">
<img src="http://placehold.it/100x100" alt="" /></div>
<div class="item item-3">
<img src="http://placehold.it/100x100" alt="" /></div>
<div class="item item-4">
<img src="http://placehold.it/100x100" alt="" /></div>
</div>
I am trying to center a group (a table with 3x3) of pictures to the center of the webpage, I manage to do it before adding image overlay to it. But since I added image overlay, the images are appearing on top left of the webpage. How do i group them and center them, also how am I supposed to get the image location so that when I set the image overlay, it goes to the specific picture as each picture will have different image overlay text.
CSS
.container {
position: relative;
width: 100px;
height: 100px;
}
.image {
display: block;
width: 100px;
height: 100px;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: red;
font-size: 20px;
font-weight: bold;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
HTML
<div style="text-align:center">
<div class="container">
<img src="wheel1.jpg" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="container">
<img src="wheels2.jpg" class="image">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="container">
<img src="wheel3.jpg" class="image"">
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
`
You could center it using flexbox. Change your main div
<div style="text-align-center;">
......
</div>
to
<div style="display: flex; flex-direction: column;align-items: center;">
.....
</div>
And it should work.
.wrapper{
display: flex;
flex-direction: row;
justify-content: center;
}
.container {
position: relative;
width: 100px;
height: 100px;
}
.image {
display: block;
width: 100px;
height: 100px;
border: 1px solid red;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: red;
font-size: 20px;
font-weight: bold;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="wrapper">
<div class="container">
<div class="image"></div>
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="container">
<div class="image"></div>
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
<div class="container">
<div class="image"></div>
<div class="overlay">
<div class="text">Hello World</div>
</div>
</div>
</div>
Here is the fiddle.
I have 3 images in a div that I need centered on my webpage. I need the 3 images centered with the main top image.
I believe the .container needs to be centered but I can not figure it out for the life of me! Thank you!
Here is the code I have made. All is working I just need the 3 images centered.
<h2 class="section-title desktop-12" style="text-align: center;"></h2>
<p><img src="//cdn.shopify.com/s/files/1/1317/8733/files/PHOTOGRFR_JoinTheTribe_1920x500_8f70f303-f8ac-4d6a-9c52-ae8cd939349d.jpg?v=1490462024" alt="Join The Tribe" /></p>
<p> </p>
<style><!--
.container { display: inline-block; position: relative; width: 30%; margin: auto; } .image { display: block; width: 100%; height: auto; } .overlay { position: absolute; top: 0; bottom: 0; left: 0; right: 0; height: 100%; width: 100%; opacity: 0; transition: .5s ease; background-color: #f03d41; } .container:hover .overlay { opacity: 1; } .text { color: white; font-size: 20px; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); }
--></style>
<div class="container"><img src="https://cdn.shopify.com/s/files/1/1317/8733/files/Creative.jpg?5705585986642973725" alt="Creative" class="image" />
<div class="overlay"><img src="https://cdn.shopify.com/s/files/1/1317/8733/files/Creative_Hover.jpg?5705585986642973725" alt="CreativeHover" class="image" /></div>
</div>
<div class="container"><img src="https://cdn.shopify.com/s/files/1/1317/8733/files/Brand_Rep.jpg?5705585986642973725" alt="Brand_Rep" class="image" />
<div class="overlay"><img src="https://cdn.shopify.com/s/files/1/1317/8733/files/Brand_Rep_Hover.jpg?5705585986642973725" alt="Brand_RepHover" class="image" /></div>
</div>
<div class="container"><img src="https://cdn.shopify.com/s/files/1/1317/8733/files/Influencer.jpg?5705585986642973725" alt="Influencer" class="image" />
<div class="overlay"><img src="https://cdn.shopify.com/s/files/1/1317/8733/files/Influencer_Hover.jpg?5705585986642973725" alt="InfluencerHover" class="image" /></div>
</div>
You have to add a wrapper div around your .container divs and then make that the same width as the image at the top and have it text-align center.
The style for this:
.container-wrapper {
text-align: center;
width: 1920px;
}
1920px comes from the image the top that you're trying to center under.
Here's a fiddle of this working
The html demonstrating the wrapper is:
<div class="container-wrapper">
<div class="container"><img src="https://cdn.shopify.com/s/files/1/1317/8733/files/Creative.jpg?5705585986642973725" alt="Creative" class="image" />
<div class="overlay"><img src="https://cdn.shopify.com/s/files/1/1317/8733/files/Creative_Hover.jpg?5705585986642973725" alt="CreativeHover" class="image" /></div>
</div>
<div class="container"><img src="https://cdn.shopify.com/s/files/1/1317/8733/files/Brand_Rep.jpg?5705585986642973725" alt="Brand_Rep" class="image" />
<div class="overlay"><img src="https://cdn.shopify.com/s/files/1/1317/8733/files/Brand_Rep_Hover.jpg?5705585986642973725" alt="Brand_RepHover" class="image" /></div>
</div>
<div class="container"><img src="https://cdn.shopify.com/s/files/1/1317/8733/files/Influencer.jpg?5705585986642973725" alt="Influencer" class="image" />
<div class="overlay"><img src="https://cdn.shopify.com/s/files/1/1317/8733/files/Influencer_Hover.jpg?5705585986642973725" alt="InfluencerHover" class="image" /></div>
</div>
</div>
The easiest way to achieve what you want with what you already have is to set text-align: center on a parent container of your .container divs. I've tided the code a little bit, but I've simple added a .container-wrapper that contains your centered elements and it should work as desired.
.container {
display: inline-block;
position: relative;
width: 30%;
margin: auto;
}
.image {
display: block;
width: 100%;
height: auto;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
background-color: #f03d41;
}
.container:hover .overlay {
opacity: 1;
}
.text {
color: white;
font-size: 20px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
.container-wrapper {
text-align: center;
}
<h2 class="section-title desktop-12" style="text-align: center;"></h2>
<p><img src=
"//cdn.shopify.com/s/files/1/1317/8733/files/PHOTOGRFR_JoinTheTribe_1920x500_8f70f303-f8ac-4d6a-9c52-ae8cd939349d.jpg?v=1490462024"
alt="Join The Tribe" /></p>
<p></p>
<div class="container-wrapper">
<div class="container">
<img src=
"https://cdn.shopify.com/s/files/1/1317/8733/files/Creative.jpg?5705585986642973725"
alt="Creative" class="image" />
<div class="overlay"><img src=
"https://cdn.shopify.com/s/files/1/1317/8733/files/Creative_Hover.jpg?5705585986642973725"
alt="CreativeHover" class="image" /></div>
</div>
<div class="container">
<img src=
"https://cdn.shopify.com/s/files/1/1317/8733/files/Brand_Rep.jpg?5705585986642973725"
alt="Brand_Rep" class="image" />
<div class="overlay"><img src=
"https://cdn.shopify.com/s/files/1/1317/8733/files/Brand_Rep_Hover.jpg?5705585986642973725"
alt="Brand_RepHover" class="image" /></div>
</div>
<div class="container">
<img src=
"https://cdn.shopify.com/s/files/1/1317/8733/files/Influencer.jpg?5705585986642973725"
alt="Influencer" class="image" />
<div class="overlay"><img src=
"https://cdn.shopify.com/s/files/1/1317/8733/files/Influencer_Hover.jpg?5705585986642973725"
alt="InfluencerHover" class="image" /></div>
</div>
</div>
To make center child element(s) set this style to their parent element:
.parent{
display: flex;
justify-content: center;
}
No need to display: block or margin: auto or position: absolute/relative ... for child element(s).
In your case wrap the .container divs in a parent div that said.