change src image on hover using css - html

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

Related

How to align images in one row?

I am trying to align images in one row but it doesn't seem to be working. I have tried flex but the last logo is still on another row.
<section id="clients" class="clients clients">
<div class="container">
<div class="row content">
<div class="col-3">
<img src="logo1" class="img-fluid srl" alt="">
</div>
<div class="col-3">
<img src="logo2" class="img-fluid" alt="">
</div>
<div class="col-3">
<img src="logo3" class="img-fluid" alt="">
</div>
<div class="col-3">
<img src="logo4" class="img-fluid" alt="">
</div>
<div class="col-2">
<img src="logo5" class="img-fluid" alt="">
</div>
</div>
</div>
.clients {
background: #f3f9fd;
padding: 0px 0px;
text-align: center;
}
.clients .col-lg-2 {
display: flex;
align-items: center;
justify-content: center;
}
.clients img {
width: 70%;
-webkit-filter: grayscale(100);
filter: grayscale(100);
transition: all 0.4s ease-in-out;
display: inline-block;
padding: 10px 0;
}
.clients img:hover {
-webkit-filter: none;
filter: none;
transform: scale(1.1);
}
As you can see the last logo is in its own row but I want it to be on the same row as the rest of them but i cant seem to do this?
Thanks
Your idea was flawed in using col-3
bootstrap grid system is divided into 12 spaces
col-1 uses 1 space
col-2 uses 2 spaces
an so on
Your images all have col-3 and there is 5 of them which is taking 15 "spaces" which is more than 12 thats why last element is moved down.
When you check bootstrap documentation for grid system you will find that you don't have to speciy how many spaces col needs to take.
You can use .col which will take as many width as it need for all elements to fill whole parent element
.clients {
background: #f3f9fd;
padding: 0px 0px;
text-align: center;
}
.clients .col {
display: flex;
align-items: center;
justify-content: center;
}
.clients img {
width: 70%;
/* just for presentation*/ min-height: 50px;
/* just for presentation*/ background-color: red;
-webkit-filter: grayscale(100);
filter: grayscale(100);
transition: all 0.4s ease-in-out;
display: inline-block;
padding: 10px 0;
}
.clients img:hover {
-webkit-filter: none;
filter: none;
transform: scale(1.1);
}
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<section id="clients" class="clients clients">
<div class="container">
<div class="row content">
<div class="col">
<img src="logo1" class="img-fluid srl" alt="">
</div>
<div class="col">
<img src="logo2" class="img-fluid" alt="">
</div>
<div class="col">
<img src="logo3" class="img-fluid" alt="">
</div>
<div class="col">
<img src="logo4" class="img-fluid" alt="">
</div>
<div class="col">
<img src="logo5" class="img-fluid" alt="">
</div>
</div>
</div>
</section>

How to vertically fix navigation arrows?

