It works really well, but not so well in Safari or iOS mobiles. When you leave the hover state it does not return to the original state. In other browsers it does.
His CSS was;
.hotspot {
position: absolute;
border: 1px solid blue;
}
.hotspot + * {
pointer-events: none;
opacity: 0;
}
.hotspot:hover + * {
opacity: 1.0;
}
.wash {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background-color: rgba(255, 255, 255, 0.6);
}
and his html was;
<div style="position: relative; height: 188px; width: 300px;">
<img src="http://demo.cloudimg.io/s/width/300/sample.li/boat.jpg">
<div class="hotspot" style="top: 50px; left: 50px; height: 30px; width: 30px;"></div>
<div>
<div class="wash"></div>
<div style="position: absolute; top: 0; left: 0;">A</div>
</div>
<div class="hotspot" style="top: 100px; left: 120px; height: 30px; width: 30px;"></div>
<div>
<div class="wash"></div>
<div style="position: absolute; top: 0; left: 0;">B</div>
</div>
</div>
Any help fixing this and only using CSS would be appreciated, thanks in advance.
There is no hover on touch devices, you're either touching an element or you're not. Sometimes your :hover state may be triggered by the touch event itself - which is why you can't leave that state as there is no mouse-out.
One solution would be to disable the :hover style for touch devices and using the :active styles instead.
You’ll need to detect if the user is using a touch device. There is no reliable way to do this in CSS. There are JS solutions such as Modernizr but you really need to research the problems with detecting touch devices. Sure, the user might have a touchscreen but perhaps they’ve got a mouse plugged in. See Stu Cox's article about this. It's old but still relevant.
Anyway, I digress. Back to your question:
if ('ontouchstart' in window || navigator.maxTouchPoints) {
document.body.classList.add('touch');
} else {
document.body.classList.add('notouch');
}
.hotspot {
position: absolute;
border: 1px solid blue;
}
.hotspot + * {
pointer-events: none;
opacity: 0;
}
.notouch .hotspot:hover + * {
opacity: 1.0;
}
.hotspot:active + * {
opacity: 1.0;
}
.wash {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background-color: rgba(255, 255, 255, 0.6);
}
<div style="position: relative; height: 188px; width: 300px;">
<img src="http://demo.cloudimg.io/s/width/300/sample.li/boat.jpg">
<div class="hotspot" style="top: 50px; left: 50px; height: 30px; width: 30px;"></div>
<div>
<div class="wash"></div>
<div style="position: absolute; top: 0; left: 0;">A</div>
</div>
<div class="hotspot" style="top: 100px; left: 120px; height: 30px; width: 30px;"></div>
<div>
<div class="wash"></div>
<div style="position: absolute; top: 0; left: 0;">B</div>
</div>
</div>
Related
Screenshot for the Popup
Popup is not coming up in front of screen which is implemented in the hmtl and css
Code Snippet for Modal Popup
------HTML------
{this.state.isOverviewScreenshotOpen && (
<div className={styles.modal}>
<div onClick={this.toggleModal} className={styles.overlay}></div>
<div className={styles.modalContentOverview}>
<img onClick={this.toggleModal}
src={this.state.overviewImageImageUrl} className={styles.imagePopup} alt="" />
<div className={styles.closeModal} onClick={this.toggleModal}>
<button
type="button"
className={styles.close}
data-dismiss="modal"
aria-label="Close"
onClick={this.toggleModal}
>
<span aria-hidden="true" className={styles.crossIcon}>×</span>
</button>
</div>
</div>
</div>
-----CSS-----
.modal {
width: 102vw;
height: 130vh;
top: 0;
left: 0;
right: 0;
bottom: 0;
position: fixed;
z-index: 100;
}
.overlay {
width: 100vw;
top: 0;
left: 0;
right: 0;
bottom: 0;
position: fixed;
background: rgba(49, 49, 49, 0.8);
}
.modalContent {
position: absolute;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
line-height: 1.4;
padding: 14px 28px;
border-radius: 3px;
}
body.activeModal {
overflow-y: hidden;
}
.closeModal {
cursor: pointer;
position: absolute;
top: 12px;
right: 50px;
color: black;
padding: 5px 7px;
}
I tried with giving highest z-index=100 to modal with position fixed but still its not working, please have a look and let me know if we are missing up something from the css
.collection {
margin-bottom: 20px;
}
.collection-content{
position: relative;
padding: 50px 143px;
background-color: #F8F8F2;
background-image: url("../img/collection-bg-img.jpg") ;
}
.collection-leafe-left{
position: absolute;
left: -150px;
top: 40px;
}
.collection-leaves-right{
position: absolute;
right: -350px;
top: 685px;
}
.collection-leafe-left-light{
position: absolute;
left: -216px;
bottom: 170px;
}
<section class="collection">
<div class="container">
<div class=" collection-content ">
<img class="collection-leafe-left" src="https://via.placeholder.com/371 " alt width="371" height="371" >
<img class="collection-leaves-right" src="https://via.placeholder.com/546/592?text=POSITION+IS+NOT+WORKING
C/O https://placeholder.com/ " alt width="546" height="592" >
<img class="collection-leafe-left-light" src="https://via.placeholder.com/314" alt width="314" height="287" >
</div>
</div>
</section>
position:absolute; is not working with collection-right-mix image. Why is that so?
Because of position:absolute; is not working with collection-right-mix image , appear scroll across horizontal.
How to effect position to the collection-right-mix image
Change padding to margin for .collection-content
position: absolute considers the padding part of the width.
Thus, .collection-content { padding: 50px 143px; } would position the absolute children the same as .collection-content { padding: 0; }.
On the other hand, position: absolute does NOT consider the margin part of the width.
So now, the absolutely position children should be positioned as you desired.
.collection {
margin-bottom: 20px;
}
.collection-content {
position: relative;
margin: 50px 143px; /* Changed */
background-color: #F8F8F2;
background-color: #ccc; /* Changed */
background-image: url("../img/collection-bg-img.jpg");
}
.collection-leafe-left {
position: absolute;
left: -150px;
top: 40px;
}
.collection-leaves-right {
position: absolute;
right: -350px;
top: 685px;
}
.collection-leafe-left-light {
position: absolute;
left: -216px;
bottom: 170px;
}
<section class="collection">
<div class="container">
<div class=" collection-content ">
<img class="collection-leafe-left" src="https://via.placeholder.com/371 " alt width="371" height="371">
<img class="collection-leaves-right" src="https://via.placeholder.com/546/592?text=POSITION+IS+NOT+WORKING" alt width="546" height="592">
<img class="collection-leafe-left-light" src="https://via.placeholder.com/314" alt width="314" height="287">
</div>
</div>
</section>
Ive got a product page with a smaller image of the product.
Now I want to show a bigger version of this image with a colored background covering the whole page, while I hover the smaller image.
The problem is, that the bigger image flickers while I move the mouse around.
My CSS:
#zoomed-product-img {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(162, 130, 192, 0.8);
z-index: 0;
visibility: hidden;
}
#zoomed-product-img img {
display: block;
margin: auto auto;
}
.productsdetail-image:hover~#zoomed-product-img {
visibility: visible;
}
My HTML:
<div class="productdetails">
<div class="productsdetail-image">
<img src="/assets/images/products/{{page.name}}.png" alt="Produktbild">
</div>
<div class="productsdetail-info">
</div>
<div id="zoomed-product-img">
<img src="/assets/images/products/{{page.name}}.png" alt="Produktbild">
</div>
Can you help me? Maybe my way of thinking is wrong.
I think it flickers because when I show the bigger image, it is above (z index) the small one and I am not hovering the image anymore so it disappears.
I would also love to solve this with javascript, if you can give me any advice.
You need to specify dimensions for the container of the image. This is why it is flickering. I also used display: none; and display:block to hide and show the images.
.productdetails {
position: relative;
}
#zoomed-product-img {
display: none;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: -1;
}
/* This is the product detail image styles */
.productsdetail-image {
display: block;
height: 200px;
width: 200px;
}
.productsdetail-image:hover img {
display: none;
}
.productsdetail-image:hover + #zoomed-product-img {
display: block;
}
HTML
<div class="productdetails">
<div class="productsdetail-image">
<img src="https://placeimg.com/200/200/animals" alt="Produktbild">
</div>
<div id="zoomed-product-img">
<img src="https://placeimg.com/300/300/animals" alt="Produktbild">
</div>
<div class="productsdetail-info">
</div>
Demo:
http://jsfiddle.net/n07bt46y/
Please check this in full page
$(document).ready(function(){
$('.productsdetail-image img').hover(function() {
$(this).hide();
$('#zoomed-product-img ').show(500);
});
$('#zoomed-product-img .close').click(function(){
$(this).parent().hide();
$('.productsdetail-image img ').show();
});
});
.productsdetail-image img {
width: 150px;
height: auto;
transition: all 0.5s ease;
}
#zoomed-product-img {
display: none;
position: absolute;
width: 100%;
height: 100%;
background-color: red;
}
#zoomed-product-img span.close {
position: absolute;
color: #fff;
cursor: pointer;
top: 20px;
right: 20px;
}
#zoomed-product-img img {
position: absolute;
width: 300px;
height: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: aUto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="productdetails">
<div class="productsdetail-image">
<img src="https://placeimg.com/300/300/animals" alt="Produktbild">
</div>
<div id="zoomed-product-img">
<span class="close">close</span>
<img class="zoom-img" src="https://placeimg.com/300/300/animals" alt="Produktbild">
</div>
<div class="productsdetail-info">
</div>
Are you wanna build something like that? Hoppefully that fiddle can help you
I just don't come up with an idea how to do the following:
In my html-document i have two elements of the class "modal" (the bootstrap modal class).
The one modal must have a z-index of -5 and the other 10.
How could I achieve this?I suppose that I could use IDs,but I have no idea how exactly to write the code...
Thank you !
Posting some code would be nice that way you can get a direct answer.
but yes use id's
<div class="theexampleclass">
<div id="example"></div>
<div id="example2"></div>
</div>
in css
#example {
z-index: -5;
}
#example2 {
z-index: 10;
}
div {
position: relative;
width: 50px;
height: 50px;
padding: 10px;
margin:5px auto;
border: 1px solid #000;
}
.fst {
top: 0;
left: 0;
z-index: 1;
background: rgba(0,120,0,0.75);
color:gold;
}
.snd {
bottom: 15px;
left: 50px;
z-index: 2;
background: rgba(0,0,190,0.75);
color:gold;
}
.trd {
bottom: 30px;
left: 0;
z-index: 3;
background: rgba(255,0,0,0.75);
color:gold;
}
<div class="fst"> 1st Div </div>
<div class="snd"> 2nd Div </div>
<div class="trd"> 3rd Div </div>
Its very straight forward. Just focus on Z-index properties as other properties are applied to enhance look and feel.
See below working example:
/*--CSS--*/
div {
position: relative;
width: 50px;
height: 50px;
padding: 10px;
border: 1px solid #000;
}
#a {
top: 0;
left: 0;
z-index: 1;
background: rgba(255,0,0,0.75);
}
#b {
top: -25px;
left: 25px;
z-index: 2;
background: rgba(0,255,0,0.75);
}
#c {
top: -50px;
left: 50px;
z-index: 3;
background: rgba(0,0,255,0.75);
}
<!--HTML-->
<div id="a"> A </div>
<div id="b"> B </div>
<div id="c"> C </div>
Demo Fiddle 1 : https://jsfiddle.net/nikdtu/LLepva6L/
Demo Fiddle 2 : http://jsfiddle.net/nikdtu/8yyn6qcq/
I have a big image with a dark overlay covering the front of my webpage. I want to add a div filled with bright text on top of the overlay.
Is there a way to position the div so as to exclude it from the overlay?
HTML:
.overlay {
position: absolute;
background-color: rgba(0, 0, 0, 0.45);
top: 70px;
left: 0px;
right: 0px;
bottom: -200px;
z-index: 1;
}
.about-us {
background-image: url("img.jpg");
width: 1100px;
height: 731px;
display: block;
position: relative;
}
<div class="about-us">
<div class="overlay">
<div class="intro">
<h2>Catchy title</h2>
<p>Small Para</p>
<h1>More txt</h1>
</div>
</div>
</div>
Something like this:
h2 {
background-color: white;
z-index: 2;
}
Assuming that was what you wanted on top.
Use a pseudo element instead of an overlay element.
.about-us:before {
content:"";
position: absolute;
background-color: rgba(0,0,0,0.45);
top: 70px;
left: 0px;
right: 0px;
bottom: -200px;
}
Also you need to explicitly specify position property for intro element in able to interact with the content:
.intro {
position: relative;
}
See example here