bootstrap responsive images with shadow+text overlays and another overlay when hover - css

I would like to display images with some description on them, that will be overlayed when hover. I've got something like this:
<div class="container-fluid">
<div class="row">
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-3">
<div class="product-container">
<img src="images/img.png" class="product-img" alt="">
<p class="product-descr">Some description</p>
</div>
</div>
</div>
</div>
Now I need to add some classes (product-item, product-container, product-img, product-desc) to get it working. But I've tried many combinations and still have description below the image (even if the description overlay goes in the right place). And text makes the container going out of the bottom of image and the background of this container is visible.
At present my styles look like this:
.product-item {
position: relative;
}
.product-container {
background:red;
position: relative;
width:100%;
}
.product-img {
position: relative;
width: 100%;
#include hover-focus {
opacity: .5;
}
}
.product-overlay {
position: relative;
&:after {
position: absolute;
content: "";
background: #FFF;
top: -25px;
left: 0;
width: 100%;
height: 25px;
opacity: .7;
z-index:10;
}
}
Any help appreciated. Thank you.

You could position your overlay absolutely and move it out of the way with transform: translateY(). On hover you move it back in. Is this the effect you wanted to achieve?
Here is a CodePen to play with: https://codepen.io/Sixl/pen/bOdwaZ?editors=1100
.product-item {
position: relative;
}
.product-container {
background: #000;
position: relative;
width: 100%;
overflow: hidden;
}
.product-container .product-description {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
background-color: rgba(0, 0, 0, 0.6);
text-align: right;
padding: 0.2em 0.4em 0.2em;
-webkit-transform: translateY(101%);
transform: translateY(101%);
transition: -webkit-transform 200ms ease-in-out;
transition: transform 200ms ease-in-out;
transition: transform 200ms ease-in-out, -webkit-transform 200ms ease-in-out;
}
.product-container:hover .product-description {
-webkit-transform: translateY(0);
transform: translateY(0);
}
.product-img {
display: block;
max-width: 100%;
height: auto;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row">
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-1">
<a href="#">
<figure class="product-container">
<img class="product-img" alt="" src="https://picsum.photos/800/450?image=20">
<figcaption class="product-description">Some description</figcaption>
</figure>
</a>
</div>
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-2">
<a href="#">
<figure class="product-container">
<img class="product-img" alt="" src="https://picsum.photos/800/450?image=21">
<figcaption class="product-description">Some description</figcaption>
</figure>
</a>
</div>
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-3">
<a href="#">
<figure class="product-container">
<img class="product-img" alt="" src="https://picsum.photos/800/450?image=22">
<figcaption class="product-description">Some description</figcaption>
</figure>
</a>
</div>
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-4">
<a href="#">
<figure class="product-container">
<img class="product-img" alt="" src="https://picsum.photos/800/450?image=23">
<figcaption class="product-description">Some description</figcaption>
</figure>
</a>
</div>
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-5">
<a href="#">
<figure class="product-container">
<img class="product-img" alt="" src="https://picsum.photos/800/450?image=24">
<figcaption class="product-description">Some description</figcaption>
</figure>
</a>
</div>
<div class="product-item col-md-4 col-sm-6 col-xs-12 p-6">
<a href="#">
<figure class="product-container">
<img class="product-img" alt="" src="https://picsum.photos/800/450?image=25">
<figcaption class="product-description">Some description</figcaption>
</figure>
</a>
</div>
</div>
</div>

Here something concerning the position of your description, but you should better describe what you want :
Bootply : https://www.bootply.com/blEmsHAYJ1
CSS:
.product-item {
position: relative;
}
.product-container {
background:red;
position: relative;
width:100%;
}
.product-overlay {
position: relative;
}
.product-overlay:after {
position: absolute;
content: "";
background: #FFF;
top: -25px;
left: 0;
width: 100%;
height: 25px;
opacity: .7;
z-index:10;
}
.product-img {
position: relative;
width: 100%;
}
.product-img:hover {
opacity: .5;
}
.product-descr{
position: absolute;
bottom: 0;
display: block;
width: 100%;
margin: 0;
text-align: center;
}

Related

How do I align my border animation in the center with the text

I'm using this border animation https://codepen.io/FlorinCornea/pen/KKpvRYo but I'm trying to make it responsive by wrapping it in bootstrap however now its sticking to the left and I cant seem to center it
This is my DEMO:
.circle-wrapper {
position: relative;
width: 110px;
height: 110px;
}
.icon {
position: absolute;
color: #fff;
font-size: 55px;
top: 55px;
left: 55px;
transform: translate(-50%, -50%);
}
.circle {
display: block;
width: 100%;
height: 100%;
border-radius: 50%;
padding: 2.5px;
background-clip: content-box;
animation: spin 10s linear infinite;
}
.circle-wrapper:active .circle {
animation: spin 2s linear infinite;
}
.success {
background-color: #2e3192;
border: 2.5px dashed #2e3192;
}
.error {
background-color: #CA0B00;
border: 2.5px dashed #CA0B00;
}
.warning {
background-color: #F0D500;
border: 2.5px dashed #F0D500;
}
#keyframes spin {
100% {
transform: rotateZ(360deg);
}
}
.page-wrapper {
background-color: #eee;
align-items: center;
justify-content: center;
}
<link rel="stylesheet" id="bootstrap-css" href="https://cdn.jsdelivr.net/npm/bootstrap#3.3.7/dist/css/bootstrap.min.css?ver=6.0" type="text/css" media="all">
<div class="our-process center-align tinted-bg">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>Our Process</h2>
</div>
<div class="row">
<div class="page-wrapper d-md-flex">
<div class="col-md-3 text-center">
<div class="circle-wrapper mx-auto">
<div class="success circle"></div>
<div class="icon">
<span class="glyphicon glyphicon-user"></span>
</div>
</div>
<h5>Assessor's Visit</h5>
</div>
<div class="col-md-3 text-center">
<div class="circle-wrapper mx-auto">
<div class="success circle"></div>
<div class="icon">
<span class="glyphicon glyphicon-user"></span>
</div>
</div>
<h5>Surveyor's Visit</h5>
</div>
<div class="col-md-3 text-center">
<div class="circle-wrapper mx-auto">
<div class="success circle"></div>
<div class="icon">
<span class="glyphicon glyphicon-user"></span>
</div>
</div>
<h5>installation</h5>
</div>
<div class="col-md-3 text-center">
<div class="circle-wrapper mx-auto">
<div class="success circle"></div>
<div class="icon">
<span class="glyphicon glyphicon-user"></span>
</div>
</div>
<h5>Post Inspection Visit</h5>
</div>
</div>
</div>
</div>
</div>
</div>
I have bootstrap linked to my site so that's not the issue
Here's an image of what it looks like now i am trying to center align the blue circles with the text that's below them:
For Bootstrap 4:
As you use bootstrap, I add 3 bootstrap classes:
d-md-flex (= display:flex on medium screen) on your page-wrapper
text-center on your col-md-3
mx-center (= margin horizontal auto) on your circle-wrapper
The d-md-flex could be replace by row mx-0
For bootstrap 3:
You just need to create the missing css classes:
#media (min-width: 768px){
.d-md-flex {
display: -webkit-box!important;
display: -ms-flexbox!important;
display: flex!important;
}
}
.mx-auto{
margin-right:auto !important;
margin-left:auto !important;
}
Check that on large screen and it should be centered.
.circle-wrapper {
position: relative;
width: 110px;
height: 110px;
}
.icon {
position: absolute;
color: #fff;
font-size: 55px;
top: 55px;
left: 55px;
transform: translate(-50%, -50%);
}
.circle {
display: block;
width: 100%;
height: 100%;
border-radius: 50%;
padding: 2.5px;
background-clip: content-box;
animation: spin 10s linear infinite;
}
.circle-wrapper:active .circle {
animation: spin 2s linear infinite;
}
.success {
background-color: #2e3192;
border: 2.5px dashed #2e3192;
}
.error {
background-color: #CA0B00;
border: 2.5px dashed #CA0B00;
}
.warning {
background-color: #F0D500;
border: 2.5px dashed #F0D500;
}
#keyframes spin {
100% {
transform: rotateZ(360deg);
}
}
.page-wrapper {
background-color: #eee;
align-items: center;
justify-content: center;
}
/************************************/
/** BOOTSTRAP 4 CSS ADDED **/
/************************************/
#media (min-width: 768px){
.d-md-flex {
display: -webkit-box!important;
display: -ms-flexbox!important;
display: flex!important;
}
}
.mx-auto{
margin-right:auto !important;
margin-left:auto !important;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha512-6MXa8B6uaO18Hid6blRMetEIoPqHf7Ux1tnyIQdpt9qI5OACx7C+O3IVTr98vwGnlcg0LOLa02i9Y1HpVhlfiw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<div class="page-wrapper d-md-flex">
<div class="col-md-3 text-center">
<div class="circle-wrapper mx-auto">
<div class="success circle"></div>
<div class="icon">
<span class="glyphicon glyphicon-user"></span>
</div>
</div>
<h5>Assessor's Visit</h5>
</div>
<div class="col-md-3 text-center">
<div class="circle-wrapper mx-auto">
<div class="success circle"></div>
<div class="icon">
<span class="glyphicon glyphicon-user"></span>
</div>
</div>
<h5>Surveyor's Visit</h5>
</div>
<div class="col-md-3 text-center">
<div class="circle-wrapper mx-auto">
<div class="success circle"></div>
<div class="icon">
<span class="glyphicon glyphicon-user"></span>
</div>
</div>
<h5>installation</h5>
</div>
<div class="col-md-3 text-center">
<div class="circle-wrapper mx-auto">
<div class="success circle"></div>
<div class="icon">
<span class="glyphicon glyphicon-user"></span>
</div>
</div>
<h5>Post Inspection Visit</h5>
</div>
</div>

Slider doesn't start - CSS only

I create a slider with some logos, but the animation doesn't start. I create it with only css but it remains blocked. I check few time the code but I can find the answer.
The slider should scroll and change the logo, but it doesn't work.
I think that it could be also created with javascript but I'm not sure how to do it.
Can someone help me?
.slider {
width: 960px;
height: 100px;
overflow: hidden;
position: relative;
margin: auto;
}
.slider::before,
.slider::after {
content: "";
position: absolute;
width: 200px;
height: 100px;
background: linear-gradient(to right, width 0%, rgba(255, 255, 255, 0) 100%);
z-index: 2;
}
.slider::before {
top: 0;
left: 0;
}
.slider::after {
top: 0;
right: 0;
transform: rotateZ(180deg);
}
.slider .slide img {
width: 200px;
height: 100px;
}
.slider .slider-track {
display: flex;
width: calc(200px * 20);
animation: scroll 4s ease 3s infinite linear;
}
#keyframes scroll {
0% {
transform: translateX(0);
}
100% {
transform: translateX(calc(-200px * 10));
}
}
<div class="slider">
<div class="slider-track">
<div class="slide">
<img src="./1.png">
</div>
<div class="slide">
<img src="./2.png">
</div>
<div class="slide">
<img src="./3.png">
</div>
<div class="slide">
<img src="./4.png">
</div>
<div class="slide">
<img src="./5.png">
</div>
<div class="slide">
<img src="./6.png">
</div>
<div class="slide">
<img src="./7.png">
</div>
<div class="slide">
<img src="./8.png">
</div>
<div class="slide">
<img src="./9.png">
</div>
<div class="slide">
<img src="./10.png">
</div>
</div>
</div>
Your animation property is wrong.
use these properties instead. This is more readable and it makes it easier to avoid similar mistakes:
animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count
animation-direction
animation-fill-mode
animation-play-state
https://www.w3schools.com/cssref/css3_pr_animation.asp
.slider {
width: 960px;
height: 100px;
overflow: hidden;
position: relative;
margin: auto;
}
.slider::before,
.slider::after {
content: "";
position: absolute;
width: 200px;
height: 100px;
background: linear-gradient(to right, width 0%, rgba(255, 255, 255, 0) 100%);
z-index: 2;
}
.slider::before {
top: 0;
left: 0;
}
.slider::after {
top: 0;
right: 0;
transform: rotateZ(180deg);
}
.slider .slide img {
width: 200px;
height: 100px;
}
.slider .slider-track {
display: flex;
width: calc(200px * 20);
animation: scrolll 4s ease;
}
#keyframes scrolll {
0% {
transform: translateX(0);
}
100% {
transform: translateX(calc(-200px * 10));
}
}
<div class="slider">
<div class="slider-track">
<div class="slide">
<img src="./1.png">
</div>
<div class="slide">
<img src="./2.png">
</div>
<div class="slide">
<img src="./3.png">
</div>
<div class="slide">
<img src="./4.png">
</div>
<div class="slide">
<img src="./5.png">
</div>
<div class="slide">
<img src="./6.png">
</div>
<div class="slide">
<img src="./7.png">
</div>
<div class="slide">
<img src="./8.png">
</div>
<div class="slide">
<img src="./9.png">
</div>
<div class="slide">
<img src="./10.png">
</div>
</div>
</div>

