Hover Box Color and Image Opacity - html

I have an image and text below it wrapped in one "a" tag. Hovering over the white box with text in it turns the box grey. Hovering over the image and it has an opacity effect.
How can I make the box turn grey and the image opacity happen at the same time when hovered over. At the moment these happen seperately. This is not a huge problem but it'd look better if they happened together.
Here's a screenshot - https://imgsafe.org/image/ef3964b27c
This is my HTML;
<div class="w3-third w3-container w3-margin-bottom">
<a href="#" style="display:block">
<img src="Images/MCR.png" style="width:100%" class="w3-hover-opacity">
<div class="w3-container w3-white">
<p><b>PSB2 and COM4</b></p>
<p><b> </b></p>
</div>
</a>
</div>

Since your snippet is different from the image you provided, I created a simple snippet that changes the opacity of the image and changes the border color (if that is what you mean by box) to gray
.wrapper {
height: 200px;
width: 250px;
border: 3px solid green;
}
.wrapper:hover {
border: 3px solid gray;
}
.wrapper:hover img {
opacity: 0.5;
}
<div class="wrapper">
<a href="#">
<img src="http://via.placeholder.com/250x150" />
</a>
</div>

Try This:
.w3-third {
border: 5px solid lightgreen;
display: inline-block;
position: relative;
text-align: center;
}
p {
margin: 0;
}
a {
color: #000;
text-decoration: none;
}
.w3-third:hover .w3-white {
background-color: gray;
}
.w3-third:hover img {
opacity: 0.2;
}
<div class="w3-third w3-container w3-margin-bottom">
<a href="#" style="display:block"><img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQEnn9dYYZlciBKfaHCw17-dUgRPX3nq5_6-kV1ua-LIsId5g43uA">
<div class="w3-container w3-white">
<p><b>PSB2 and COM4</b></p>
<p><b> </b></p>
</div></a>
</div>

now try this one with edited code
.w3-white {
margin-top: -20px;
width: 40%;
}
.w3-container:hover img {
opacity: 0.5;
}
.w3-container:hover .w3-white {
background-color: grey;
}
<div class="w3-third w3-container w3-margin-bottom">
<a href="#" style="display:block"><img src="http://webneel.com/daily/sites/default/files/images/daily/09-2013/1-diwali-greetings.preview.jpg" style="width:40%" class="w3-hover-opacity">
<div class="w3-container w3-white">
<p><b>PSB2 and COM4</b></p>
<p><b> </b></p>
</div>
</a>
</div>

Try to put you image and text into a single container and add simple transition. check below snippet.
.img-container {
width: 250px;
border: 2px solid blue;
}
.img-container p {
padding: 10px 0;
margin:0;
transition: all 0.5s ease;
}
.img-container img{
transition: all 0.5s ease;
}
.img-container:hover img {
opacity: 0.5;
}
.img-container:hover p {
background-color: grey;
}
<div class="img-container">
<a href="#">
<img src="http://via.placeholder.com/250x150" />
<p>Some text</p>
</a>
</div>

Related

css3 transform width hover do not working?

I'm trying to animate the width of the span inside the an of this link.
The same demo: https://www.khaneyeax.com/en
.lang {
background-color: rgba(255,255,255,0.1);
left: -130px;
top: 400px;
}
.lang a {
padding: 10px;
color: black;
max-width: 0;
display: block;
overflow: hidden;
white-space: nowrap;
transition: max-width 1s ease-in-out;
}
.lang a:hover {
width: 300px;
max-width: 300px;
}
<div id="left">
<img src="https://via.placeholder.com/150">
<div class="position-fixed lang">
Language Persian FA
<a class="english">Language English EN</a>
<a class="search"><i class="fas fa-search"></i> Advanced Search </a>
</div>
</div>

How can I overlap an image with text, but both of them are inside the same anchor tag?

