A user hovers over glyphicon-globe image and behind it lies a like button and a comment form. When a user goes to click on the button or the comment form nothing happens. How can I make clickable what lies behind the globe?
view
<div class="image-container">
<span class="glyphicon glyphicon-globe" style="font-size: 7em; color: white; text-align: center; width: 100%; background-color: #446CB3; border-radius: 4px; padding: 19%;" id="image-foreground"></span>
<div class="text-wrapper">
<div class="like-button">
<%= link_to like_challenge_path(:id => #challenge.id), class: "btn", method: :post do %>
<span class='glyphicon glyphicon-thumbs-up'></span> Like
<% end %>
</div>
<div class="text-background">
<%= render "comments/form" %>
</div>
</div>
</div>
css
.image-container {
position: relative;
height: auto;
#image-foreground {
position: absolute;
z-index: 2;
opacity: 1;
&:hover {
opacity: 0;
}
}
}
.text-wrapper {
opacity: 1;
}
no hover
hover
There's two ways I'd try. So you know, giving an element opacity: 0; won't make it disappear completely. It is still there in position but not able to be seen. To have an element removed also use both opacity: 0; and visibility: hidden in your &:hover action.
The second way you could do it is stick with opacity: 0 but also set z-index: 0 (or any number below the z-index of the underlying layers. You have the hover working nicely but because it has a higher z-index than the underlying layers, it is still technically sitting on top of them and covering them, making them unclickable.
Hope that helps
Also a side note to the answer below, one of the answers here suggested using display: none in your hover action. display: none doesn't work for this as once an element is set to display: none, it is no longer there, not part of the DOM and so breaks the hover action.
you could do on hover display the blue screen as none.
.image-container:hover {
display: none;
}
it that what you wanted ?
Here was the trick that worked:
.hide-globe {
position: absolute;
width: 100%;
background-color: #ccac00;
padding: 100px;
}
.text-wrapper {
position: absolute; // This was essential
opacity: 0;
z-index: 1;
width: 100%;
&:hover {
opacity: 1;
background-color: white; // And this helped make the image seemingly go away
}
}
Related
So I thought it'd be a great idea to add tooltips to my Neocities site, but I seem to have run into an issue I can't find the answer to...
Okay for some ungodly reason my tooltip class isn't working. I assigned my div the class, and the span inside it the tooltiptext class, but it would still just use what I had assigned the body. I only noticed this when the text was still white, when it should've been black, among other things.
Here's the html section:
<h1>please god ignore the background, I haven't found a good one yet</h1>
<img id="A wooden door framed with clip-art of flowers." style="position: relative;" src="images/flowerydoor.png" />
<div class="tooltip">
<p>this is literally copy+pasted from w3schools what the actual fuck-
<span class="tooltiptext">wait a minute this should have black text why isn't the class working</span></p>
</div>
I'm including the header and image parts because I'm desperate and worry the answer lies within one of the miniscule details
here's the stylesheet:
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: white;
color: black;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
body {
background-color: #fbb291;
color: white;
font-family: Verdana;
}
Once again all copy+pasted from w3schools just to make sure it wasn't me
Like I said, the text of the tooltip-assigned div still has white text, and nothing from the tooltip class...
Either the body is overriding my class, or there's something going on with the class itself that's stopping it from working.
I don't know if this helps, but I have assigned a class to my body, which works perfectly fine. I'm wondering if there's something going on with it? I mean, it shouldn't, because I have another page using said class, along with divs using other classes that work perfectly fine!
.door {
margin: 0 auto;
background-image: url("https://64.media.tumblr.com/1adbeafb3ca992a7681ede48ddedcbbd/d5886a952040c00b-9b/s250x400/a917bb1772111a1460eac4922c0502e0ba860bd1.jpg");
/*position: relative;*/
width: 600px;
height: 900px;
text-align: center;
}
I apologize if I'm not making much sense, I'm not super familiar with certain html and css terms.
In this snippet based on your code, the tooltip text is black:
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: white;
color: black;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
body {
background-color: #fbb291;
color: white;
font-family: Verdana;
}
<h1>please god ignore the background, I haven't found a good one yet</h1>
<img id="A wooden door framed with clip-art of flowers." style="position: relative;" src="images/flowerydoor.png" />
<div class="tooltip">
<p>this is literally copy+pasted from w3schools what the actual fuck-
<span class="tooltiptext">wait a minute this should have black text why isn't the class working</span></p>
</div>
If you're using other libraries with their own CSS or are deploying this on a third-party website, there could be a namespace collision. You can check what styles are applying to an HTML element using the Chrome DevTools or similar tools in other browsers. Here is a guide for doing this in Chrome: https://developer.chrome.com/docs/devtools/css/overrides/
The main issue is caused by a button being circular. But I really want a circular button, which is leading to hovering problems!
All I want is to have a circular <a> button that when hovered-over will reveal another element below it, like a div or another a tag. These two elements are separated by a gap.
Then I should be able to move my mouse down and hover over the revealed element and click on it or whatever. But of course if you unhover the original <a> then the other element will disappear, especially since there is a gap between the two elements. What is the best way to make it so that I can move my mouse from element 1 to element 2 without element 2 vanishing during mouse travel?
Ideally this shouldn't require JS.
I've created a basic setup for this so far to get started:
body {
padding: 30px;
height: 100vh;
}
#myBtn {
background-color: grey;
padding: 20px;
border-radius: 50%;
}
#hoverInfo {
display: none;
margin-top: 40px;
background-color: green;
width: 100px;
height: 50px;
}
#myBtn:hover + #hoverInfo, #hoverInfo:hover {
display: block;
}
<a id="myBtn" href="/">
button
</a>
<a id="hoverInfo" href="/">hover info</a>
Here's an explanation of an old solution attempt of mine:
My first solution to stop element 2 from vanishing upon downward movement of the mouse was to put an invisible hoverable element between elem 1 and 2 which would keep elem 2 active while the mouse moves down to it. And this would work great, IF all elements were rectangular. But my elem 1 is circular!
This means that there is literally one single pixel of contact between the middle hover buffer element and elem 1 because there are those circular "corner" gaps between elem 1 and the invisible middle element. So whenever you move your mouse down, you are still going to miss that middle hover element 99% of the time.
And you can't put it behind elem 1 either to fill in those circular "corners" because the circular element has a bounding box that you can only see in inspect element and this bbox prevents you from filling up those "corners" with an area that actually interacts with the mouse, therefore making this solution useless. It's quite confusing in my explanation but try it out if you manage to implement this "solution".
The first solution to come to mind is wrapping the circular button into a parent div, which will be the div that will activate the hover effect. This way, you can add padding-bottom to imitate the gap look while still making the "gap area" trigger the hover effect. In the snippet below, I made the wrapper div have a red background so you can see how it works. If you remove the red background, it should function as intended.
https://codepen.io/xenvi/pen/yLONOEa
body {
padding: 30px;
height: 100vh;
}
.buttonWrapper {
display: inline-block;
margin-bottom: 40px;
background: red;
}
#myBtn {
background-color: grey;
padding: 20px;
border-radius: 50%;
}
#hoverInfo {
display: none;
background-color: green;
width: 100px;
height: 50px;
}
.buttonWrapper:hover+#hoverInfo,
#hoverInfo:hover {
display: block;
}
.buttonWrapper:hover {
margin: 0;
padding-bottom: 40px;
}
<div class="buttonWrapper">
<a id="myBtn" href="/">
button
</a>
</div>
<a id="hoverInfo" href="/">hover info</a>
You can solve this easily using a pseudo element that will make the hoverable area bigger and that you activate only on hover:
body {
padding: 30px;
height: 100vh;
}
#myBtn {
background-color: grey;
padding: 20px;
border-radius: 50%;
position:relative;
}
#myBtn:before {
content:"";
display:none;
position:absolute;
top:90%;
left:0;
right:0;
height:28px;
}
#hoverInfo {
display: none;
margin-top: 40px;
background-color: green;
width: 100px;
height: 50px;
}
#myBtn:hover::before {
display:block;
background:rgba(0,0,255,0.2); /* to illustrate */
}
#myBtn:hover + #hoverInfo, #hoverInfo:hover {
display: block;
}
<a id="myBtn" href="/">
button
</a>
<a id="hoverInfo" href="/">hover info</a>
I have very weird problem. So let try explan you. Im developing web application thats going to be used on mobiles. Everything is going well, but i hit a very nasty problem. The app is simple, we have Welcome screen from where you have just on button called Get Strated (near in the middle of screen), after clicking this button app switch to page with listing products in 2x2 grid. Every product has hover effect which blur the image and show name and price. So i hope everything till now sounds good? The problems ocurs when user clicks Get Started and the page render after that automaticly has the item which is on the same place as button 'hovered' which seems strange behavior because you won't to see any of those items pre-selected.
Step one:
main welcome screen when the user clicks Get Started button:
Step two: user has clicked Get Started and goes to products list with one item marked as selected/clicked because of hover effect
Here is the html/css, just an regular hover effect thats add blur and show prodcut name&price:
<ul className="list-products">
{productsStore.menuProducts.filter(p => p.sectionId == productsStore.activeSectionId).map((product, index) => {
return (
<li key={index} onClick={() => handleOnProductClick(product.id)}>
<button>
<small style={{ backgroundImage: "url(" + getDefaultImage(product.image) + ")" }}></small>
<strong id={product.id}>
<span>
{product.name}
<em>{product.price.toFixed(2)}</em>
</span>
</strong>
</button>
</li>
)
})}
</ul>
.list-products { display: -moz-flex; display: -ms-flex; display: -o-flex; display: flex; flex-wrap: wrap; }
.list-products li { width: 50%; position: relative; padding-bottom: 50%; border-bottom: 1px solid #252525; }
.list-products li:nth-child(odd) { border-right: 1px solid #252525; }
.list-products li button { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: #fff; border: 0; border-radius: 0; }
.list-products li button strong { position: absolute; top: 0; left: 0; width: 100%; height: 100%; font-weight: 400; background: rgba(0,0,0,.3); opacity: 0; }
.list-products li button:hover strong { opacity: 1; }
.list-products li button strong { display: -moz-flex; display: -ms-flex; display: -o-flex; display: flex; align-items: flex-end; justify-content: center; padding: 10px; }
.list-products li button span { display: inline-block; font-size: 18px; text-align: left; width: 100% }
.list-products li button span em { font-style: normal; display: block; }
.list-products li button small { background-size: cover; background-position: center; position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
.list-products li button:hover small { filter: blur(2px); -webkit-filter: blur(2px); }
I have forgot to mention that I'm using React. Also this behaviour couldn't be reproduced on PC even with mobile view enabled. It is possible only on mobile devices and I have tested it on iphone with safari browser.
What i think is happening: since we are on mobile device, hover effect triggers when users click somewhere on the screen and till the user click onther place, hover keep staying there and since we clicked Get Started (right side of button), the browser thinks we are hovering there and thats why it show as hovered? But now whats the solution here?
Your guess is exactly right. Hover effects do not work correctly on mobile. When a user clicks on the element it quickly triggers the hover effect before taking them to the next link. Sometimes phones will cache that triggered the hover effect and make it always appear that way. Instead of hover effects, you would only want to use on-click effects for mobile. Maybe one day our phones will support this better.
I have an image link that has a :hover functionality to show text on top of the image on rollover and then on click you are taken to the new web page.
However on mobile (only been tested on safari mobile), one tap shows the hover functionality and then the second tap takes you to the page. I don't want this, I could see that being beneficial for a drop down menu, but for my use case it just makes the ui more confusing.
I want it to go straight to the page on one tap, which is what happens with normal links with a:hover.
Here's my code:
.thumb_text {
position: absolute;
top: 0;
left: 2.531645569620253%;
width: 73.83966244725738%;
padding-top: 12px;
z-index: 1;
color: white;
}
.the_line_thumb {
position: relative;
overflow: hidden;
}
.the_line_thumb img {
height: 200px;
width: 500px;
background-color: yellow;
}
.the_line_thumb_text {
display: none;
}
.the_line_thumb:hover img {
filter: brightness(40%);
}
.the_line_thumb:hover .the_line_thumb_text {
display: block;
}
<a href="https://example.com">
<div class="the_line_thumb">
<img src="example.png">
<div class="the_line_thumb_text thumb_text">
<h1>Hello Stack Overflow</h1>
<p>
Hope you're having a great day and thanks for trying to help me out.
</p>
</div>
</div>
</a>
Via saurabh (in the comments): The issue seems to be an ios issue to do with an inability to deal with the muiltiple :hover entries like desktop can.
You might want to consider the Level 4 Media Query spec which allows for direct targeting of devices which support hover.
#media(hover: hover) and (pointer: fine) {
.the_line_thumb:hover img {
filter: brightness(40%);
}
}
Demo
.thumb_text {
position: absolute;
top: 0;
left: 2.531645569620253%;
width: 73.83966244725738%;
padding-top: 12px;
z-index: 1;
color: white;
}
.the_line_thumb {
position: relative;
overflow: hidden;
}
.the_line_thumb img {
height: 200px;
width: 500px;
background-color: yellow;
}
.the_line_thumb_text {
display: none;
}
.the_line_thumb:hover .the_line_thumb_text {
display: block;
}
.the_line_thumb:hover .plus {
color: #ffbdff;
background-color: white;
}
#media(hover: hover) and (pointer: fine) {
.the_line_thumb:hover img {
filter: brightness(40%);
}
}
<a href="https://example.com">
<div class="the_line_thumb">
<img src="example.png">
<div class="the_line_thumb_text thumb_text">
<h1>Hello Stack Overflow</h1>
<p>
Hope you're having a great day and thanks for trying to help me out.
</p>
</div>
</div>
</a>
Support
I know this question has been asked a hundred times and I have read every last one of them.
I have an image that is also a link. When the image is hovered it shows a new image and I have a small paragraph description I would like to pop up next to the image when the link is hovered over as well. Simple, right?
What i'm doing makes sense to me, and is the answer to this question. What am I doing wrong? This seems very straightforward.
How to show text on image when hovering?
I will paste my relevant code. Comparing to the posted link answer, I have the class project1 instead of imgWrapper and novelDescrip instead of imgDescription
HTML
<div class="project1">
<img id="novel" src="img/newnovel.png" onmouseover="this.src='img/newnovelblue.png'" onmouseout="this.src='img/newnovel.png'" />
<p class="novelDescrip" >A website for a local musician to market, stream, and distribute music and merchandise.</p>
</div>
CSS
.project1 p {
width: 25%;
margin: 20px 15px 0 0;
float: right;
}
.novelDescrip {
position: absolute;
top:0;
bottom: 0;
left: 0;
right: 0;
visibility: hidden;
opacity: 0;
-webkit-transition: visibility opacity 0.2s;
}
.project1:hover .novelDescrip {
visibility: visible;
opacity: 1;
}
EDIT
Here is my problem now, the text hides and reveals but the hover is activated anytime my mouse is hovering in the area enclosed by the rectangle I drew on this image. Any ideas on why this is happening?
You don't need the the positions. top:0;left: 0; with absolute positioned div will always show up on top left corner of the browser. also added display:inline for the novelDescrip for the div to show-up next to the image.
.project1 p {
width: 25%;
margin: 20px 15px 0 0;
float: right;
}
.novelDescrip {
position: absolute;
visibility: hidden;
opacity: 0;
-webkit-transition: visibility opacity 0.2s;
display:inline;
}
.project1:hover .novelDescrip {
visibility: visible;
opacity: 1;
}
Hope this is what you are looking for.
My be this will solve your problem
img {
height:30%;
width:30%;
}
.project1 p
{
width: 65%;
float: right;
display:none;
margin-left:5px;
}
.project1:hover .novelDescrip
{
display:block;
}
Live Demo