I have a modal album which shows images with different sizes. My pbolem is that how to style the navigation arrows, so that they appear at the middle of the page, no matter what is the size of the image. Here is my code:
<div class="row img-box">
<div class="col-1">
<span #click="nextImg(-1)" class="nav-arrow">❮</span>
</div>
<div class="col-9">
<h1>Modal comes here</h1>
<img class="img-fluid modal-img" :src=" getImgUrl(currentMediaUrl)">
</div>
<div class="col-1">
<span #click="nextImg(1)" class="nav-arrow">❯</span>
</div>
</div>
And here is the relevant css:
.modal-img {
max-height: 1080px;
}
.img-box {
display: flex;
align-items:center;
}
.nav-arrow {
font-size: 3em;
position: absolute;
top: 50%;
}
But whatever I tweak the CSS can not get the desired effect. Hence the question.
Use position fixed
.modal-img {
max-height: 1080px;
}
.img-box {
display: flex;
align-items:center;
justify-content: center;
}
.nav-arrow {
font-size: 3em;
position: fixed;
top: 120px;
}
.nav-left {
left: 10px;
}
.nav-right {
right: 10px;
}
<div class="row img-box">
<div class="col-1">
<span #click="nextImg(-1)" class="nav-arrow nav-left">❮</span>
</div>
<div class="col-9">
<h1>Modal comes here</h1>
<img class="img-fluid modal-img" src="https://via.placeholder.com/500C/O https://placeholder.com/">
</div>
<div class="col-1">
<span #click="nextImg(1)" class="nav-arrow nav-right">❯</span>
</div>
</div>
you need to apply transform: translateY(-50%) on arrow container's, in order to put the arrows in the center.
.nav-arrow {
font-size: 3em;
position: absolute;
top: 50%;
transform: translateY(-50%)
}
or simply, remove position: absolute; top: 50%;
Does this works for you? I have added the bootstrap class align-items-center and some padding to spans
.modal-img {
max-height: 1080px;
}
.nav-arrow {
font-size: 3em;
position: relative;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row img-box align-items-center">
<div class="col-1 ">
<span #click="nextImg(-1)" class="nav-arrow pt-5 d-inline-block">❮</span>
</div>
<div class="col-9 text-center">
<h1>Modal comes here</h1>
<img class="img-fluid modal-img" src="https://via.placeholder.com/100/O https://placeholder.com/">
</div>
<div class="col-1">
<span #click="nextImg(1)" class="nav-arrow pt-5 d-inline-block">❯</span>
</div>
</div>

image hover effect all at the same time

I have an all css and bootstrap hover effect, the overlay tags are all encased in a div class but all of them hover at the same time. all three have separate bootstrap grids and the effect even extends to the empty space in between the photos. any help would be appreciated thank you.
HTML:
<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">
<a href="cards/list.php?tn=beauty">
<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">
<div class="spacer overlay-text">BEAUTY</div>
</div>
</div>
</a>
</div>
<div class="col-md-4 col-xs-12">
<a href="cards/list.php?tn=health">
<img class="img-responsive" src="img/_stock_mwc_health.jpg">
<div class="overlay">
<div class="overlay-content">
<img src="img/icon-health-white.png" class="img-responsive center-block">
<div class="spacer overlay-text">HEALTH</div>
</div>
</div>
</a>
</div>
<div class="col-md-4 col-xs-12">
<a href="cards/list.php?tn=wellness">
<img class="img-responsive" src="img/_stock_mwc_wellness.jpg">
<div class="overlay">
<div class="overlay-content">
<img src="img/icon-wellness-white.png" class="img-responsive center-block">
<div class="spacer overlay-text">WELLNESS</div>
</div>
</div>
</a>
</div>
</div>
</div>
CSS:
.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;
}
here is my js fiddle for more info, i just added random placeholder images: http://jsfiddle.net/cnkgqhdw/1/
Don't do the hover on the container, do it on the columns! Just change .container:hover to .col-md-4:hover.
To keep the space correct, you can use bootstrap own spacing system. In your case, you can put a default margin around by adding the class mx-3 to the overlay element.
.overlay {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
opacity: 0;
transition: .5s ease;
background-color: #f3a64c;
}
.col-md-4:hover .overlay {
opacity: 1;
}
.overlay-content {
color: white;
font-size: 30px;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
text-align: center;
}
.exact-center {
text-align: center;
vertical-align: middle;
}
.spacer {
margin: 20px 0px 20px 0px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<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 mx-3">
<div class="overlay-content">
<img src="img/icon-beauty-white.png" class="img-responsive center-block">
<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 class="overlay mx-3">
<div class="overlay-content">
<img src="img/icon-health-white.png" class="img-responsive center-block">
<div class="spacer overlay-text">HEALTH</div>
</div>
</div>
</div>
<div class="col-md-4 col-xs-12">
<img class="img-responsive" src="img/_stock_mwc_wellness.jpg">
<div class="overlay mx-3">
<div class="overlay-content px-3">
<img src="img/icon-wellness-white.png" class="img-responsive center-block">
<div class="spacer overlay-text">WELLNESS</div>
</div>
</div>
</div>
</div>
</div>
You have it setup to :hover on the .container element, which is the entire row. Need to add a class to your card and do .card:hover
You are hovering on the whole container. So that's why everything gets the hover state.
You should add a class to the
<a class="item" href="">
and hover that:
.item:hover {
//styling here
}

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>

Bootstrap Add Space between Columns

I have closely followed the most popular example of how to add space between columns, but it doesn't work. You can view it in action at
codepen.io
What I've done is put a col-sm-12 inside of a col-sm-4 for each column. According to the most popular answer here this should automatically render some space between the 2 divs.
HTML:
<div class="row blocks-grid">
<div class="col-xs-6 col-sm-4 item">
<div class="col-sm-12">
<img src="http://example.com/1MBVDF4">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4 item">
<div class="col-sm-12">
<img src="http://example.com/1MBVDF4">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4 item">
<div class="col-sm-12">
<img src="http://example.com/1MBVDF4">
<h2>This is me</h2>
</div>
</div>
</div>
CSS:
body {
background: #BEB7A4;
}
.blocks-grid {
max-width:75.0rem;
margin:0 auto;
.item {
cursor: pointer;
margin-bottom:1rem;
position:relative;
height:34.0rem;
padding-top:2.5rem;
background:#FFFFFC;
&:hover {
background:#FF0000;
color:white;
img {
display:none;
}
}
h2 {
font-size:2.0rem;
margin-top:1rem;
text-align: center;
}
img {
max-width: 100%;
margin:auto;
display:block;
}
}
}
Basically, I would think the result would look like the following photo, but it does not:
you can try this: Demo
Add your "item" class with "col-sm-12"
body {
background: #BEB7A4;
}
I made some changes on your code.
HTML
Note the subitem class added to col-sm-12 divs.
<div class="row blocks-grid">
<div class="col-sm-4 item">
<div class="col-sm-12 subitem">
<img src="image_url">
<h2>This is me</h2>
</div>
</div>
<div class="col-sm-4 item">
<div class="col-sm-12 subitem">
<img src="image_url">
<h2>This is me</h2>
</div>
</div>
<div class="col-sm-4 item">
<div class="col-sm-12 subitem">
<img src="image_url">
<h2>This is me</h2>
</div>
</div>
</div>
LESS
body {
background: #BEB7A4;
}
.blocks-grid {
max-width:75.0rem;
margin:0 auto;
.item {
cursor: pointer;
margin-bottom:1rem;
position:relative;
height:34.0rem;
padding-top:2.5rem;
.subitem {
background:#FFFFFC;
height: 100%;
padding-top: 50px;
&:hover {
background:#FF0000;
color:white;
img {
display:none;
}
}
h2 {
font-size:2.0rem;
margin-top:1rem;
text-align: center;
}
img {
max-width: 100%;
margin:auto;
display:block;
}
}
}
}
Take a look: http://codepen.io/anon/pen/KgzVRK
Hope it can helps you.
You can actually remove all the extra junk and let bootstrap do it for you... NEVER change margins / widths on the framework. This is all you need....
HTML
<div class="row">
<div class="col-xs-6 col-sm-4">
<img src="http://placehold.it/350x250">
<h2>This is me</h2>
</div>
<div class="col-xs-6 col-sm-4">
<img src="http://placehold.it/350x150">
<h2>This is me</h2>
</div>
<div class="col-xs-6 col-sm-4">
<img src="http://placehold.it/350x150">
<h2>This is me</h2>
</div>
</div>
CSS
img { width: 100%; }
You may try to move the class item from col-xs-6 to col-sm-12
The snippet:
body {
background: #BEB7A4;
}
.blocks-grid {
max-width: 75.0rem;
margin: 0 auto;
}
.blocks-grid .item {
cursor: pointer;
margin-bottom: 1rem;
position: relative;
height: 34.0rem;
padding-top: 2.5rem;
background: #FFFFFC;
}
.blocks-grid .item:hover {
background: #FF0000;
color: white;
}
.blocks-grid .item:hover img {
display: none;
}
.blocks-grid .item h2 {
font-size: 2.0rem;
margin-top: 1rem;
text-align: center;
}
.blocks-grid .item img {
max-width: 100%;
margin: auto;
display: block;
}
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css'>
<style>
body {
background: #BEB7A4;
}
.blocks-grid {
max-width: 75.0rem;
margin: 0 auto;
}
.blocks-grid .item {
cursor: pointer;
margin-bottom: 1rem;
position: relative;
height: 34.0rem;
padding-top: 2.5rem;
background: #FFFFFC;
}
.blocks-grid .item:hover {
background: #FF0000;
color: white;
}
.blocks-grid .item:hover img {
display: none;
}
.blocks-grid .item h2 {
font-size: 2.0rem;
margin-top: 1rem;
text-align: center;
}
.blocks-grid .item img {
max-width: 100%;
margin: auto;
display: block;
}
</style>
</head>
<body>
<div class="row blocks-grid">
<div class="col-xs-6 col-sm-4">
<div class="col-sm-12 item">
<img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4">
<div class="col-sm-12 item">
<img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg">
<h2>This is me</h2>
</div>
</div>
<div class="col-xs-6 col-sm-4">
<div class="col-sm-12 item">
<img src="https://www.samhober.com/howtofoldpocketsquares/Flat1.jpg">
<h2>This is me</h2>
</div>
</div>
</div>
</body>