I'm kind of new to css and html, never touched JS or jquery.
I'm building as practice a website that looks like somewhat a portfolio site where I have some photos that are clickable. One thing that I wanted to do is, when a user hovers an image, an opaque box would pop up from the photo's bottom showing some text, the problem is that I want this text to be clickable as well so I put it inside the same anchor tag, but they don't overlap instead the clickable area stretches and the text gets positioned to the side of the image.
Is there a way of doing it so the "clickable area" doesn't stretch and the text overlap the image but without using the image as a background ?
Here's what I'm trying to achieve https://theme-frsch2.tumblr.com/ .
I've tried wrapping the text in a div and moving the text so it would overlap the image but the problem is that the "clickable" area would still be stretched anyway.
And this is what I got so far.
HTML
#allimg{
display: flex;
flex-wrap: wrap;
justify-content: center;
}
#allimg a{
margin: 10px;
border: 2px solid red;
}
#allimg img{
transition: 0.1s ease;
box-shadow: 5px 5px 10px #888888;
float: left;
border: 1px solid pink;
}
#allimg img:hover{
transform: scale(1.02);
}
#allimg a p{
color: black;
position: relative;
bottom: 20px;
left: 0;
text-align: center;
}
<div id="allimg">
<a href="link1">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text1
</p>
</a>
<a href="link2">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text2
</p>
</a>
<a href="link3">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text3
</p>
</a>
<a href="link4">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text4
</p>
</a>
</div>
Here is jsfiddel link
If you want to overlap text inside an image and achieve that hover effect on the website you attached
you have to use position: absolute for your text
and set the position for your anchor tag to relative
make it hideen by setting visibility property to hidden and opacity
to 0
then on anchor tag hover, you set it back visible and 1 opacity
#allimg{
display: flex;
flex-wrap: wrap;
justify-content: center;
}
#allimg a{
margin: 10px;
border: 2px solid red;
position: relative;
}
#allimg img{
transition: 0.1s ease;
box-shadow: 5px 5px 10px #888888;
float: left;
border: 1px solid pink;
}
#allimg img:hover{
transform: scale(1.02);
}
#allimg a p{
color: black;
position: absolute;
bottom: 0;
left: 0;
margin: 0;
text-align: center;
width: 100%;
padding: 10px 0;
background: rgba(255,255,255,.5);
visibility: hidden;
opacity: 0;
transition: .2s ease-in-out;
}
#allimg a:hover p{
visibility: visible;
opacity: 1
}
<div id="allimg">
<a href="link1">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text1
</p>
</a>
<a href="link2">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text2
</p>
</a>
<a href="link3">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text3
</p>
</a>
<a href="link4">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text4
</p>
</a>
</div>
Put the image in parent container and text in child container, then in css file add 'position:relative' to the parent container and add 'position:absolute' to the child container.
This will overlap text and image.
Somewhat like this:
HTML Part:
<div class="parent">
<img src="https://via.placeholder.com/150" alt="image">
<div class="child">
<p>Text goes here</p>
</div>
</div>
CSS Part:
.parent
{
position:relative;
text-align:center;
}
.child
{
position:absolute;
top:0px;
left:0px;
}
This will overlap text on image and you make changes as you want in the position of the text.
Here's my solution with smooth transition.
#allimg{
display: flex;
flex-wrap: wrap;
justify-content: center;
}
#allimg a{
position: relative;
margin: 10px;
border: 2px solid red;
box-sizing: border-box;
transition: all 0.3s ease;
}
#allimg img{
position: abosolute;
vertical-align: bottom;
transition: 0.1s ease;
box-shadow: 5px 5px 10px #888888;
border: 1px solid pink;
transition: all 0.3s ease;
}
#allimg img:hover{
transform: scale(1.02);
}
#allimg a p{
margin: 0;
padding: 5% 0;
width: 100%;
color: black;
background-color: #fff;
box-sizing: border-box;
position: absolute;
text-align: center;
bottom: 0;
left: 0;
opacity: 0;
transition: all 0.3s ease;
}
#allimg a:hover{
transform: scale(1.1);
transition: all 0.3s ease;
}
#allimg a:hover p{
opacity: 1;
transition: all 0.6s ease;
}
<div id="allimg">
<a href="link1">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text1
</p>
</a>
<a href="link2">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text2
</p>
</a>
<a href="link3">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text3
</p>
</a>
<a href="link4">
<img src="https://via.placeholder.com/150" alt="">
<p>
Text4
</p>
</a>
</div>

Hover effect on image with text

