Hi so I'm quite new to programming and I have a basic knowledge in html and an even more basic knowledge of CSS. I've been trying to make images for my wordpress.com website that when hovered over by the cursor change to an overlay with text. I've managed to find some samples for what I want and I've gotten pretty close. The only thing I don't know how to do is make it so my image is also a hyperlink because currently all it has is the hover effect.
Here is my CSS code:
.container {
position: relative;
width: 400px;
}
.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: #008CBA;
}
.container:hover .overlay {
opacity: 1;
}
.projeto01 {
color: white;
font-size: 40px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
Here is my html code:
<div class="grid-portefolio">
<div class="container">
<img src="https://insert1australia.files.wordpress.com/2021/04/real-sinister-minister-14-250x250-1-1.png" class="image" alt="Albert Lee Banks Electorate"/>
<div class="overlay">
<div class="projeto01">Albert Lee<br>Banks Electorate</div>
</div>
</div>
So to summarize I want to know what to add to my code in either CSS or html to make it so the image also acts as a hyperlink to another page.
Just wrap everything inside an <a> tag, like this:
<div class="container">
<a href="https://example.com/"><img src="https://insert1australia.files.wordpress.com/2021/04/real-sinister-minister-14-250x250-1-1.png" class="image" alt="Albert Lee Banks Electorate"/>
<span class="overlay">
<span class="projeto01">Albert Lee<br>Banks Electorate</span>
</span>
</a>
</div>
I think it can help you.
.page-link {
position: relative;
width: 400px;
display: flex;
overflow: hidden;
}
.page-link img {
width: 100%!important;
height: auto;
transform: scale(1);
transition: transform .4s ease;
}
.projeto01 {
color: white;
font-size: 40px;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(0, 135, 186, .6);
opacity: 0;
transition: opacity .4s ease;
}
.page-link:hover {
cursor: pointer;
}
.page-link:hover img {
transform: scale(1.1);
}
.page-link:hover .projeto01 {
opacity: 1;
}
<div class="grid-portefolio">
<a class="page-link" href="https://www.example.com">
<img src="https://insert1australia.files.wordpress.com/2021/04/real-sinister-minister-14-250x250-1-1.png" alt="Albert Lee Banks Electorate"/>
<div class="projeto01">Albert Lee<br>Banks Electorate</div>
</a>
Related
I want to have a hover animation that disappears when hovering over the picture and another picture takes its place, but the back picture isn't disappearing
I tried to use opacity 1 to go to 0, and transition time 0.5sec but it's stuck in the old position
.Menu .mnpic {
transform: translateX(30%);
/* display: flex;
justify-content: center;
align-content: center; */
}
.mnovly {
position: absolute;
top: 0;
}
.mwhite{
/* position: relative; */
opacity: 1;
transition: 0.5s;
}
.mwhite:hover {
opacity: 0;
}
.mblack{
opacity: 0;
transition: 0.5s;
}
.mblack:hover{
opacity: 1;
height: 200px;
}
<div class="mnpic">
<img calss="mwhite" src="menuwhite.png" alt="" height="150px">
<div class="mnovly">
<img class="mblack" src="menublack.png" alt="" height="150px">
</div>
</div>
This is happening because the front picture is always over the back picture so the .mwhite:hover never triggers, also you have a typo in your html, change that calss="mwhite" to class="mwhite"
I had to change your HTML and CSS styles to make it work, I placed the front picture always in front and used this CSS selector to activate when hovering on the front picture .mwhite:hover + .mblack
In the example I added a border and the images are not exactly over each other so the effect is more noticeable:
.Menu .mnpic {
transform: translateX(30%);
}
.mwhite{
opacity: 1;
transition: 0.5s;
border: 1px green solid;
position: absolute;
top: 0;
left: 0;
z-index: 10;
}
.mwhite:hover {
opacity: 0;
border: 1px blue solid;
}
.mblack{
border: 1px red solid;
opacity: 0;
transition: 0.5s;
}
.mwhite:hover + .mblack{
opacity: 1;
height: 200px;
}
<div class="mnpic">
<img class="mwhite" src='https://picsum.photos/200' alt="" height="150px">
<img class="mblack" src='https://picsum.photos/300' alt="" height="150px">
</div>
.hover {
width: 200px;
height: 200px;
background: url('https://picsum.photos/200') no-repeat center center;
position: relative;
}
.hover:after{
content: '';
display: block;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
background: url('https://picsum.photos/300') no-repeat center center;
opacity: 0;
transition: opacity .3s;
}
.hover:hover:after {
opacity: 1;
}
<div class="hover"></div>
I got some simple code to make text appear when I hover over an image, the problem I run into is that the hover hitbox is bigger than the image. I looked at my CSS and tried a lot but I can't find the right bit of code that I need to change.
CSS:
.container {
position: relative;
width: 50%;
}
.image {
opacity: 1;
display: block;
width: 30%;
height: 183px;
transition: .5s ease;
backface-visibility: hidden;
}
.middle {
transition: .5s ease;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
}
.container:hover .image {
opacity: 0.3;
}
.container:hover .middle {
opacity: 1;
}
.over_image_text {
background-color: #6552c7;
color: white;
font-size: 16px;
padding: 16px 32px;
}
html:
<div class='container'>
<img class="projects" src="../../images/spaceinvaders.jpg" alt="spaceinvaders"></a>
<div class="middle">
<div class="over_image_text">Read more about this project</div>
</div>
</div>
The code you are looking for is this class in your CSS:
.over_image_text {
background-color: #6552c7;
color: white;
font-size: 16px;
padding: 16px 32px;
}
The part which is interesting for you is the last line padding: 16px 32px;.
Try decreasing the pixel values to the size which would fit for you. If that's not enough, then you can also decrease the font-size here.
I need the title link to direct to a separate page.
Here is a snippet of my code.
<div class="img-container design" data-category="design">
<h3 class="pro2">Angular JS Sales List <a class="pro1" href="https://github.com/Daniel1836/Angular-JS-Project">Git Hub</a> </h3>
<img src="img/angular.png">
<a class="img-overlay" href="/portfolio/index2.html"></a>
<div class="img-overlay-text">
I've tried many combinations of ordering the code, but the link on the bottom is the one that both links redirect to, as if it is spanning the entire image length.
Thanks
Edit
Here is the relevant CSS. The code is not my own.
.img-container {
position: relative;
width: 30%;
margin: 10px;
height: auto; }
.img-container img {
border-radius: 10px; }
#media screen and (max-width: 760px) {
.img-container {
width: 100%; } }
.img-overlay {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(229, 46, 45, 0.3);
border-radius: 10px;
outline: 1px solid #fff;
outline-offset: -15px;
cursor: pointer;
-webkit-transition: all .3s ease-out;
-o-transition: all .3s ease-out;
transition: all .3s ease-out;
opacity: 0; }
.img-overlay:hover {
opacity: 1; }
.img-overlay-text {
position: inherit;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
color: #fff;
text-align: center; }
.img-overlay-text h3 {
margin: 0; }
.img-overlay-text p {
color: #fff; }
The second link should be like this:
<a class="img-overlay" href="/portfolio/index2.html">
<img src="img/angular.png" />
</a>
I'm trying to achieve a drop down cover effect (Not sure how it's really called) with the following code:
.new_events_list {
position: absolute;
width: 26%;
height: 28vh;
background-color: #323642;
cursor: pointer;
}
#new_events_list_effect {
background-color: #ee5f95;
width: 100%;
opacity: 0.5;
top: -100%;
transition: 0.5s;
}
div.new_events_list:hover #new_events_list_effect {
top: 0%;
transition: 0.5s;
}
div.new_events_list:hover img {
filter: grayscale(0.5);
transition: 1s;
}
<div class="new_events_list" style="overflow: hidden;border-radius: 10px;">
<img class="new_events_list" id="photo1" src="https://www.dpreview.com/files/p/articles/7395606096/Google-Photos.jpeg" alt="event_list_1" style=" object-fit: cover; width: 100%;border-radius: 10px;">
<div class="new_events_list" id="new_events_list_effect">
</div>
</div>
The problem that I'm facing is that once you hover over the photo the pink block drops down with the corners visible which only disappear after a second or so. Could anyone explain to me how I could possibly drop down the pink coloured div without the corners being visible?
Thank you very much for your help in advance.
The following code should work:
.new_events_list {
position: relative;
width: 26%;
backgorund-color: black;
border-radius: 10px;
overflow: hidden;
}
.image {
width: 100%;
}
.new_events_list_effect {
position: absolute;
height: 100%;
width: 100%;
background-color: #ee5f95;
opacity: 0.5;
top: -100%;
transition: 0.5s;
border-radius: 10px;
}
.new_events_list:hover .new_events_list_effect {
top: 0%;
transition: 0.5s;
}
<div class="new_events_list">
<img src="https://www.dpreview.com/files/p/articles/7395606096/Google-Photos.jpeg" class="image">
<div class="new_events_list_effect"></div>
</div>
I know this question has been asked before (here and here), but for some reason I can't get mine to work when using the same techniques. Basically when you hover over this,
You should get this:
By the way, if there's a simpler way to do this without loading a new image when hovering, please let me know.
Here's what I tried:
HTML
<div class="image">
<a href="#">
<img class="image" src="wp-content/themes/TheBullshitCollection/Images/bs-1.jpg">
</a>
</div>
CSS
.image {
width: 100%;
margin-right: 28px;
margin-bottom: 28px;
display: inline-block;
}
.image a:hover {
display:block;
background-image:url("/wp-content/themes/TheBullshitCollection/Images/bs-1.5.jpg");
margin-right:28px;
margin-bottom:28px;
transition: all 0.2s ease-in-out;
position: absolute;
z-index:1;
width: 100px;
height: 120px;
}
JS Fiddle Link:
https://jsfiddle.net/ot8a5oba/
You can see that the width and height is also confusing me - I'm not sure how to make sure it stays the same size, and that it appears on top. Thanks in advance!
I would do it like this using a pseudo element to apply an overlay. Simplifies things quite a bit.
.imageContainer a {
width: 100%;
display: inline-block;
position: relative;
}
.imageContainer a:after {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(139,69,19,0.5);
content: 'Buy';
display: flex;
justify-content: center;
align-items: center;
color: white;
font: 5em cursive;
opacity: 0;
transition: opacity .5s;
}
.imageContainer a:hover:after {
opacity: 1;
}
.imageContainer img {
max-width: 100%;
vertical-align: top;
}
/*
.image a:hover {
display: block;
background-image: url("http://i.imgur.com/ARiA0ua.jpg");
margin-right: 28px;
margin-bottom: 28px;
transition: all 0.2s ease-in-out;
position: absolute;
z-index: 1;
width: 100px;
height: 120px;
}
*/
<div class="imageContainer">
<a href="#">
<img class="image" src="http://i.imgur.com/F2PaGob.jpg">
</a>
</div>