I've set up span elements to be visible only when buttons are hovered over. I'd like the span to continue to be visible if the cursor is then moved onto the span element. (This already happens in Chrome by default.) I thought I could do that just with span:hover {visibility: visible}, but it doesn't work. Do I need to add something else as well, or is something else wrong?
reduced CSS:
.tooltipT {
position: absolute;
}
.tooltipT span {
position: absolute;
width: 0px;
visibility: hidden;
}
.tooltipT:hover span, .tooltipT span:hover {
visibility: visible;
width: 400px;
}
.tooltipT:hover span, .tooltipT span:hover {
bottom: 16px;
left: -200px;
}
reduced HTML:
<div class="pix">
<button class="tooltipT" style="top: 50%; left: 50%;">1
<span>blah
</span>
</button>
<img src="img/MIPs.jpg" alt="Melt-in-Place Station details">
</div>
It's live here, the image with the span element involved is half-way down the page, it is used on the pink button in the middle.
I put it on Codepen and am playing with suggested solutions there.
You'll need JavaScript here because the minute you move off the button (to move towards the now visible span), the button is no longer being hovered and so the CSS class no longer applies. This should do it:
button.addEventListener("mouseover", function(){
span.setAttribute("class", "tooltip");
});
Obviously, replace button with the id of your button and tooltip with the name of the class that should be applied when the button is moused over.
It does work if you let the span outside of the button. In this case you'll need the element ~ element or element + element selector to show up the span when hovering the button.
body {
background: honeydew;
}
.tooltipT {
position: absolute;
background: tomato;
width: 50px;
height: 50px;
}
span {
position: absolute;
width: 50px;
height: 50px;
visibility: hidden;
background: gold;
border: 3px solid black;
top: calc(40% - 40px);
left: calc(50% + 40px);
}
span:hover, .tooltipT:hover ~ span {
visibility: visible;
}
button {
border: 3px solid black;
top: 40%;
left: 50%;
}
button:hover {
background: red;
}
<button class="tooltipT">0</button>
<span>_blah</span>
Related
So I did was the snippet I've attached but the problem is when hovering on square area and not in the circle area or in the corner it's jittering. I need to somehow keep the square area as clickable. I'm wondering on how to approach this properly.
.container {
background-color: orange;
width: 150px;
height: 150px;
}
.container:hover {
border-radius: 50%;
background-color: red;
}
<div class="container"> </div>
enter image description here
You can use pseudo elements such as ::after or ::before.
Though they insert content at selected element, ::after inserts content after the selected element and ::before inserts content before the selected element.
content property generates the pseudo element. If you do not set that property, it will be content: none; by default and your pseudo element is not generated.
.container {
background-color: orange;
width: 150px;
height: 150px;
}
.container::after {
content: "";
position: absolute;
height: inherit;
width: inherit;
background-color: red;
opacity: 0;
transition: all .15s linear;
}
.container:hover::after {
opacity: 1;
border-radius: 50%;
}
<div class="container"> </div>
You can use a before pseudo element to be the background, so leaving the actual element untouched on hover.
The before pseudo element is given the same dimensions as the element but changes its background from orange to red on hover, and its radius changes to 50%.
To achieve the correct positioning and sizing of the before pseudo element you need to set the actual element to have a position, in this case the snippet sets it to relative, and the pseudo element is positioned absolute, behind the actual element:
.container {
width: 150px;
height: 150px;
position: relative;
}
.container::before {
content: '';
background-color: orange;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.container:hover::before {
border-radius: 50%;
background-color: red;
}
<div class="container"> </div>
I want to add some pizzazz to some banners... my banners are simply an h1 element with a background color property that stretches the legth of the containing element.
Here is my CSS:
.banner {
position: relative;
z-index: 1000;
padding: 20px;
}
.banner-blue {
background-color: #93DEFF;
color: #222222;
}
.banner-yellow {
background-color: #FFF072;
color: #777777;
}
.banner-red {
background-color: #FF356B;
color: white;
}
And I would apply it like this:
<h1 class="banner banner-yellow">I'm a banner!</h1>
My problem:
I want to overlay a copy of the banner background but change the color and rotate it slightly on the z-axis to get an effect like this.
However I can't work out how to do that using the ::before (or is it ::after) psuedo-elements to do that... here is what I have tried:
.banner-red::before {
display: block;
position: absolute;
padding: 20px;
content: "";
background-color: rgba(255,30,60,0.4);
transform: rotateZ(3deg);
width: 100%;
margin-left: -30px;
}
Here is a codepen of it running: not looking too good: https://codepen.io/jethazelhurst/pen/JyKqRB
Just rotate your box in the opposite direction: transform: rotateZ(-3deg);
You can set the top and left value in order to place your rotated box correctly.
.banner-red::before {
display: block;
position: absolute;
content: "";
background-color: rgba(255,30,60,0.4);
transform: rotateZ(-3deg);
width: 102%;
height: 97px;
margin-left: -30px;
top: 2px;
}
Of course you can change the colors: your horizontal box is #91c6ff and the rotated one is #91c6ff. Also, they are transparent.
Here's a fork of your project: https://codepen.io/anon/pen/zdBVGe
And with the colors:
Make a element with another child element for text, span for example. Then you can set z-index on span so that text is above pseudo element.
div {
background: #91C6FF;
padding: 25px;
margin: 40px;
position: relative;
}
div:after {
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: rgba(135, 171, 255, 0.7);
transform: rotate(-4deg);
}
span {
position: relative;
z-index: 2;
font-size: 30px;
}
<div><span>Lorem ipsum dolor.</span></div>
Trying to have my back and next buttons have an animated 'background' created by a :before element when hovered over. The back and next buttons are located at the sides of the page and are the text of the posts so I don't have full control over their content. I want the background block to stretch from one side to the other (right to left on next, left to right on previous) behind the text.
I want the background block (:before element) to be the full height and width of the text it is behind (text has padding)
css (I left out the transition: css until I can get it working properly.)
#nav-BN {
position: relative;
display: block;
padding: 0;
margin: 50px 0;
}
.nav-previous, .nav-next {
display: block;
position: absolute;
z-index: 1;
}
.nav-previous { left: 0; }
.nav-next { right: 0; }
.nav-previous a, .nav-next a {
display: block;
position: relative;
z-index: 2;
text-align: center;
color: #333;
padding: 10px 20px;
}
.nav-previous a:before, .nav-next a:before {
display: inline-block;
position: absolute;
content: '';
left: 0; top: 0;
height: 100%; width: 0%;
background-color: #000;
}
.nav-previous a:hover:before, .nav-next a:hover:before { width: 100%; }
.nav-previous:before { transform-origin: left center; }
.nav-next:before { transform-origin: right center; }
<div id="nav-BN">
<div class="nav-previous">
<a>link</a>
</div>
<div class="nav-next">
<a>link</a>
</div>
</div>
Issues I've encountered is using 100% width, makes it full width of screen not of the containing div. text jumping around page when hovered, etc
I have used this before and I think it is exactly what you are looking for:
http://ianlunn.github.io/Hover/
Use the example hvr-shutter-out-horizontal :
<a class="hvr-shutter-out-horizontal" href="#">Shutter Out Horizontal</a>
but change the css for .hvr-shutter-out-horizontal to background: transparent;
https://cssanimation.rocks/pseudo-elements/
Hope this helps. Not sure exactly what you are trying to do-
I think you should try
flex box
I got this css modal script and wondering why I can't replace <label> with <a> or <div> tag.
Also, What is the point of this line below? Why can't I replace <input> with something else like <div>?
Here's the complete CSS Code:
.modal {
opacity: 0;
visibility: hidden;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
text-align: left;
background: rgba(0,0,0, .9);
transition: opacity .25s ease;
}
.modal__bg {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
cursor: pointer;
}
.modal-state {
display: none;
}
.modal-state:checked + .modal {
opacity: 1;
visibility: visible;
}
.modal-state:checked + .modal .modal__inner {
top: 0;
}
.modal__inner {
transition: top .25s ease;
position: absolute;
top: -20%;
right: 0;
bottom: 0;
left: 0;
width: 50%;
margin: auto;
overflow: auto;
background: #fff;
border-radius: 5px;
padding: 1em 2em;
height: 50%;
}
.modal__close {
position: absolute;
right: 1em;
top: 1em;
width: 1.1em;
height: 1.1em;
cursor: pointer;
}
.modal__close:after,
.modal__close:before {
content: '';
position: absolute;
width: 2px;
height: 1.5em;
background: #ccc;
display: block;
transform: rotate(45deg);
left: 50%;
margin: -3px 0 0 -1px;
top: 0;
}
.modal__close:hover:after,
.modal__close:hover:before {
background: #aaa;
}
.modal__close:before {
transform: rotate(-45deg);
}
#media screen and (max-width: 768px) {
.modal__inner {
width: 90%;
height: 90%;
box-sizing: border-box;
}
}
and HTML
<p>
<label class="btn" for="modal-1">Show me modal with a cat</label>
</p>
<input class="modal-state" id="modal-1" type="checkbox" />
<div class="modal">
<label class="modal__bg" for="modal-1"></label>
<div class="modal__inner">
<label class="modal__close" for="modal-1"></label>
<h2>The title!</h2>
<p>This is the body</p>
</div>
</div>
JSFIDDLE DEMO
Because clicking on a label will toggle a checkbox, but clicking on a link will go to another page and clicking on a div will do nothing.
The modal depends on the checked state of the input. A div can't be checked.
The whole thing is a nasty hack. It's clever, but nasty. Tracking state in order to display content based on user interaction is a job better handled by JavaScript.
You have to use a label as explained here
This attribute explicitly associates the label being defined with another control. When present, the value of this attribute must be the same as the value of the id attribute of some other control in the same document. When absent, the label being defined is associated with the element's contents.
The label will change the state of the input[type=checkbox] when clicked, and can be placed anywhere on the document.
The input[type=checkbox] must be placed right next to the modal so the modal can be targeted with CSS:
input + .modal { display:none; }
input:checked + .modal { display:block}
The <label> element has a for="" attribute, it looks for the same value of id="" where you set on a form element.
Example: <label for="myid1">...</label> <input id="myid1"> when you click on the label it will change the state of the matching form element. They are normally next to each other in the markup, but not necessarily.
For <input type="checkbox">, you can capture :checked state in the CSS and change some style to itself or next siblings by using + or ~ selector. Which means that modal div needs to be a sibling of the checkbox and next to it.
All of these put in together is to use the label to control the div, a CSS way of making a modal without using any Javascript.
I have a button that is in a div, that is behind another div. The second div overlaps the first by using the css: position: absolute;
Therefore the button is not clickable. Is there any way I can make it clickable like a normal button?
Example: jsfiddle
body {
background-color: blue;
}
.stack {
width: 320px;
height: 240px;
position: absolute;
top: 50%;
left: 50%;
background-color: white;
margin-top: -120px;
margin-left: -160px;
}
.background {
width: 320px;
height: 240px;
background-image: url('http://www.userlogos.org/files/logos/ps1d3r/apple-black-i.png');
top: 0px;
left: 0px;
position: absolute;
}
.card {
pointer-events: none;
width: 320px;
height: 240px;
background-image: url('http://2.bp.blogspot.com/-OIHQM4x8l0U/UEiDLQyiTRI/AAAAAAAAHFs/i1a6rkqQ8tQ/s320/floral+swirl.png');
top: 0px;
left: 0px;
position: absolute;
}
<div class="stack">
<div class="background" onclick="alert('background clicked');">
<button onclick="alert('bg-button clicked');" style="left:65px; top:65px; position: absolute;">This is a background button</button>
<div class="card">
<button onclick="alert('card-button clicked');">This is a card button</button>
<textarea style="left:100px; top:100px; position: absolute;">This is a card textarea</textarea>
</div>
</div>
</div>
You can use pointer-events:none; on .card. This will disable the click event on the .card div and user can click on the button behind it. More info here (MDN).
Here is an example showing how you can enable the click envent on an element hidden behind another one :
button {
margin: 50px;
}
button:focus {
background: red;
}
button:hover {
background: teal;
}
.inFront {
pointer-events: none;
position: absolute;
top: 25px; left: 25px;
right: 25px; height: 150px;
border: 3px solid red;
background: rgba(0, 0, 0, .5);
}
<button onclick="alert('button clicked');">I am a button behind the .inFront div</button>
<div class="inFront"></div>
In this example, the .inFront div is over the button but the pointer-events: none; property on the div allows the button to be clicked, focused and hovered.
Regarding your example, the drawback is that it will also disable the textarea and the "card button" so you will have to change your HTML and move both textarea and card button out of the .card div so they are still clickable. Here is a demo :
DEMO
Use z-index in this case.
<button onclick="alert('bg-button clicked');" style="left:65px; top:65px; position: absolute; z-index:1;">This is a background button</button>
DEMO
This positions the element in the depth field higher than everything else. The higher the number, the higher the stack order.
z-index: 1;
Though, z-index requires positioning such as position: absolute; or position: relative;.
Read a great article about Z-Index here.
Give the button a positive z-index
button {
position: absolute;
z-index: 1;
}
For those who have the same issue as I do where(not restructuring your HTML):
div 1 is on top of div 2
Both div 1 and 2 needs to be clickable/interactive
However div 2 should be infront of div 1
Apply the following codes to div 2:
div2 {
position: absolute; // to manipulate position
z-index: 999; // manipulating the position, putting it in front of div1
pointer-events: visible; // making it interactive, clickable
}