With pure HTML and CSS it is possible to show and hide content with an anchor tag:
#red { background: red; }
#blue { background: blue; }
#green { background: green; }
.box {
width: 200px;
height: 200px;
display: none;
}
.box:target {
display: block;
}
Red item | Blue item | Green item
<div class="box" id="red"></div>
<div class="box" id="blue"></div>
<div class="box" id="green"></div>
But how can I display the first (red) item on page load?
If you're ok with modifying the html, and putting the red box last then you can do something like:
#red {
background: red;
display: block;
}
#blue { background: blue; }
#green { background: green; }
.box {
width: 200px;
height: 200px;
display: none;
}
.box:target {
display: block;
}
.box:target ~ #red {
display: none;
}
The solution is somehow easy but I cannot show it here. If you are using this code within a page you simply need to append the anchor of the the first a tag to the url to activate its target. So you need to simply do something like this:
wwww.page.html#red
Here is a screenshot of the result:
This will work without modifying the code and you can choose which one to make visible at the start.
You can try this:
#red { background: red; display:block;}
#blue { background: blue; }
#green { background: green; }
.box {
width: 100%;
height: 100%;
display: none;
position: absolute;
top: 0;
left: 0;
}
.box:target {
display: block;
}
.wrapper {
position: relative;
width: 200px;
height: 200px;
}
Red item | Blue item | Green item
<div class="wrapper">
<div class="box" id="red"></div>
<div class="box" id="blue"></div>
<div class="box" id="green"></div>
</div>
Solution(s) :-
<style>
#red {
background: red;
}
#blue {
background: blue;
}
#green {
background: green;
}
.box {
display: none;
}
.box:target {
display: block;
}
</style>
Red item |
Blue item |
Green item
<div class="box" id="red">Red</div>
<div class="box" id="blue">Blue</div>
<div class="box" id="green">Green</div>
Explanation(s) :-
I Finally found a solution for your answer but ...
for it to work properly , you need to add a background color ....
finally , I hope that it is what you wanted .....
Notes And References :-
currently , i have no references for above codes ,
but ,
NOTE : Please Add Background color fr it to work properly
Related
This question already has answers here:
Is it possible to cancel parent hover style when a child element is hovered?
(2 answers)
Closed 5 months ago.
The problem is, when I hover my yellow box, the hover effect is running. How to avoid this effect when I am hover stricte yellow box.
.p {
width: 200px;
height: 200px;
background: red;
}
.c {
width: 100px;
height: 100px;
background: yellow;
}
.p:hover {
background: blue;
}
<div class="p">
<div class="c"></div>
</div>
A solution w/o JS:
.wrapper {position: relative}
.p {
position: absolute;
top:0;
left:0;
width: 200px;
height: 200px;
background:red;
}
.c {
position: absolute;
top:0;
left:0;
width: 100px;
height: 100px;
background: yellow;
}
.p:hover {
background: blue;
}
}
<div class="wrapper">
<div class="p"></div>
<div class="c"></div>
</div>
Turns out this is possible with CSS. However, you can also try to accomplish this with a JQuery hover effect..
$(function() {
$('.p').on('mouseover', function(e) {
if (e.target === this) {
$('.p').css('background', 'blue');
}
})
.on('mouseout', function() {
$('.p').css('background', 'red');
});
});
.p {
width: 200px;
height: 200px;
background:red;
}
.c {
width: 100px;
height: 100px;
background: yellow;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="p">
<div class="c"></div>
</div>
I have really simple solution for this.
just create a new class
.noHover{ pointer-events: none; }
and use this to disable any event on it. use it like:
<a href='' class='btn noHover'>You cant touch ME :P</a>
So I have an element that I want to show a tooltip for. But of course, to show this tooltip, I need to make it go above everyhing, no matter what (including overflow: hidden parents). Right now I'm making this happen with the :hover::after rule, but the element's been hidden beneath siblings with a backdrop-filter: blur(...) style.
Minimal reproducable example:
.nephew {
backdrop-filter: blur(10px);
background-color: #0005;
width: 100px;
height: 100px;
}
.nephew.tooltip {
position: relative;
}
.tooltip:hover::after {
content: 'This is a very long tooltip';
background-color: white;
z-index: 999999999;
position: absolute;
width: max-content;
}
.main {
display: flex;
}
<div class="main">
<div class="nephew"></div>
<div class="nephew tooltip"></div>
<div class="nephew"></div>
</div>
Please tell me how to fix this problem. I'm also open to new solutions, since I'm aware this is a bodgy way of implementing this feature.
You need to bring the container div forward too and not just the pseudo element.
Include this CSS and it should now work fine:
.nephew:hover {
z-index: 99999999;
}
Updated example:
.nephew {
backdrop-filter: blur(10px);
background-color: #0005;
width: 100px;
height: 100px;
}
.nephew:hover {
z-index: 99999999;
background-color: #0004; /* just added this to highlight the container */
}
.nephew.tooltip {
position: relative;
}
.tooltip:hover::after {
content: 'This is a very long tooltip';
background-color: white;
z-index: 999999999;
position: absolute;
width: max-content;
}
.main {
display: flex;
}
<div class="main">
<div class="nephew"></div>
<div class="nephew tooltip"></div>
<div class="nephew"></div>
</div>
One approach to solving this might be to apply to the ::after pseudo-element something like:
transform: translateY(-24px)
to raise the tooltip above the row of squares so that it isn't automatically truncated by the next square in the row.
Working Example:
.main {
display: flex;
width: 600px;
margin-top: 24px;
}
.nephew {
position: relative;
width: 100px;
height: 100px;
background-color: rgb(0, 0, 127);
}
.nephew.tooltip {
background-color: rgb(63, 63, 127);
}
.nephew::after {
content: '';
position: absolute;
top: 0;
left: 0;
background-color: white;
white-space: nowrap;
}
.nephew.tooltip:hover::after {
content: 'This is a very long tooltip';
transform: translateY(-20px);
}
<div class="main">
<div class="nephew tooltip"></div>
<div class="nephew"></div>
<div class="nephew tooltip"></div>
<div class="nephew"></div>
<div class="nephew tooltip"></div>
<div class="nephew"></div>
</div>
i going to create a progress bar, just like the picture below(ues red and green for sharp contrast).
progress bar
my codes is as follows
// react
class App extends React.Component {
render () {
return (
<div className='home-page-wrapper'>
<ProgressBar />
</div>
);
}
}
// css
.outter {
width: 260px;
height: 46px;
border-radius: 22px;
background: green;
overflow: hidden;
.inner {
width: 100%;
height: 100%;
background: red;
transform: translateX(100px);
}
}
the problem is that the red div can not full cover the green one, it looks like that the red div has a green border, how can i do?
Please try this:
.progress-bar {
width:90%;
height:30px;
overflow:hidden;
background:green;
border-radius:6px;
}
.bar {
float:left;
height:100%;
background:red;
}
<div class="progress-bar">
<div class="bar" style="width:45%">
</div>
</div>
You may use this code:
.outter {
width: 260px;
height: 46px;
border-radius: 22px;
background: green;
overflow: hidden;
}
.outter .inner {
height: 100%;
background: red;
border-radius: 22px;
}
<div class="outter">
<div class="inner" style="width: 70%;"></div>
</div>
change the .inner width property to perform the progression.
In the below examples I have 2 div's, What I'm trying to figure out is how to make .two green when .one is .active. Is it possible? jsFiddle
div {
position: relative;
height: 100px;
width: 300px;
}
.one {
background: red;
}
.two {
background: blue;
}
.one.active ~ .two {
background: green;
}
<directive-one>
<div class="one active">
First block
</div>
</directive-one>
<directive-two>
<div class="two">
Second block
</div>
</directive-two>
You can do this be referencing the directives specifically in css
div {
position: relative;
height: 100px;
width: 300px;
}
.one {
background: red;
}
.two {
background: blue;
}
directive-one:active ~ directive-two > .two {
background-color: green;
}
<directive-one>
<div class="one active">
First block
</div>
</directive-one>
<directive-two>
<div class="two">
Second block
</div>
</directive-two>
You can also just remove the directives so the divs can be accessed
div {
position: relative;
height: 100px;
width: 300px;
}
.one {
background: red;
}
.two {
background: blue;
}
.one:active ~ .two {
background-color: green;
}
<div class="one active">
First block
</div>
<div class="two">
Second block
</div>
Otherwise, I dont believe its possible to access a div that isnt a sibling or child, which is the case with the <div> inside the <directive-one> trying to access another <div> inside another <directive-two>
If you mark the directive-one with active, then it is possible to do with this css:
directive-one.active ~ directive-two > .two {
background: green;
}
I don't think it is possible to dig into the 'preceding' element though, but not totally sure.
My idea is, when my Boolean variable is true, than a grey container with a opacity overlaps the orange and with a higher z-index.
I can't click on some buttons or else inside the orange container.
But I need the flexbox on the wrapper.
At the moment, my idea with the z-index failed, and it's flex in a row.
How can I fix this and put the grey above the orange (both 100% width and high of the wrapper) and still using flexbox.
Important: When its overlapped, I can't click in the orange container, looking like it is disabled.
I've got following code:
angular.module("myApp", []).controller("myController", function($scope) {
$scope.isDisabled = true;
});
.wrapper {
display: flex;
width: 100%;
height: 50px;
border: 1px solid red;
z-index: 100;
}
.overlapped {
width: 100%;
height: 100%;
background-color: grey;
opacity: 0.5;
z-index: 102;
}
.someContent {
width: 100%;
height: 100%;
background-color: orange;
z-index: 101;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController" class="wrapper">
<div ng-if="isDisabled" class="overlapped"></div>
<div class="someContent">I have some random content...</div>
</div>
To make the container overlaying the other:
just use position:relative in the parent .wrapper and position:absolute in overlapped
To disable the orange container:
use pointer-events:none linked to your Boolean variable. (might be optional)
angular.module("myApp", []).controller("myController", function($scope) {
$scope.isDisabled = true;
$scope.isPointer = true;
});
.wrapper {
display: flex;
width: 100%;
height: 50px;
border: 1px solid red;
position: relative;
}
.overlapped {
width: 100%;
height: 100%;
background-color: grey;
opacity: 0.5;
z-index: 1;
position: absolute;
}
.someContent {
width: 100%;
height: 100%;
background-color: orange;
}
.pointer-events {
pointer-events: none
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myController" class="wrapper">
<div ng-if="isDisabled" class="overlapped"></div>
<div ng-if="isPointer" class="someContent pointer-events">I have some random content...</div>
</div>