How can I make that the hover option allows me to see the image with opacity and the p tag inside not affected by opacity style? Please note that the img is inside an input tag and when I click it a bootsrap modal will appear with input form
.img_wrap:hover
#updateImg{ opacity: 0.7; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="img_wrap">
<input type='image' id='updateImg' src='http://placehold.it/350x150'>
</input>
<span></span><p class="imgText">Click here to change your image</p>
</div>
You need to handle each children's opacity separately. Also, if you want them overlapped, you need one of them (the text in my example, positioned absolute and the parent relative).
I'm guessing the following example does what you want to achieve? If not, please state your request clearer.
.img_wrap {
position: relative;
display: inline-block;
}
.img_wrap input[type="image"]{
opacity: 1;
display: block;
transition: opacity .3s cubic-bezier(.4,0,.2,1)
}
.img_wrap:hover input[type="image"] {
opacity: .3;
}
.img_wrap .imgText {
position: absolute;
height: 100%;
width: 100%;
left: 0;
top: 0;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
opacity: 0;
transition: opacity .3s cubic-bezier(.4,0,.2,1)
}
.img_wrap:hover .imgText {
opacity: 1;
pointer-events: none;
}
<div class="img_wrap">
<input type='image' id='updateImg' src='http://placehold.it/350x150' />
<div class="imgText">Click here to change your image</div>
</div>
Notes:
<input> is a self-closing tag, so <input></input> is invalid.
<input type="image"> is supposed to be used instead of a (submit) button. It's a shortcut for a button with a background image, that resizes itself to the image ratio. If you want to submit an image to the server using an <input>, you probably want to use <input type="file" />
here is what you want
.img_wrap{
display: inline-block;
position: relative;
}
.img_wrap:hover #updateImg{
opacity: 0.7;
position: relative;
}
.img_wrap:hover .imgText{
position:absolute;
top:0;
bottom: 0;
left: 0;
right:0;
}
Related
I'm using React and try to change 2 images by hovering them.
This is what I have done so far:
Card.js
<div className="image-wrapper">
<img src={sprites.front_default} className="image" alt="normal" />
<img src={sprites.back_default} className="image-hover" alt="hover" />
</div>
style.css
.image-wrapper {
position: relative;
}
.image-hover {
position: absolute;
top: 0;
left: 0;
opacity: 0;
transition: opacity 1s ease-out;
}
.image-hover:hover {
opacity: 1;
}
The main problem is that i want to make the front image opacity to 0 when im hovering the div, how can i make it?
I can make it without the fade changing but its important to make it with transition.
This is how I make it without transition
<img
className="figure"
src={sprites.front_default}
onMouseOver={(e) => (e.currentTarget.src = sprites.back_default)}
onMouseOut={(e) => (e.currentTarget.src = sprites.front_default)}
alt={"pokemon"}
/>
You can use just HTML & CSS. In the Card:
<div className="image-wrapper">
<img
src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/1.png"
className="pokemon-image"
alt="normal"
/>
<img
src="https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/2.png"
className="pokemon-image pokemon-image--back"
alt="normal"
/>
</div>
Here, I've used one class pokemon-image to position the two images at the center of the image-wrapper element, and pokemon-image--back as the class that is showed when hovering over the image-wrapper element.
The CSS:
.image-wrapper {
width: 200px;
height: 150px;
background-color: #f7f7f7;
position: relative;
}
.pokemon-image {
position: absolute;
height: 100%;
left: 50%;
transform: translateX(-50%);
}
.pokemon-image--back {
opacity: 0;
transition: opacity 1s ease-out;
}
.image-wrapper:hover .pokemon-image--back {
opacity: 1;
}
Hope this helps. You can try it in this codesandbox.
on my home page I have a grid block with 6 images on it
On hover, it becomes more transparent thanks to CSS (opacity: 0.6)
I also would like that when I hover on the button at the center of the image, the image itself keeps being transparent
Since it's not the case here
So I have applied some code here, but I couldn't figure why it doesn't work
.flexItem.grid_sections .button:hover ~ .grid_sections img {
opacity: 0.6;
}
Those elements appear on my homepage, 5th section
URL: https://www.tresor-ethnique.com/
Any idea?
Let me know, and thank you in advance :)
Pascal
Try
div {
height: 260px;
width: 260px;
position: relative;
}
div > img {
width: 100%;
height: 100%;
position: absolute;
z-index: 1;
opacity: 0.6;
}
div > button {
position: absolute;
z-index: 2;
top: 45%;
left: 30%;
width: 80px;
height: 45px;
}
div > button:hover + img {
opacity: 1;
}
<div>
<button>Button</button>
<img src="https://via.placeholder.com/260x260">
</div>
NOTE: you must put the button tag before img tag
how do I apply background image on the checkbox.I know this is something which is very easy but still I am finding it difficult
here is my HTML code . I don't know what is the issue in this
<div>
<style>
input[type="checkbox"], input[type="radio"] {
box-sizing: border-box;
padding: 0px;
background: transparent url("http://ilexsquare.com/finalhot/wp-content/uploads/2015/12/hotlogo-2.png") repeat scroll 0% 0%;
}
</style>
<input type="checkbox" />
</div>
please Help
Julian Be is correct you can't apply background images directly to checkboxes.
The only way to achieve this is to spoof the result. You could do this by having a <label> wrapped around the checkbox with it's overflow set to hidden and then move the checkbox itself into the overflow. This way ensures the checkbox is still clickable but not visible to the user. You can then add a <span> after the checkbox and apply the background image to this element depending on the state of the checkbox using the :checked selector and + selector.
Something like this
/* Set overflow of label to hidden so the checkbox can disappear */
.label-with-hidden-checkbox {
overflow: hidden;
position: relative;
}
/* Move the checkbox out of view */
.label-with-hidden-checkbox .hidden-checkbox {
position: absolute;
left: -9999px;
}
/* Set the background image of the spoof checkbox to the unchecked state */
.label-with-hidden-checkbox .hidden-checkbox + .spoof-checkbox{
display: inline-block;
margin-right: 10px;
background: transparent url("unchecked-state-image.png") repeat scroll 0% 0%;
}
/* When the checkbox is checked set the background image of the spoof checkbox to the checked state */
.label-with-hidden-checkbox .hidden-checkbox:checked + .spoof-checkbox{
display: inline-block;
width: 20px;
height: 20px;
margin-right: 10px;
background: transparent url("checked-state-image.png") repeat scroll 0% 0%;
}
</style>
<label class="label-with-hidden-checkbox">
<input class="hidden-checkbox" type="checkbox" /><span class="spoof-checkbox"></span> This is a checkbox
</label>
</div>
Hope that helps.
You can Use label to apply the image here is the jsfiddle
jsfiddle
this is your HTML code:
<input type="checkbox" />
<label></label>
and CSS:
input[type="checkbox"], input[type="radio"] {
box-sizing: border-box;
padding: 0px;
opacity: 0;
cursor: pointer;
}
label{
height:100px;
width:100px;
}
label:before{
content:"";
width: 100px;
height: 60px;
display: block;
z-index: 1;
border-radius: 2.5px;
background: url("http://ilexsquare.com/finalhot/wp-content/uploads/2015/12/hotlogo-2.png") repeat scroll 0% 0%;
}
You cannot add images to checkboxes.
Below is a code snippet from a page that shows attribute options. The code shown is for an item selected by hidden radio button, and the requirement was for the attribute image to be overlaid with a checkmark when selected.
Whilst I have got the checkmark to show on selection, it is always behind the original image. I have tried using z-index, opacity, and also absolute and relative positioning. What is the way to achieve this? I've run out of ideas.
I have already looked at multiple answers for similar questions, but none have worked for me.
<div class="attribImg">
<input type="radio" name="id[11]" value="61" checked="checked" id="attrib-11-61" />
<label class="attribsRadioButton four" for="attrib-11-61"><img src="images/attributes/18mg.png" alt="" width="50" height="50" />
</label>
<br />
</div>
Css used is:
input[type="radio"] {
visibility:hidden;
}
label {
cursor: pointer;
}
.attribImg {z-index:0;}
input[type="radio"]:checked+label{
background:url(../images/checkmark.png) no-repeat 7px -20px;
}
Fiddle is http://jsfiddle.net/1jcz1xyn/
The problem is caused by the <img> being inside the <label>. No matter the z-index you use on the label, the child (img), will always be above it's parent background, unless you set the child with z-index: -1 (updated fiddle - click the 2nd):
.attribImg {
position: relative; /** this is the positioning context **/
width: 50px;
height: 50px;
}
input {
visibility: hidden;
}
label {
position: absolute;
width: 100%;
height: 100%;
cursor: pointer;
}
img {
position: relative;
z-index: -1;
}
input[type="radio"]:checked+label { background:url(https://cdn1.iconfinder.com/data/icons/mimiGlyphs/16/check_mark.png) no-repeat center center;
}
i suggest you try to manipulate the icon/image with CSS background-image only, instead of having one case with img and another with CSS. If you do that, z-index won't fix cause it's a logical error.
If you are going to use images/icons (in some cases that's useful for transitions), its also better to add both with the same technique and change the state with css.
So, you can manipulate with CSS:
<div class="form-item">
<label for="radio-1">
<input type="radio" name="radios" id="radio-1"> <span>Sample 1</span>
</label>
</div>
label > input[type="radio"]{
display: none;
}
input[type="radio"]:checked + span:after{
font-family:"FontAwesome";
content: "\f00c";
margin-left:10px;
}
And you can add both images in the same form-field, and manipulate them with some CSS (And FontAwesome):
<div class="form-item">
<label for="radio-switch-2">
<input type="radio" name="radios-2" id="radio-switch-2">
<div class="radio-switch-state">
<span class="icon-off"></span>
<span class="icon-on"></span>
</div>
</label>
</div>
input[type="radio"]{
display: none;
}
.radio-switch-state{
background-color:#aaa;
display: inline-block;
color:#fff;
transition:all .5s ease;
width:50px;
height:50px;
position: relative;
overflow:hidden;
vertical-align:middle;
}
.radio-switch-state .icon-on,
.radio-switch-state .icon-off{
display: inline-block;
position: absolute;
width:100%;
top:0;
}
// If you are using font
.radio-switch-state .icon-on:after,
.radio-switch-state .icon-off:after{
font-family:"FontAwesome";
width:100%;
display: block;
line-height:50px;
position: absolute;
transition:all .5s ease;
}
.radio-switch-state .icon-on:after{
content: "\f00c";
margin-left:100;
left:100%;
}
.radio-switch-state .icon-off:after{
content: "\f056";
left:0;
}
.radio-switch-state:hover{
background-color:#FFA374;
cursor:pointer;
}
input[type="radio"]:checked + .radio-switch-state{
background-color:#FA8144;
}
input[type="radio"]:checked + .radio-switch-state .icon-on:after{
content: "\f00c";
margin-left:100;
left:0;
}
input[type="radio"]:checked + .radio-switch-state .icon-off:after{
content: "\f056";
left:-100%;
}
I made a Pen with both samples.
Also, when using icons try to use an icon font library, like FontAwesome or Glyphicon.
Edit - Added a sample with images
Maybe this variant will help you? It's without any changes to HTML. I've used ::after instead and here's the Fiddle: https://jsfiddle.net/mvchalov/1jcz1xyn/2/
input[type="radio"]:checked+label::after{
background:url(https://cdn1.iconfinder.com/data/icons/mimiGlyphs/16/check_mark.png) no-repeat center center;
width:50px;
height:50px;
position: absolute;
content:'';
margin:0 0 0 -50px;
}
I'm trying to make a grid of images that once you hover over one, it's webpage title appears below it, as well as the other images around it changing in opacity.
I have managed to create the opacity mouseover effect I want, but now I'm having trouble making the page heading images appear as you hover over the corresponding image. I hope that makes sense
Hope someone can help. Here is my code
HTML:
<div style="position: relative; left: 140px; top: 0px;">
<img src="window.jpg" style="position: relative; top: 0; left: 0;"/>
<div id="windowimages">
<a class="image-one"></a><a href="https://example-site.com/music/">
<img src="pic1.jpg/>
<a class="image-two"></a><a href="https://example-site.com/dance/">
<img
src="pic2.jgp"/>
<a class="image-three"></a><a href="https://example-site.com/art/">
<img
src="pic3.jpg" />
<a class="image-four"></a><a href="https://example-site.com/aboutus/">
<img
src="pic4.jpg"/>
</div>
CSS:
body {
}
#windowimages {
position: absolute;
left: 3px;
top: 4px;
font-size: 0;
width: 198px;
margin: 0 auto;
padding:1px;
overflow:hidden
}
#windowimages img {
width:90px;
height:90px;
margin: 3px;
cursor:pointer;
-webkit-transition:opacity 0.26s ease-out;
-moz-transition:opacity 0.26s ease-out;
-ms-transition:opacity 0.26s ease-out;
-o-transition:opacity 0.26s ease-out;
transition:opacity 2s ease-in-out;
}
#windowimages:hover img {
opacity:0.55;
}
#windowimages:hover img:hover {
opacity:1;
}
If I understood you correctly, it seems like what you want to do is add a title to each image on hover.
Check out this example I wrote: http://jsfiddle.net/arthurcamara/chbsL3pq/
The key part to adding the title was .image:hover:after as you can see above and in the code below:
.grid:hover .image:hover:after {
display: block;
position: absolute;
top: 5px;
width: 90px;
padding: 5px;
content: attr(data-title);
text-align: center;
background-color: #333;
color: #fff;
}
I changed your markup a bit as well to make it more semantic. Check out the example and let me know if that helped :)