I don't know how to make text in the photo, and make a link in the whole photo. I've made a darkening effect which I don't want to change, I just want to add text to it. I really want to keep the current dimensions and, above all, responsiveness.
There is link to codepen: 'https://codepen.io/pawe-dejda/pen/XyPzpK'
body, html {
height: 100%;
}
.caption {
position: absolute;
left: 0;
top: 50%;
width: 100%;
text-align: center;
color: #000;
}
.responsive {
width: 100%;
max-width: 88px;
height: auto;
position: center;
}
.tz-gallery .row > div {
padding: 2px;
margin-bottom: 4px;
}
.tz-gallery .lightbox img {
width: 100%;
border-radius: 0;
position: relative;
}
#media(max-width: 768px) {
body {
padding: 0;
}
}
.fade {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
}
.fade:hover {
opacity: 0.5;
}
<link rel="stylesheet" href="https://www.w3schools.com/w3css/3/w3.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="http://dejda.e-kei.pl/nuar/css/style.css">
<div class="w3-container w3-padding-64 w3-black">
<div class="w3-content">
<div class="tz-gallery">
<div class="row no-gutters">
<div class="col-sm-6 col-md-4">
<a class="lightbox fade" href="http://dejda.e-kei.pl/nuar/images/mieszkanie-w-kamienicy-lodz/mieszkanie-w-kamienicy-lodz5.jpg">
<img src="http://dejda.e-kei.pl/nuar/images/thumbnails/mieszkanie-w-kamienicy-lodz.jpg">
</a>
</div>
<div class="col-sm-6 col-md-4">
<a class="lightbox fade" href="http://dejda.e-kei.pl/nuar/images/mieszkanie-w-kamienicy-lodz/mieszkanie-w-kamienicy-lodz5.jpg">
<img src="http://dejda.e-kei.pl/nuar/images/thumbnails/mieszkanie-w-kamienicy-lodz.jpg">
</a>
</div>
<div class="col-sm-6 col-md-4">
<a class="lightbox fade" href="http://dejda.e-kei.pl/nuar/images/mieszkanie-w-kamienicy-lodz/mieszkanie-w-kamienicy-lodz5.jpg">
<img src="http://dejda.e-kei.pl/nuar/images/thumbnails/mieszkanie-w-kamienicy-lodz.jpg">
</a>
</div>
</div>
</div>
</div>
</div>
If i understand correctly, you want to be able to post links (link can be a-href, h1, h2, span etc') on top of your picture. To do so, do the following:
1. write a container div. for example:
<div>
text
</div>
set its style (CSS) to the background picture you want. Make sure the div's sizes fit the picture size. Then, inside the div you can simply write down the tag you wish (text). for example:
< span >
text
< /span >
Now things get interesting. In order to position the text inside the div? => set the div's position to relative (position:relative;) and set the span position to absolute. then play around with the top / left / bottom / right of the absoloute position, and text would appear whereever you want it to.
Here's an updated codepen
https://codepen.io/kelvinsusername/pen/YROYZM
It adds a container with some text in it but makes it opaque, then on hover instead of making it less visible (like the image) it makes it more visible.
.fade:hover .description {
opacity: 1;
}
.description {
position: absolute;
z-index: 100;
opacity: 0;
color: #fff;
font-size: 20px;
}
.tz-gallery .row>div {
padding: 2px;
margin-bottom: 4px;
}
.tz-gallery .lightbox img {
width: 100%;
border-radius: 0;
position: relative;
}
.img-text-box {
position: absolute;
bottom: 0;
background: rgba(0, 0, 0, 0.479);
color: #ffffff;
width: 100%;
padding: 20px;
font-family: Arial;
font-size: 17px;
}
.fade {
opacity: 1;
transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
color: #e9e9e9;
}
.fade:hover {
opacity: 0.5;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="tz-gallery">
<div class="container">
<div class="row">
<div class="col-md-4">
<a class="lightbox fade" href="">
<img src="http://dejda.e-kei.pl/nuar/images/thumbnails/mieszkanie-w-kamienicy-lodz.jpg" alt="">
<div class="img-text-box">
<p>Be brave js is cool</p>
</div>
</a>
</div>
<div class="col-md-4">
<a class="lightbox fade" href="">
<img src="http://dejda.e-kei.pl/nuar/images/thumbnails/mieszkanie-w-kamienicy-lodz.jpg" alt="">
<div class="img-text-box">
<p>Readability counts.</p>
</div>
</a>
</div>
<div class="col-md-4">
<a class="lightbox fade" href="">
<img src="http://dejda.e-kei.pl/nuar/images/thumbnails/mieszkanie-w-kamienicy-lodz.jpg" alt="">
<div class="img-text-box">
<p>If the implementation is hard to explain, it's a bad idea.</p>
</div>
</a>
</div>
</div>
</div>
</div>

when hover on image or text the both scale

i want when the user hover on the image or the text and the image scale.i have tried this but only one scale
.top3 , .top1 {
transition: all 1s ease;
}
.top3:hover ,.top1:hover {
transform: scale(1.17);
}
<div class="top3" id="DSC0123"><img src="images/DSC0123.png"></div>
<div class="top3" id="Layer4"><img src="images/Layer4.png"></div>
<div class="top3" id="DSC0416"><img src="images/DSC0416.png"></div>
<div class="top3" id="IMG0541"><img src="images/IMG0541.png"></div>
<div class="top3 top3" id="DSC0331"><img src="images/DSC03311.png"></div>
<div class="top1 top3" id="Food">Food</div>
<div class="top1 top3" id="portrait">Food</div>
<div class="top1 top3" id="LANSCAPES">Food</div>
<div class="top1 top3" id="kids">Food</div>
<div class="top1 top3" id="SPORTS">Food</div>
Use display on <a> and apply hover on <a>, like:
.top3 , .top1 {
transition: all 1s ease;
}
.top3 a, .top1 a {
display: inline-block;
transition: all 1s ease;
}
.top3:hover a ,.top1:hover a {
transform: scale(1.17);
transform-origin: center;
}
Have a look at the snippet below:
.top3 , .top1 {
transition: all 1s ease;
}
.top3 a, .top1 a {
display: inline-block;
transition: all 1s ease;
}
.top3 a:hover ,.top1 a:hover {
transform: scale(1.5);
transform-origin: center;
}
<div class="top3" id="DSC0123"><img src="images/DSC0123.png"></div>
<div class="top3" id="Layer4"><img src="images/Layer4.png"></div>
<div class="top3" id="DSC0416"><img src="images/DSC0416.png"></div>
<div class="top3" id="IMG0541"><img src="images/IMG0541.png"></div>
<div class="top3 top3" id="DSC0331"><img src="images/DSC03311.png"></div>
<div class="top1 top3" id="Food">Food</div>
<div class="top1 top3" id="portrait">Food</div>
<div class="top1 top3" id="LANSCAPES">Food</div>
<div class="top1 top3" id="kids">Food</div>
<div class="top1 top3" id="SPORTS">Food</div>
Hope this helps!
If I understand correctly, you want an image to scale up/down on hover, but not the text. You can do this without duplicating links and with fewer, more robust code. I've made an example to demonstrate, and added borders for ease. You can do whatever you like on hover, of course. I kept it simple.
a {
display: block;
width: 300px;
height: 300px;
border: solid 1px red;
}
a img {
width: 300px;
height: 200px;
}
a span {
width: 300px;
height: 100px;
border: solid 1px green;
}
a:hover {
width: 600px;
height: 600px;
}
a:hover span {
width 600px;
}
a:hover img {
width: 600px;
height: 500px;
}
<img src="http://img05.deviantart.net/c135/i/2011/134/7/0/bridge_by_kzonedd-d3gcetc.jpg" alt="old wooden bridge" /><span>text</span>
The user wants BOTH to scale (the img and the text)
You should put the text div inside the image div, like this:
<div class="top3" id="DSC0123">
<img src="http://www.w3schools.com/css/trolltunga.jpg" />
<div class="top1 top3" id="Food">
Food
</div>
</div>
https://jsfiddle.net/933ex7pv/2/ (working fiddle)
Add transform-origin: 0 0; (or some other values that you like) to make it scale in the center.

Displaying Image caption with only HTML and CSS

I am trying to display caption on images.
This is my HTML
<div class="image-hover">
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
<div class="image-block">
<a href="" target="_blank" class="image-overlay">
<div class="details">
<h4>Our philosophy and Vision</h4>
</div>
<div class="image-backdrop">
<img src="http://buildinternet.s3.amazonaws.com/projects/mosaic/omr-office.jpg"/>
</div>
</a>
</div>
</div>
This is my CSS :
.image-hover {
overflow: hidden;
}
.image-hover .image-block {
width: 234px;
height: 100px;
display: inline-block;
border: 1px solid #666666;
}
.image-hover .image-block img {
width: 230px;
height: 100px;
border: 2px solid #fff;
}
.details, .image-backdrop {
float: left;
}
.details h4:after {
display: inline-block;
content:" ";
width: 0;
height: 0;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-left: 8px solid #666666;
margin: 0 10px;
}
This is my JsFiddel
My problem is how can I get image's caption to above of image?
Any comments are greatly welcome.
Thank you.
you should use position:relative; to the container and position:absolute; to the child container whom you want to on image it is styled as you want
http://jsfiddle.net/ADMvd/2/
Add this to your CSS
.details h4 {
color: white; /* just to make it look pretty */
}
.details {
position: absolute;
}
.image-overlay {
position: relative;
}
DEMO
EDIT
Note that you are using div tag inside your a tag so don't forget to add display: block to your a.image-overlay tag because inline elements can't contain any other type of elements. It does work but will cause many weird problems.
For starters height:100% won't work for div inside a