I have this image which is inside div with class="image-wrapper". All I am trying to do is:
display .image-wrapper::before while being hovered on image so it works like title of image
also use transform: scale(1.1) on img so it grows little on being hovered
Description of problem from my side
In order to display title inside image (part 1), using ::before, we cannot use it directly on img as they are replaced elements, so I enclosed img with div with class="image-wrapper" and used ::before on div. And it worked fine as I expected. Now for the second part, I am not able to render both property same time. I am kinda confused.
.image-wrapper {
border: 2px solid black;
display: inline-block;
overflow: hidden;
}
.image-wrapper::before {
content: 'Hello';
height: auto;
width: auto;
padding: 4px;
margin-left: 8px;
background: rgba(0, 0, 240, 0.3);
color: white;
font-size: 20px;
position: absolute;
opacity: 0;
}
img {
width: 100%;
}
img:hover {
transform: scale(1.1);
transition: all 0.2s;
cursor: pointer;
}
/*HERE IS THE PROBLEM*/
.image-wrapper:hover::before {
opacity: 1;
}
<div class="image-wrapper">
<img src="https://images.unsplash.com/photo-1624215824600-ed3118b76873?ixid=MnwxMjA3fDB8MHx0b3BpYy1mZWVkfDMwfDZzTVZqVExTa2VRfHxlbnwwfHx8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60">
</div>
It's kind of all there in your code, but the before pseudo element wont show up above its element, unless you give it a higher z-index.
Also this snippet slightly alters the CSS so that what it's looking for is hover on the image-wrapper class both for the Hello and the img scaling.
.image-wrapper {
display: inline-block;
overflow: hidden;
}
.image-wrapper::before {
content: 'Hello';
height: auto;
width: auto;
padding: 4px;
background: pink margin-left: 8px;
background: rgba(0, 0, 240, 0.3);
color: white;
font-size: 20px;
position: absolute;
opacity: 0;
}
img {
width: 100%;
}
.image-wrapper:hover img {
transform: scale(1.1);
transition: all 0.2s;
cursor: pointer;
}
.image-wrapper:hover::before {
opacity: 1;
z-index: 100;
}
<div class="image-wrapper">
<img src="https://images.unsplash.com/photo-1624215824600-ed3118b76873?ixid=MnwxMjA3fDB8MHx0b3BpYy1mZWVkfDMwfDZzTVZqVExTa2VRfHxlbnwwfHx8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60">
</div>
Related
When hovering over the image, a textbox should be shown. However, it is not working for me and I am completely stuck.
These are the code snippets, thank you in advance.
#passinfo {
height: 20px;
width: 20px;
margin-left: 130px;
margin-top: -20px;
margin-bottom: 15px;
padding: -20px;
position: absolute;
display: block;
}
#infotext {
background-color: #628ca0;
border-radius: 5px;
color: rgba(34, 34, 34, 0.829);
padding: 5px 4px 4px 4px;
position: relative;
box-shadow: 0px 1px 5px #999;
opacity: 0;
margin-left: 100px;
left: 10px;
position: absolute;
transition: .5s ease;
}
#passinfo .img:hover #infotext {
opacity: 1;
visibility: visible;
}
<h4>Password</h4>
<img src="infoicon.png" id="passinfo">
<div id="infotext">Password must be at least 8 characters and must contain an uppercase letter, a lowercase letter, and a number.</div>
Your selector:
#passinfo .img:hover #infotext
is looking for the element with id="infoText" that is a descendant of an element with a class of img, that is hovered-over, that is itself a descendant of an element with id="passinfo".
Your <img> element does not have a class of img, it is an <img> element and itself has the id="passinfo"; and <img> elements cannot have any child, or descendant, elements of any kind (not even pseudo-elements); so this selector will, and can, never apply.
Instead, you're looking for – and should use – the following:
#passinfo:hover + #infotext
Which selects the element with id="infotext" which is the immediately-adjacent sibling of the element with a class of img, that is hovered-over.
#passinfo {
height: 20px;
width: 20px;
margin-left: 130px;
margin-top: -20px;
margin-bottom: 15px;
padding: -20px;
position: absolute;
display: block;
}
#infotext {
background-color: #628ca0;
border-radius: 5px;
color: rgba(34, 34, 34, 0.829);
padding: 5px 4px 4px 4px;
position: relative;
box-shadow: 0px 1px 5px #999;
opacity: 0;
margin-left: 100px;
left: 10px;
position: absolute;
transition: .5s ease;
}
#passinfo:hover + #infotext {
opacity: 1;
visibility: visible;
}
<h4>Password</h4>
<img src="https://via.placeholder.com/150" id="passinfo">
<div id="infotext">Password must be at least 8 characters and must contain an uppercase letter, a lowercase letter, and a number.</div>
Change
#passinfo .img:hover #infotext {
opacity: 1;
visibility: visible;
}
to
#passinfo:hover
opacity: 1;
visibility: visible;
}
Move your #passinfo into a div wrapping the image and text, and use that to set the :hover.
<h4>Password</h4>
<div id='passinfo'>
<img src="icon.png">
<div id="infotext">Password must be...</div>
</div>
#passinfo:hover #infotext {
opacity: 1;
}
W3Schools.com is a great resource for stuff like this if you haven't heard of it. https://www.w3schools.com/howto/howto_css_image_overlay.asp
#passinfo:hover {
opacity: 1;
visibility: visible;
}
I have an image, with text on top. When I rollover the Image I want the opacity of the background image to lower, but not the opacity for the text above it.
I thought that since the text was in a span i could simply tell the span to have the opacity: 1 !important; however that doesn't seem to do the trick. Can anyone help?
Here is the JSFiddle: https://jsfiddle.net/zerojjc/xrwao8n9/
HTML:
<div class="boxThird">
<a class="btnBox boxOne" href="<?php bloginfo('url'); ?>/" title="About Heath, Fania & Co"><span>About</span></a>
</div>
CSS:
.boxThird {
float: left;
width: 33.33%;
height: 400px;
background: #000;
}
.boxThird span {
margin-left: 25px;
position: relative;
top: 344px;
text-decoration: none;
border-bottom: 1px solid #fff;
}
.btnBox {
display: block;
text-align: left;
color: #fff;
text-shadow: 0px 0px 2px #555;
text-transform: uppercase;
text-decoration: none;
font-weight: 400;
font-size: 2em;
letter-spacing: .125em;
}
.boxOne {
height: 100%;
width: 100%;
background-position: center;
background-size: cover;
}
.boxOne {
background-image: url(https://i.imgur.com/izS0fLZ.jpg);
}
.boxOne:hover{
opacity: 0.8;
}
.boxOne:hover span{
opacity: 1 !important;
}
Opacity cascades, which means that if you have a span inside a div and they both have 0.8 opacity, the child-span would actually have 80% opacity of the parents 80% opacity (so IDK, 64% opacity). So by setting opacity: 1 to your span, you basically set it to the parents 0.8 opacity.
To prevent this, you can move the background image into a :before pseudo element and just change the :before opacity.
You can see a working example here:
https://jsfiddle.net/xr06hby2/
Relevant CSS:
.boxOne {
position: relative;
}
.boxOne:before {
content: '';
background-image: url(https://i.imgur.com/izS0fLZ.jpg);
background-position: center;
background-size: cover;
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
opacity: 1;
transition: opacity 0.3s;
}
.boxOne:hover:before{
opacity: 0.3;
}
I am trying to have a square-shaped div (the red box) on the page by default. When the user hover the mouse over it, a second div should display with a semi-transparent black background and some text/content. I'm trying to imitate Devon Stank's project section on his website.
The code I have right now increases the height of the default square red box and the second div doesn't cover the whole of the red box. What's wrong with the code?
Fiddle
.project-box {
position: relative;
width: 30%;
padding-top: 30%;
overflow: hidden;
margin-right: 20px;
margin-bottom: 15px;
display: inline-block;
}
.default-box {
background-color: red;
}
.hover-content {
position: relative;
width: 100%;
height: 100%;
padding-top: 30%;
overflow: hidden;
display: inline-block;
}
.default-hover {
opacity: 0;
-webkit-transition: 0.5s;
-moz-transition: 0.5s;
-o-transition: 0.5s;
-ms-transition: 0.5s;
transition: 0.5s;
background-color: rgba(0, 0, 0, 0.5);
}
.default-box:hover .default-hover {
opacity: 1;
}
<div class="default-box project-box">
<div class="default-hover hover-content">hello</div>
</div>
height: 100%; won't work on the element if the parent's height isn't defined.
Also, if you stick with position: relative with a padding on the parent, you won't be able to cover it all.
If you want to cover all the .project-box (parent) no matter its padding values,
I suggest you to use an absolute positioning on its child:
(I've done it by adding the new class .veil, but it could be done within your existing class)
.project-box {
position: relative; /* ADDED so that the absolute positioning refers to this parent */
width: 30%;
padding-top: 30%;
overflow: hidden;
margin-right: 20px;
margin-bottom: 15px;
display: inline-block;
}
.default-box {
background-color: red;
}
.hover-content {
/* REMOVED position and sizes */
padding-top: 30%;
overflow: hidden;
display: inline-block;
}
.default-hover {
opacity: 0;
transition: 0.5s;
background-color: rgba(0, 0, 0, 0.5);
}
.default-box:hover .default-hover {
opacity: 1;
}
/* ADDED this class */
.veil {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
<div class="default-box project-box">
<!-- Added a class for the child here -->
<div class="default-hover hover-content veil">hello</div>
</div>
Hope it helps.
Here, it may help you, try it.
.project-box {
position: relative;
width: 30%;
height:100%
}
.default-box {
background-color: red;
}
.hover-content {
position: relative;
width: 100%;
height: 100%;
text-align:center;
padding-top: 30%;
}
I am trying to add and animate a line under a link using CCS but the positioning of the line (or, perhaps, its width) breaks when the text wraps.
Here is an illustration of what I am trying to achieve and what the problem is:
normal behavior:
breaking:
Here is the fiddle of the illustration: https://jsfiddle.net/b1zajhs5/. To make it break, just shrink the result panel until the text wraps.
This is the HTML used
<div class="centered">
<span class="effect-underline">Some Text That Has to Be Quite Long To Prove the Point</span>
</div>
And this is the SCSS:
.centered {
border: 1px solid #ccc;
width: 80%;
margin: 2rem auto;
padding: 1.5rem .5rem;
text-align:center;
}
a {
text-decoration: none;
}
.effect-underline {
position: relative;
&:after {
content: '';
border-bottom: 1px solid;
width: 100%;
height: 1em;
display: inline-block;
margin-top: 10px;
position: absolute;
left: 0;
opacity: 0;
transition: all 0.35s;
transform: scale(0, 1);
}
&:hover {
&:after {
opacity: 1;
transform: scale(1);
}
}
}
Do you know how the line can be expanded the match the full width of the link when the text is wrapped?
Add display: inline-block; to .effect-underline to make it go across when the text wraps.
.centered {
border: 1px solid #ccc;
width: 80%;
margin: 2rem auto;
padding: 1.5rem 0.5rem;
text-align: center;
}
a {
text-decoration: none;
}
.effect-underline {
display: inline-block;
position: relative;
}
.effect-underline:after {
content: "";
border-bottom: 1px solid;
width: 100%;
height: 1em;
display: inline-block;
margin-top: 10px;
position: absolute;
left: 0;
opacity: 0;
-webkit-transition: all 0.35s;
transition: all 0.35s;
-webkit-transform: scale(0, 1);
transform: scale(0, 1);
}
.effect-underline:hover:after {
opacity: 1;
-webkit-transform: scale(1);
transform: scale(1);
}
<div class="centered">
<span class="effect-underline">Some Text That Has to Be Quite Long To Prove the Point</span>
</div>
The reason why display: inline-block worked, was because a span, by default has a inline display. So, naturally, the line is going till the end of a text, and the end was on last sentence, that broke bellow.
giving it a display of inline-block, an element becomes like a block element, so the line goes till the end of a block, not the end of a sentence.
I'm a real novice and trying to use a web template to design my own website.
I have a basic lightbox gallery and it all works ok, but whatever I have tried, I cannot get a caption to show on the gallery image (not the thumbnail image).
This is a snippet of the html code with a single gallery item:
<div class="gallery-item">
<div class="image">
<div class="overlay">
</div>
<img src="img/gallery/gallery-item1.jpg" alt="image 4">
</div>
I've tried using title="caption" instead of data-title ="caption", but no joy. Here is the css for the lightbox:
#lightbox {
cursor: pointer;
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: black;
/* IE Fallback (Solid Colour) */
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAIElEQVQ4T2NkYGDYDMRkA8ZRAxhGw4BhNAyA+WAYpAMAIFgLQfO9BoEAAAAASUVORK5CYII=);
background: rgba(0, 0, 0, 0.7);
-webkit-filter: none !important;
}
#lightbox img {
display: block;
position: absolute;
border: 5px solid #fff;
box-shadow: 0 0 20px #000;
border-radius: 1px;
}
body.blurred > * {
-webkit-filter: blur(2px);
-webkit-transform: translate3d(0, 0, 0);
}
.lightbox-loading {
background: url(../img/loading.gif) center center no-repeat;
width: 31px;
height: 31px;
margin: -16px 0 0 -16px;
position: absolute;
top: 48%;
left: 50%;
}
.lightbox-caption {
display: none;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
text-align: center;
z-index: 1000;
background: #000;
background: rgba(0, 0, 0, 0.7);
}
.lightbox-caption p {
margin: 0 auto;
max-width: 70%;
display: inline-block;
*display: inline;
*zoom: 1;
padding: 10px;
color: #fff;
font-size: 12px;
line-height: 18px;
}
.lightbox-button {
position: absolute;
z-index: 9999;
background: no-repeat center center;
width: 32px;
height: 32px;
opacity: 0.4;
-webkit-transition: all 0.3s;
-moz-transition: all 0.3s;
-ms-transition: all 0.3s;
transition: all 0.3s;
}
.lightbox-button:hover,
.lightbox-button:focus {
opacity: 1;
-webkit-transform: scale(1.4);
-moz-transform: scale(1.4);
-ms-transform: scale(1.4);
transform: scale(1.4);
}
.lightbox-close {
right: 30px;
top: 30px;
background-image: url("../img/close.png");
}
.lightbox-next {
right: 30px;
top: 48%;
background-image: url("../img/next.png");
}
.lightbox-previous {
left: 30px;
top: 48%;
background-image: url("../img/previous.png");
}
any tips / help is welcomed. thanks
The caption is being loaded by the 'data-caption' attribute in your anchor tag.
Your anchor tags currently look like this:
You need to insert the caption like this:
For your own interest, if you look at the javascript in the source files you'll see these lines:
setCaption: function () {
var caption = $(plugin.current).data('caption');
if(!!caption && caption.length > 0) {
plugin.caption.fadeIn();
$('p', plugin.caption).text(caption);
}else{
plugin.caption.hide();
}
},
The second line says:
var caption = $(plugin.current).data('caption');
This is setting the caption to whatever text you have in the data-caption field. If it said .data('title'), then you would use data-title = "my caption"
Hope that helps.
Need more code to check I would say but you do have
.lightbox-caption {
display: none;
}
This would usually hide this class. Maybe try and remove display:none or change to block or inline etc?