Display content in the card when hover - html

I have a card item as you see in the picture, opacity is 0.5:
When I hover I want to display some information on it like in the picture again:
So here is my example;
.card-img {
width: 100%;
border-radius: calc(0.3rem - 0px);
}
.card-img-top {
width: 100%;
border-radius: 32px;
opacity: 0.5;
}
.card-img-top:hover {
opacity: 1;
}
<div class="col-md-6">
<div class="card">
<a href="#">
<img class="card-img-top img-raised" src="img/banner-1.png" alt="Open Project 1">
<div class="banner-content">
Description
</div>
<a class="mb-2 mt-2 text-center small-xl" href="#">Check More Details</a>
</a>
</div>
</div>
So what I am trying to achieve in this example, when I hover I want to display Description (banner-content) and I want to set the opacity to 1 which I am already doing.

You can use + selector wicth select the adjacent sibling. More on mdn
.card{
position:relative;
}
.card-img {
width: 100%;
max-width:150px;
border-radius: calc(0.3rem - 0px);
}
.card-img-top {
border-radius: 32px;
opacity: 0.5;
width:150px;
}
.card-img-top:hover {
opacity: 1;
}
.banner-content{
position:absolute;
top:0;
left:0;
display:none;
}
.card-img-top:hover + .banner-content{display:block;}
<div class="col-md-6">
<div class="card">
<a href="#">
<img class="card-img-top img-raised" src="https://via.placeholder.com/50" alt="Open Project 1">
<div class="banner-content">
Description
</div>
<a class="mb-2 mt-2 text-center small-xl" href="#">Check More Details</a>
</a>
</div>
</div>

Step 1: I make a .top-layout class with opacity: 0 to keep it hide by default.
Step 2: Use .card:hover .top-layout selector in CSS to set what style you want when the card item is hover.
.card {
width: 100%;
border-radius: calc(0.3rem - 0px);
}
.card:hover .top-layout {
opacity: 0.5 !important;
}
.top-layout {
opacity: 0;
position: absolute;
bottom: 0;
text-align: center;
width: 100%;
}
.card-img-top {
width: 100%;
border-radius: 32px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div class="col-md-6">
<div class="card">
<a href="#">
<img class="card-img-top img-raised" src="https://image.freepik.com/free-vector/comic-colorful-frame-background_52683-71995.jpg" alt="Open Project 1">
<div class="top-layout">
<div class="banner-content">
Description
</div>
<a class="mb-2 mt-2 text-center small-xl" href="#">Check More Details</a>
</div>
</a>
</div>
</div>

Put a Adjacent Sibling Selector when you hover on img and display the content .
+ is used here which selects the first .banner-content element that is placed immediately after .card-img-top element .
Find more info here about combinators
.card {
position: relative;
}
.banner-content {
position: absolute;
top: 20px;
left: 20px;
display:none;
}
.card-img {
width: 100%;
border-radius: calc(0.3rem - 0px);
}
.card-img-top {
width: 400px;
height:200px;
border-radius: 32px;
opacity: 0.5;
}
.card-img-top:hover {
opacity: 1;
}
.card-img-top:hover + .banner-content {
display: block;
}
<div class="col-md-6">
<div class="card">
<a href="#">
<img class="card-img-top img-raised" src="https://pixy.org/src/477/4774988.jpg" alt="Open Project 1">
<div class="banner-content">
I am a new coder.<br> Happy to meet : )
</div><br>
<a class="mb-2 mt-2 text-center small-xl" href="#">Check More Details</a>
</a>
</div>
</div>

Related

Apply CSS Animation on overlapping images

