Using transitions with span? [duplicate] - html

This question already has answers here:
Transitions on the CSS display property
(37 answers)
Closed 2 years ago.
I tried to show a centered text when I put my mouse over a image.
I found a way to do it with Span but then the Transition does not work.
Could someone help me with that ?
is there maybe an other way to make a "over centered txt" ?
here is the code:
body {
margin: 0;
padding: 0px;
overflow-x: hidden;
font-family: Arial, Helvetica, sans-serif;
background-color: #000000;
;
text-align: center;
}
#content {
padding-top: 71px;
transition-duration: 1s;
}
#content a {
width: 800px;
display: inline-block;
position: relative;
text-decoration: none;
transition: 1s
}
#content a img {
border: none;
width: 100%;
transition: 1s
}
#content a span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: none;
}
#content a:hover span {
display: block;
}
#content span.title {
display: none;
color: #FFF;
font-weight: bold;
font-size: 1.2em;
z-index: 2;
transition: 1s;
}
#content span.bg {
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
height: 100%;
width: 100%;
background: black;
transition: 1s;
opacity: 0.5;
}
<div id="content">
<a href="#">
<span class="title">Mon titre</span>
<span class="bg"></span>
<img src="B 1.jpg" alt="" />
</a>
</div>
<div id="footer">
</div>
Here is the source of the example that I used

As i know , you can not use transition over display property. why you do not use opacity instead??
do something like this
#content a span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
opacity : 0;
transition : opacity 1s ease-in-out;
}
#content a:hover span {
opacity:1;
}
and remove other display and transition.

Related

How to animate background-color on hovering from bottom to top and again from bottom to top [duplicate]

This question already has answers here:
Position absolute but relative to parent
(5 answers)
Closed 9 months ago.
I am trying to animate background-color property on hovering from bottom to top and again from bottom to top when mouse is out. I have this pen, but it seems like width: 100% and height: 100% in ::after is calculated based on <p> tag, not <span>.
So how can I fix it? I want background-color animation just on underlined text (dolor), not for the whole paragraph.
div {
display: flex;
align-items: center;
justify-content: center;
}
p {
position: relative;
font: 2em sans-serif;
}
.underlined {
font-weight: bold;
text-decoration: underline solid black 0.1em;
transition: color 0.25s ease-out;
}
.underlined::after {
content: "";
position: absolute;
left: 0;
bottom: 0;
width: 100%; /* 100% of <p>, not <span> */
height: 100%; /* 100% of <p>, not <span> */
background: black;
z-index: -1;
transform: scaleY(0);
transform-origin: top;
transition: transform 0.25s ease-out;
}
.underlined:hover {
color: white;
}
.underlined:hover::after {
transform: scaleY(1);
transform-origin: bottom;
}
.underlined:hover::selection {
color: black;
background: white;
}
<div>
<p>Lorem ipsum <span class="underlined">dolor</span> sit amet</p>
</div>
add a position to <span> with class .underlined
.underlined {
position: relative;
}
.main-nav-link {
color: #0F1D4A;
font-size: 1rem;
font-weight: 700;
display: flex;
flex-direction: column;
}
.under-line::after {
height: 5px;
background: #6ECDE5;
width: 0px;
position: absolute;
content: "";
transition: all 0.2s ease;
}
.main-nav-link:hover{
.under-line{
&::after {
width: 100%;
}
}
}
<a class="main-nav-link" href="https://happytots.a101.co/shop/">All<span class="under-line"></span></a>

Html and CSS how to make image with hover effect a hyperlink

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>

Over image text that only appears when hovering over the image

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 have 2 links: one for my image and one for my title. Why are they both redirecting to the same place?

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>

How to write Text on a image.

How to add TEXT in the image...so that the TEXT is view-able only when the image becomes dark when mouse is placed over it.. something like ..the one given in the example image below...
Thanks for your help.
.image {
width: 250px;
height: 200px;
background: black;
position: relative;
overflow: hidden;
}
.image img {
transition: all ease 1s;
}
.image:hover img { /* Darkening effect on mouseover */
background: black;
opacity: 0.7;
}
.image .arrow { /* Creates a half triangle with top and left arrow transparent */
opacity: 0;
border-color: transparent #f2f2f2 #f2f2f2 transparent;
transition: all ease 1s;
position: relative;
}
.image:hover .arrow { /* Mouseover effect */
opacity: 1;
font-family: Roboto;
font-size: 36px;
text-align: center;
border-image: none;
border-style: solid;
border-width: 45px;
position: absolute;
bottom: 0;
font-weight: normal;
width: 0;
height: 0;
right: 0;
}
.image:hover .arrow {
border-image: none;
border-style: solid;
border-width: 45px;
bottom: 0;
display: block;
font-family: Roboto;
font-size: 36px;
font-weight: normal;
height: 0;
opacity: 1;
position: absolute;
right: 0;
text-align: center;
width: 0;
}
.image .arrow {
border-color: transparent #f2f2f2 #f2f2f2 transparent;
opacity: 0;
position: relative;
transition: all 1s ease 0s;
}
.image .arrow span {
left: 5px;
position: relative;
top: -10px;
}
<div class="image">
<img src="http://lorempixel.com/250/200/sports" />
<div class="arrow"><span>></span></div>
</div>
enter image description here
It's simple. Create some text inside your wrapper div, then order the text to display on hovering the wrapper. Below is a demo of this logic.
The HTML:
<div class="image">
<p>I'm some very interesting text!</p>
<div class="arrow"><span>></span></div>
</div>
The CSS:
p{
color: #fff;
opacity: 0;
font-weight: bold;
text-align: center;
font-size:32px;
color: red;
/* bring your own prefixes */
transform: translate(0, 50%);
transition: all .5 ease;
}
.image:hover p {
visibility: visible;
opacity: 1;
}
CODEPEN DEMO
i think you can create like this
you need to change the position of the .image class so that text div can appear overlap on that
.image-hover-wrapper {
display:none;
text-align: center;
width: 250px;
color: red;
font-size: 35px;
position: relative;
top: -125px;
background: rgba(255,255,255,0.6);
}
.image:hover > .image-hover-wrapper{
display:block;
opacity:0.8;
transition-property: animation;
transition-duration: 2s;
transition-timing-function: linear;
}
<div class="image">
<img src="http://lorempixel.com/250/200/sports" />
<div class="arrow"><span></span></div>
<div class="image-hover-wrapper">
Hii
</div>
</div>
and here is the
Updated DEmo