I can't get the hover effect right. I have a block with a picture and text in it. When hovering over the picture - should change the fill, filter: brightness. It does, but if I hover over the text which is in the middle of the picture, the text overlaps the picture and the hover effect doesn't work. If I put filter: brightness on the whole block, not only on the image, then the text gets filled too and becomes black. And my task is to change only the color of the picture, but not the text. What am I doing wrong?
.blocks
h5
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: inline-block
text-align: center;
color: white;
font-size: 18px;
img
filter: brightness(0.28)
&:hover
filter: brightness(0.7)
please make sure to put your relevant code (HTML and CSS) into an Stack-Snippet, so everyone here can easy reproduce the problem!
If you want to change the IMG-style when hovering the parent-element, use .parentElementClass:hover img{}
.blocks {
position: relative;
display: inline-block;
width: 150px;
}
.blocks h5 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: inline-block;
text-align: center;
color: white;
font-size: 18px;
z-index: 2;
}
.blocks img {
filter: brightness(0.28);
z-index: 1;
}
.blocks:hover img {
filter: brightness(0.7);
}
<div class="blocks">
<h5>headline 5</h5>
<img src="https://via.placeholder.com/150/000000/" />
</div>
Related
basically all i want to do is: Have a picture and when someone hovers over it i want some text to appear in its position(in the middle to be exact). What I have done so far is make the picture disappear on hover but i cannot get the text to be appeared..
Html:
<div class="container">
<img id="atp "class="atp" src="atp.jpg">
<div class="center">Some text</div>
</div>
Css:
atp{
display:block;
margin-left:auto;
margin-right:auto;
width:27%;
height:50%;}
container{
position: relative;
text-align: center;
}
.center{
position: absolute;
top:50%;
left:50%;
opacity: 0;
}
So basically, what i seek to be done is .atp:hover{opacity:0;} and what I also want is on atp's hover the .center{opacity:1;] So is there a way to put the opacity of center's to 1 when I am in the atp:hover{} code block?
Hope everything looks fine, thanks in advance!
Here is the code. Hope it will help you. if any changes please let me know.
/********* Simple or original overlay *******/
/* Main container */
.overlay-image {
position: relative;
width: 100%;
}
/* Original image */
.overlay-image .image {
display: block;
width: 100%;
height: auto;
}
/* Original text overlay */
.overlay-image .text {
color: #fff;
font-size: 30px;
line-height: 1.5em;
text-shadow: 2px 2px 2px #000;
text-align: center;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 100%;
}
/********* Overlay on hover *******/
/* New overlay on hover */
.overlay-image .hover {
position: absolute;
top: 0;
height: 100%;
width: 100%;
opacity: 0;
transition: .5s ease;
}
/* New overlay appearance on hover */
.overlay-image:hover .hover {
opacity: 1;
}
/********* Background and text only overlay on hover *******/
.overlay-image .normal {
transition: .5s ease;
}
.overlay-image:hover .normal {
opacity: 0;
}
.overlay-image .hover {
background-color: rgba(0,0,0,0.5);
}
<div class="overlay-image">
<a href="LINK_URL">
<div class="normal">
<div class="text">Image + text ORIGINAL</div>
</div>
<div class="hover">
<img class="image" src="https://dummyimage.com/200x150/00ccff/fff.png" alt="Alt text hover" />
</div>
</a>
</div>
#atp {
position: relative;
display: block;
margin-left: auto;
margin-right: auto;
width: 27%;
height: 50%;
z-index: 50;
}
.container {
position: relative;
text-align: center;
}
.center {
position: absolute;
top: 50%;
left: 50%;
z-index: 30;
}
#atp:hover {
opacity: 0;
}
try this, using z-index. It worked with me :)
I have an image with a CSS overlay that slides up from the bottom, and it's on the left. I want it in the center. Also, I hate to admit it, but the other post doesn't help. I got a post suggestion(IDK why), but I don't see how it helps me. I'm not super familiar with this and what I'm doing is for a project in a class of mine, which is late, and I'm trying to shoot for extra credit.
I just want to know how to make it go to the center. I have tried moving it to the left by 25, 50, and 75%, same with the right. It just won't move. Here is the code:
.container {
position: relative;
width: 50%;
}
.image {
display: block;
width: 50%;
height: auto;
}
/* This is what I have been using with to move it. */
.overlay {
position: absolute;
bottom: 0;
left: 0;
/* This will move wherever */
right: 0;
background-color: darkblue;
overflow: hidden;
width: 50%;
height: 0;
transition: .5s ease;
}
.container:hover .overlay {
height: 100%;
}
.text {
white-space: nowrap;
color: red;
font-size: 20px;
font-family: cursive;
position: absolute;
overflow: hidden;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
}
<div class="container">
<img src="image is here" alt="Avatar" class="image"> This won't move
<div class="overlay">
<div class="text"><u>This is just here atm</u></div>
</div>
</div>
I solved it. I just needed to use the "center" tag and put my style tag in it. Moved the overlay and it was fixed.
Trying to get span element to display in the center of my image to create an interactive button. Span class is "plus_own" element displays in left corner of the image.
.plus_own {
font-size: 70px;
color: white;
font-family: unc;
position: relative;
font-weight: bold;
top: -30px;
transition: all 0.4s ease;
}
Centered span class element trying to create an interactive button.
I would recommend taking a look at this to get a better understanding of how this works.
How I would recommend to do it is something like this:
.container {
position: relative;
text-align: center;
color: white;
}
.plus_own {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: red;
font-weight: bold;
}
<div class="container">
<img src="https://cdn.shopify.com/s/files/1/1330/4567/files/DSC_0838_1024x1024.jpg?v=1522089465" style="width:100%;">
<span class="plus_own">Some Text</span>
</div>
I have an image that has a hover state that changes two things: it darkens the image and it displays absolute positioned text over the image. The issue I'm having is when I hover over the text the image is no longer showing darkened. I've tried adding a hover state to the text as well. The image and hover text are siblings so I tried using the ~ following-sibling combinator like this: .hovertext:hover ~ .hoverimg but obviously I'm not using it correctly.
Code
.wrapper {
position: relative;
text-align: center;
}
.hovertext {
display: none;
color: white;
font-size: 30px;
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
}
.wrapper:hover .hovertext {
display: block;
}
.hoverimg:hover,
.hovertext:hover~.hoverimg {
filter: brightness(50%);
}
<div class="wrapper">
<img class="hoverimg" src="https://loremflickr.com/320/240">
<div class="hovertext">HOVER TEXT</div>
</div>
Is there a way to show both hover states with CSS only?
Use pointer-events:none to the text if there is no hover or click event on text
Stack Snippet
.wrapper {
position: relative;
text-align: center;
}
.hovertext {
display: none;
color: white;
font-size: 30px;
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
pointer-events: none;
}
.wrapper:hover .hovertext {
display: block;
}
.hoverimg:hover,
.hovertext:hover~.hoverimg {
filter: brightness(50%);
}
<div class="wrapper">
<img class="hoverimg" src="https://loremflickr.com/320/240">
<div class="hovertext">HOVER TEXT</div>
</div>
And if you are planning to add event on the text then you can change img and text properties on .wrapper class hover
.wrapper {
position: relative;
text-align: center;
}
.hovertext {
display: none;
color: white;
font-size: 30px;
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
}
.wrapper:hover .hovertext {
display: block;
}
.wrapper:hover .hoverimg {
filter: brightness(50%);
}
<div class="wrapper">
<img class="hoverimg" src="https://loremflickr.com/320/240">
<div class="hovertext">HOVER TEXT</div>
</div>
There is no way of selecting the previous element i.e. changing the styling of previous element using CSS as you are trying using sibling selector .hovertext:hover ~ .hoverimg, to make use of sibling selector here you need to make some changes in your html markup as below,
.wrapper {
position: relative;
text-align: center;
}
.hovertext {
display: none;
color: white;
font-size: 30px;
position: absolute;
top: 50%;
left: 50%;
transform: translateX(-50%) translateY(-50%);
z-index: 9;
}
.wrapper:hover > .hovertext {
display: block;
}
.hoverimg:hover,
.hovertext:hover ~ .hoverimg {
filter: brightness(50%);
}
<div class="wrapper">
<div class="hovertext">HOVER TEXT</div>
<img class="hoverimg" src="https://loremflickr.com/320/240">
</div>
In the above codes I have changed your HTML markup, thus now .hoverimg is sibling of targeted element i.e. .hovertext, so now every-time when you hover .hovertext or .hoverimg it adds assigned styling.
I would like to show the image with a non glassy display. Similar to the following one,
I am using the image as it is. I would like to show that with matte finish.
normal image:
Matte finish:
I am not able find it online. May be I am not using the right search keywords. Could anyone help me with this?
Inside a container I did put an image with reduced contrast / brightness / saturation plus a little bit of blur (all these four effects made by CSS filter). The image could've be placed as the container background but I wanted to apply these filters so it went separated.
After it, there's a colored layer with transparency covering the whole area. The letter represents the page's content that can be anything.
UPDATE: multiple filters must be all in a row, like it is on this latest update:
body {
width: 100%;
height: 100vh;
margin: 0px;
font-family: Georgia, serif;
}
#container {
width: 100%;
height: 100%;
position: relative;
background-color: navy;
overflow: hidden;
}
#thepic {
width: 100vw;
height: 100vh;
object-fit: cover;
-webkit-filter: brightness(90%) contrast(90%) blur(2px) grayscale(10%);
filter: brightness(90%) contrast(90%) blur(2px) grayscale(10%);
}
#color_layer {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: navy;
opacity: 0.3;
}
#content {
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
left: 0;
right: 0;
margin: auto;
text-align: center;
}
h1 {
display: inline-block;
color: white;
text-shadow: 1px 2px 2px #000;
font-size: 4em;
font-weight: 100;
letter-spacing: 2px;
text-align: center;
vertical-align: middle;
}
#letter {
vertical-align: middle;
}
<div id=container>
<img id=thepic src="http://i.imgur.com/s9J4MnI.jpg">
<div id=color_layer></div>
<span id=content><img id=letter src="http://i.imgur.com/CB1vUqy.png" alt=img><h1> 書面</h1></span>
</div>
#freestock.tk - That's the idea I had in mind also.
Here's another way to do it with less markup:
img {
max-width: 100%;
height: auto;
}
.container {
position: relative;
z-index: -1;
}
.container:before {
content: "";
position: absolute;
z-index: 1;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.5);
}
<div>
<h1>Original Image</h1>
<img src="http://i.imgur.com/WjbwTUH.jpg">
</div>
<div class="container" id="content">
<h1> With Transparent Overlay </h1>
<img src="http://i.imgur.com/WjbwTUH.jpg">
</div>
In this example, I put the image inside a container that is relatively positioned. The z-index is -1 so it will be behind the next layer.
Then I used a pseudo element that is absolutely positioned so it will stretch across the whole width of the container and cover the image. The positive z-index sets it on top of the first layer. Rather than setting an opacity, I used an rgba value for the background color. The first three numbers or the red, green, and blue values as usual, but the last number is a decimal between 0 and 1 that sets the opacity level. I made it a little darker than you probably want just so you can see the difference. You may also choose a different color to fit your image.
For reference: http://nicolasgallagher.com/css-background-image-hacks/