Am trying to achieve this animation on the CISO website header. I created a fiddle showing what i was able to achieve but something seems off.
img {
transition: all .3s ease;
overflow: hidden;
width: 100%;
margin: 0;
padding: 0;
height: auto;
}
#img2 {}
#img1,
#img3 {
z-index: 3;
}
/* hover effects */
#img2:hover {
transform: scaleX(1.08);
z-index: 8;
}
#img1:hover {
transform: scaleX(1.08);
z-index: 8;
}
#img3:hover {
transform: scaleX(1.08);
z-index: 8;
}
<div class="container">
<div class="d-flex bd-highlight">
<div class="flex-fill bd-highlight">
<img src="https://placeimg.com/640/480/animals" alt="" id="img1">
</div>
<div class="flex-fill bd-highlight">
<img src="https://placeimg.com/640/480/nature" alt="" id="img2">
</div>
<div class="flex-fill bd-highlight">
<img src="https://placeimg.com/640/480/arch" alt="" id="img3">
</div>
</div>
</div>
Am using bootstrap framework to align the images.
Just add this css
.flex-fill{
display:inline-block;
width:33%;
}
img:not(:hover) {
transition: none;
}

change src image on hover using css

2 image appear in same time, up and down.
I want hover image display none.
Hover image is appear below primary image.
Primary image is hide when hover.
Seems like dont work. and really need help on this.
.card-img-top {
border-radius: 0;
height: 250px;
width: 100%;
top: 50%;
left: 50%;
transform: translate(0%, 0%);
object-fit: cover;
margin-bottom: 20px;
}
.card a img {
display: block;
}
.card a:hover img:first-child {
display: none;
}
<div class="card col-12 col-md-6 col-sm-12 col-lg-6 col-xl-4">
<a href="#">
<img class="card-img-top" src="images/True Blue Asia.jpg"/>
<img class="card-img-top" src="images/Asia Bagus.jpg"/>
<div class="card-img-overlay d-table-cell align-middle">
<p>true blue asia</p>
</div>
<div class="card-body">
<div class="row">
<div class="col-12 col-md-3">
<div class="card-date">Oct 2019</div>
</div>
<div class="col-12 col-md-9">
<div class="card-title">Roots, Heritage, Authenticity</div>
<div class="card-content">Asia’s myriad cultures manifest in practices derived from traditional value systems.</div>
</div>
</div>
</div>
</a>
</div>
<div class="card">
<img src="/image_displayed_as_default" class="hover-hidden"/>
<img src="/image_displayed_when_hover" class="hover-only"/>
</div>
.card img {
opacity: 1;
transition: opacity 200ms;
}
.card:hover img.hover-hidden,
.card:not(:hover) img.hover-only {
opacity: 0;
}
You are looking for this
Pure CSS solution
#aks {
width:0px;
height:0px;
background:url('http://dummyimage.com/100x100/000/fff');
padding:50px;
}
#aks:hover {
background: url('http://dummyimage.com/100x100/eb00eb/fff');
}
<img id="aks" src="http://dummyimage.com/100x100/000/fff"/>
Your code solution
Issue i you are not hide second image initially
.card-img-top {
border-radius: 0;
height: 250px;
width: 100%;
top: 50%;
left: 50%;
transform: translate(0%, 0%);
object-fit: cover;
margin-bottom: 20px;
}
.card a img {
display: block;
}
.card a:hover img:first-child {
display: none;
}
.card a .card-img-below{
display: none;
}
.card a:hover .card-img-below {
display: block;
}
a{
display:block;
}
<div class="card col-12 col-md-6 col-sm-12 col-lg-6 col-xl-4">
<a href="#">
<img class="card-img-above" src="https://cdn4.iconfinder.com/data/icons/imoticons/105/imoticon_15-128.png"/>
<img class="card-img-below" src="https://cdn4.iconfinder.com/data/icons/imoticons/105/imoticon_12-128.png"/>
<div class="card-img-overlay d-table-cell align-middle">
<p>true blue asia</p>
</div>
<div class="card-body">
<div class="row">
<div class="col-12 col-md-3">
<div class="card-date">Oct 2019</div>
</div>
<div class="col-12 col-md-9">
<div class="card-title">Roots, Heritage, Authenticity</div>
<div class="card-content">Asia’s myriad cultures manifest in practices derived from traditional value systems.</div>
</div>
</div>
</div>
</a>
</div>
Change the image url

Hiding overflow on a column with gutters