How do I achieve this particular hover effect?

I am trying to replicate this hover effect but I'm even sure where to start to be honest.
Here is my HTML code:
<div class="row">
<div class="col-sm-4 portfolio-item">
<a href="#" class="thumbnail">
<img src="img/portfolio/cabin.png">
</a>
</div>
<div class="col-sm-4 portfolio-item">
<a href="#" class="thumbnail">
<img src="img/portfolio/game.png">
</a>
</div>
<div class="col-sm-4 portfolio-item">
<a href="#" class="thumbnail">
<img src="img/portfolio/circus.png">
</a>
</div>
CSS: (all I have)
#portfolio .portfolio-item {
background-color: #18BC9C;
transition: all ease .5s;
-webkit-transition: all ease .5s;
}
#portfolio .portfolio-item:hover {
}
I don't even know where to begin. I think I need to fix something with the z-index and opacity but I don't know where to adjust it, and I'm also not sure where to put the transition effect. Everything I've tried has not worked so if someone could show me how to achieve that hover effect from a clean slate that would be greatly appreciated.
Hi this will get you started. First create an overlay opacity 0, then write a little jQuery so that on hover a class is applied opacity 1 with an rgba (rgb with opacity) and a css transition.
See the code for more, and run with this if you like I've separated the overlay from the image so you have control of them both:
$( document ).ready(function() {
$( '.portfolio-item' )
.mouseover(function() {
$( this ).find( '.overlay' ).addClass( 'show' );
})
.mouseout(function() {
$( this ).find( '.overlay' ).removeClass( 'show' );
});
});
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.col-sm-4 {
float: left;
width: 33%;
position: relative;
}
img {
width: 100%;
display: block;
}
.overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(145,0,0,0.5);
z-index: 2;
width: 100%;
height: auto;
opacity: 0;
-webkit-transition: .3s ease-in opacity;
-moz-transition: .3s ease-in opacity;
transition: .3s ease-in opacity;
}
.overlay.show {
opacity: 1;
}
.overlay.show:after {
content: 'x';
color: white;
position: absolute;
left: 50%;
margin-right: -50%;
top: 50%;
transform: translateY(-50%);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="row">
<div class="col-sm-4 portfolio-item">
<div class="overlay"></div>
<a href="#" class="thumbnail">
<img src="http://placehold.it/100x50">
</a>
</div>
<div class="col-sm-4 portfolio-item">
<div class="overlay"></div>
<a href="#" class="thumbnail">
<img src="http://placehold.it/100x50">
</a>
</div>
<div class="col-sm-4 portfolio-item">
<div class="overlay"></div>
<a href="#" class="thumbnail">
<img src="http://placehold.it/100x50">
</a>
</div>
You can use a pseudo element ::after to create an overlay. Just use opacity: 0; to hide it, and show it on hover: opacity: 0.6;. As transition you can use: transition: opacity ease .5s;.
This way, you can create an color overlay over every image (would not be possible with only using background on the parent element). To create the magnifying glass, you can either use a <span> inside the <a> tag, or the other pseudo element ::before.
.portfolio-item a {
position: relative;
}
.portfolio-item a::after {
position: absolute;
top: 0;
left: 0;
content: "";
width: 100%;
height: 100%;
background: #457647;
opacity: 0;
transition: opacity ease .5s;
}
.portfolio-item a:hover::after {
opacity: 0.6;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="col-sm-4 portfolio-item">
<a href="#" class="thumbnail">
<img src="//placehold.it/200x100/fff">
</a>
</div>
<div class="col-sm-4 portfolio-item">
<a href="#" class="thumbnail">
<img src="//placehold.it/200x100/fff">
</a>
</div>
<div class="col-sm-4 portfolio-item">
<a href="#" class="thumbnail">
<img src="//placehold.it/200x100/fff">
</a>
</div>
</div>
Of course you have to use vendor prefixes for older browsers. Also make sure that your markup is valid - a closing div tag was missing.

Inline-block display of divs with position relative

I have a series of images each with his own overlay. How can I have them aligned like inline-blocks? I tried adding adding display: inline-block;to .image-wrapper but the images are always all positioned in the top left corner of the div.container (Here is a jsfiddle).
Here are the html and css
.container {
position: relative;
}
.image-wrapper {
position: relative;
display: inline-block;
}
.tweetty {
position: absolute;
overflow: auto;
top: 0;
left: 0;
}
.image-vest {
position: absolute;
top: 0;
left: 0;
background-color: #00f;
width: 220px;
height: 300px;
opacity: 0.4;
color: #fff;
}
<div class="container">
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-one</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-two</div>
</div>
</div>
EDIT:
revised css with dfsq suggestion to remove position:absolute; from .tweetty.
Quoting dfsq comment:
"Elements with position absolute don't contribute to the width and height of their parent container. So the image-wrapper divs just collapse as if they were empty if all children have position:absolute; "
.container {
position: relative;
}
.image-wrapper {
position: relative;
display: inline-block;
}
.tweetty {
overflow: auto;
top: 0;
left: 0;
}
.image-vest {
position: absolute;
top: 0;
left: 0;
background-color: #00f;
width: 220px;
height: 300px;
opacity: 0.4;
color: #fff;
}
<div class="container">
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-one</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-two</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-three</div>
</div>
</div>
I fiddled with the fiddle, and this seems to work. removed all the positioning from all but the vest. Used the inline-block display mode. Set top to -300px, and also the bottom-margin, otherwise you get a gap below the images.
.container {
/* position:relative;*/
}
.image-wrapper {
/* position: relative;*/
display: inline-block;
}
.tweetty {
/* position:absolute;
overflow:auto;
top:0;
left:0;*/
}
.image-vest {
position:relative;
top:-300px;
margin-bottom: -300px;
left:0;
background-color:#00f;
width:220px;
height:300px;
opacity:0.4;
color:#fff;
}
<div class="container">
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-one</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-two</div>
</div>
<div class="image-wrapper">
<div class="tweetty">
<img src="http://www.picgifs.com/clip-art/cartoons/tweety/clip-art-tweety-191375.jpg" />
</div>
<div class="image-vest">Tweetty-three</div>
</div>
</div>
(here's the JSFiddle version)

overlapping elements in bootstrap

How to overlap a text with an image (text in front of the image) and center them while keeping both responsive (without using position fixed or background-image) in Bootstrap?
<pre>
<!--jumbotron-->
<div class="jumbotron">
<div class="container">
<div class="brand">
<h1 id="success">Alexandra</h1>
<img class="img-responsive" src="lavrente.jpg" width="300" height="52" >
</div>
</div>
</div>
</pre>
<pre>#success {
color: #000;
font-family: "Chopin Script";
position:relative;
z-index: 1;
}
.img-responsive {
position:relative;
z-index: 0;}
</pre>
Use position: absolute on the text.
h1{
position: absolute;
}
Here is another solution with full responsive:
<div class="jumbotron">
<div class="container">
<div class="brand">
<img src="http://via.placeholder.com/350x150" alt="" class="img-responsive" width="300" height="52">
<h1 id="success">Alexandra</h1>
</div>
</div>
</div>
CSS:
.brand {
position: relative;
text-align: center;
}
#success {
position: absolute;
top: 0%;
left: 50%;
transform: translate(-50%, -50%);
}
live preview: https://codepen.io/mesapkota/pen/QryREB

Resources