I am trying to set up a grid of thumbnails for blog posts using Bootstrap 4.
The size of the columns are col-md-6. Inside each of the columns is an anchor with a background photo, and a black -> transparent gradient overlay.
It all works fine, however, the gradient overlay is expanding past the width of the container, as you can see from the image below.
Markup:
<div class="container homeSection">
<div class="row">
<div class="col-md-6 dualBlogCallout">
<a href="#">
<div class="img-holder border-radius-15">
<div class="dualGradient"></div>
<img src="assets/img/beachPlaceholder.png" class="img-fluid w-100" alt="Blog Alt"/>
</div>
</a>
</div>
<div class="col-md-6 dualBlogCallout">
<a href="#">
<div class="img-holder border-radius-15">
<div class="dualGradient"></div>
<img src="assets/img/beachPlaceholder.png" class="img-fluid w-100" alt="Blog Alt"/>
</div>
</a>
</div>
</div>
</div>
CSS:
.dualBlogCallout{
color: white;
position: relative;
width: 100%;
bottom: 0;
left: 0;
z-index: 5;
}
.dualBlogCallout a{
overflow: hidden;
}
.dualGradient{
background-image: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,1));
position: absolute;
left: 0;
bottom: 0;
opacity: 1;
width: 100%;
height: 300px;
pointer-events: none;
z-index: 1;
}
Here is my desired result:
How can I get the absolutely positioned gradient to just remain within anchor with no overflow, and without using bootstrap 4 no-gutter class?
Add a rule in your css:
.img-holder { position: relative; }
I think your issue is that .dualGradient is positioned absolutely, but the nearest parent that has a position set is the .dualBlogCallout.
By default, anything that has position: absolute will traverse up the markup to find the nearest element that has a position explicitly set.
position: relative; is missing on your img-holder class. Here is a solution displaying your code.
Note: I added the border radius class because that was not included in the original post
.img-holder {
position: relative;
}
.dualBlogCallout{
color: white;
position: relative;
width: 100%;
bottom: 0;
left: 0;
z-index: 5;
}
.dualBlogCallout a{
overflow: hidden;
}
.dualGradient{
background-image: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,1));
position: absolute;
left: 0;
bottom: 0;
opacity: 1;
width: 100%;
height: 300px;
pointer-events: none;
z-index: 1;
}
.border-radius-15 {
border-radius: 15px;
overflow: hidden;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container homeSection">
<br><br>
<div class="row">
<div class="col-md-6 dualBlogCallout">
<a href="#">
<div class="img-holder border-radius-15">
<div class="dualGradient"></div>
<img src="https://via.placeholder.com/200x100" class="img-fluid w-100" alt="Blog Alt"/>
</div>
</a>
</div>
<div class="col-md-6 dualBlogCallout">
<a href="#">
<div class="img-holder border-radius-15">
<div class="dualGradient"></div>
<img src="https://via.placeholder.com/200x100" class="img-fluid w-100" alt="Blog Alt"/>
</div>
</a>
</div>
</div>
</div>

Putting Text Over an Image in Multi-Item-Carousel in Bootstrap 3

I have a multi-item bootstrap carousel and I want to put text in certain parts of the images in this carousel. Here is a CodePen of what I have. Currently, the text will show only when the image is the first one listed. As you can see when you go right once the streamer text appears on the first image, then if you proceed to go back left the text disappears and stays only on the first image.
HTML:
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="carousel slide multi-item-carousel" id="theCarousel">
<div class="carousel-inner">
<div class="item active">
<div class="col-xs-4"><img src="http://placehold.it/200x110/f44336/000000" class="image img-thumbnail img-responsive"></div>
<div class="image-content">Streamer</div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/200x110/f44336/000000" class="image img-thumbnail img-responsive"></div>
<div class="image-content">Streamer</div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/200x110/f44336/000000" class="image img-thumbnail img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/200x110/673ab7/000000" class="image img-thumbnail img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/200x110/4caf50/000000" class="image img-thumbnail img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/200x110/8bc34a/000000" class="image img-thumbnail img-responsive"></div>
</div>
</div>
<a class="left carousel-control" href="#theCarousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
<a class="right carousel-control" href="#theCarousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body>
CSS:
.multi-item-carousel {
width: 100%;
height: 100%;
font-size: 25px;
}
.multi-item-carousel .carousel-inner > .item {
transition: 500ms ease-in-out left;
}
.multi-item-carousel .carousel-inner .active.left {
left: -33%;
}
.multi-item-carousel .carousel-inner .active.right {
left: 33%;
}
.multi-item-carousel .carousel-inner .next {
left: 33%;
}
.multi-item-carousel .carousel-inner .prev {
left: -33%;
}
#media all and (transform-3d), (-webkit-transform-3d) {
.multi-item-carousel .carousel-inner > .item {
transition: 500ms ease-in-out left;
transition: 500ms ease-in-out all;
backface-visibility: visible;
transform: none!important;
}
}
.multi-item-carousel .carousel-control.left,
.multi-item-carousel .carousel-control.right {
width: 5%;
background-image: none!important;
filter: none!important;
outline: none!important;
border: 0;
}
.container {
width: 100%;
}
.carousel {
padding: 20px 70px;
}
.image {
border: 0;
outline: none;
background: transparent;
}
.image-content {
top: 5px;
left: 21px;
position: absolute;
color: rgb(225, 225, 225);
font-size: 11px;
}
body {
background-color: transparent;
}
If you want the text to appear on certain images, you must put the div containing the the text inside of the col in which you are placing your image. Check if this is what you are trying to acheive.
// Instantiate the Bootstrap carousel
$('.multi-item-carousel').carousel({
interval: false
});
// for every slide in carousel, copy the next slide's item in the slide.
// Do the same for the next, next item.
$('.multi-item-carousel .item').each(function () {
var next = $(this).next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone().appendTo($(this));
if (next.next().length > 0) {
next.next().children(':first-child').clone().appendTo($(this));
} else {
$(this).siblings(':first').children(':first-child').clone().appendTo($(this));
}
});
.multi-item-carousel {
width: 850px;
height: 150px;
font-size: 25px;
}
.multi-item-carousel .carousel-inner > .item {
transition: 500ms ease-in-out left;
}
.multi-item-carousel .carousel-inner .active.left {
left: -33%;
}
.multi-item-carousel .carousel-inner .active.right {
left: 33%;
}
.multi-item-carousel .carousel-inner .next {
left: 33%;
}
.multi-item-carousel .carousel-inner .prev {
left: -33%;
}
#media all and (transform-3d), (-webkit-transform-3d) {
.multi-item-carousel .carousel-inner > .item {
transition: 500ms ease-in-out left;
transition: 500ms ease-in-out all;
backface-visibility: visible;
transform: none!important;
}
}
.multi-item-carousel .carousel-control.left,
.multi-item-carousel .carousel-control.right {
width: 5%;
background-image: none!important;
filter: none!important;
outline: none!important;
border: 0;
}
.container {
width: 100%;
}
.carousel {
padding: 20px 70px;
}
.image {
border: 0;
outline: none;
background: transparent;
}
.image-content {
top: 5px;
left: 21px;
position: absolute;
color: rgb(225, 225, 225);
font-size: 11px;
}
body {
background-color: black;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="carousel slide multi-item-carousel" id="theCarousel">
<div class="carousel-inner">
<div class="item active">
<div class="col-xs-4"><img src="http://placehold.it/200x110/f44336/000000" class="image img-thumbnail img-responsive">
<div class="image-content">Streamer</div>
</div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/200x110/f44336/000000" class="image img-thumbnail img-responsive">
<div class="image-content">Streamer</div>
</div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/200x110/f44336/000000" class="image img-thumbnail img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/200x110/673ab7/000000" class="image img-thumbnail img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/200x110/4caf50/000000" class="image img-thumbnail img-responsive"></div>
</div>
<div class="item">
<div class="col-xs-4"><img src="http://placehold.it/200x110/8bc34a/000000" class="image img-thumbnail img-responsive"></div>
</div>
</div>
<a class="left carousel-control" href="#theCarousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
<a class="right carousel-control" href="#theCarousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a>
</div>
</div>
</div>
</div>
Please try using put text separate div to col-xs-4 div it will be display you content each time like:
<div class="item active">
<div class="col-xs-4">
<a href="#1">
<img src="http://placehold.it/200x110/f44336/000000" class="image img-thumbnail img-responsive">
</a>
<!-- here-->
<div class="image-content">Streamer</div>
<!-- -->
</div>
<!--<div class="image-content">Streamer</div>-->
</div>

Portfolio hover overlay not staying in image size

For my portfolio site I am making I have it so when you hover over the portfolio image it overlays the title and category. My problem is the overlay section is picking up the margin and padding for the spacing of the images in the grid. I cant get it to be whatever the portfolio image size is without removing the gutter between the images.
Example below:
Not sure how to fix this and any help would be appreciated.
.thumbnail {
padding: 0px !important;
margin-bottom: 25px;
border: none;
border-radius: 0;
display: block;
}
.thumbnail img {
width: 100%;
height: 100%;
margin-bottom: 0px;
display: block;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
padding: 0px 0px 0px 0px;
transition: .5s ease;
background-color: rgba(136, 24, 38, 0.6);
}
.thumbnail:hover .overlay {
opacity: 1;
height: 100%;
width: 100%;
}
.text {
color: white;
font-size: 20px;
position: absolute;
width: 70%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<section id="work" class="bg-grey">
<div class="container-fluid text-center">
<h2>MY WORK</h2>
<!--<h4>What we have created</h4>-->
<div class="row text-center">
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="http://www.google.com/">
<div class="thumbnail">
<img src="images/portfolio-img1.jpg" alt="PORTFOLIO NAME">
<div class="overlay">
<div class="text">
<h4>PORTFOLIO NAME</h4>
<p>category</p>
</div>
</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="http://www.google.com/">
<div class="thumbnail">
<img src="images/portfolio-img1.jpg" alt="PORTFOLIO NAME">
<div class="overlay">
<div class="text">
<h4>PORTFOLIO NAME</h4>
<p>category</p>
</div>
</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="http://www.google.com/">
<div class="thumbnail">
<img src="images/portfolio-img1.jpg" alt="PORTFOLIO NAME">
<div class="overlay">
<div class="text">
<h4>PORTFOLIO NAME</h4>
<p>category</p>
</div>
</div>
</div>
</a>
</div>
</div>
</div>
</section>
When you use a absolute positioned element, always set the respective relative, position element. Let me know if you have any issues with the output.
The only CSS change is to the below class. Where I have added the property position: relative.
.thumbnail {
padding: 0px !important;
position: relative;
margin-bottom: 25px;
border: none;
border-radius: 0;
display: block;
}
So your absolute positioned div with class overlay will be positioned with respect to the div with class thumbnail
.thumbnail {
padding: 0px !important;
position: relative;
margin-bottom: 25px;
border: none;
border-radius: 0;
display: block;
}
.thumbnail img {
width: 100%;
height: 100%;
margin-bottom: 0px;
display: block;
}
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
height: 100%;
width: 100%;
opacity: 0;
padding: 0px 0px 0px 0px;
transition: .5s ease;
background-color: rgba(136, 24, 38, 0.6);
}
.thumbnail:hover .overlay {
opacity: 1;
height: 100%;
width: 100%;
}
.text {
color: white;
font-size: 20px;
position: absolute;
width: 70%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<section id="work" class="bg-grey">
<div class="container-fluid text-center">
<h2>MY WORK</h2>
<!--<h4>What we have created</h4>-->
<div class="row text-center">
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="http://www.google.com/">
<div class="thumbnail">
<img src="http://lorempixel.com/100/100/" alt="PORTFOLIO NAME">
<div class="overlay">
<div class="text">
<h4>PORTFOLIO NAME</h4>
<p>category</p>
</div>
</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="http://www.google.com/">
<div class="thumbnail">
<img src="http://lorempixel.com/100/100/" alt="PORTFOLIO NAME">
<div class="overlay">
<div class="text">
<h4>PORTFOLIO NAME</h4>
<p>category</p>
</div>
</div>
</div>
</a>
</div>
<div class="col-md-4 col-sm-6 col-xs-12">
<a href="http://www.google.com/">
<div class="thumbnail">
<img src="http://lorempixel.com/100/100/" alt="PORTFOLIO NAME">
<div class="overlay">
<div class="text">
<h4>PORTFOLIO NAME</h4>
<p>category</p>
</div>
</div>
</div>
</a>
</div>
</div>
</div>
</section>