Reputation: 81
I have this in CSS :
#box:target {
box-shadow: 0px 0px 20px black;
}
On a "parent" page (page1), I have a button that makes you go to another page : "page2.html#box". So the #box:target
is applied when I the page is loaded.
But with a button on the page1, I activate a function which purpose is to change the #box:target
properties. I'm looking for a way to change this in javascript. Not :focus
.
Upvotes: 0
Views: 174
Reputation: 43910
Notice to Readers
This Answer Concerns the Original Post First Draft
The OP has been edited to an entirely different question. So if this answer is confusing, you'll need to review the edits. I apologize for any inconvenience.
:target
You do not need JavaScript for simple style switch. It appears that you have misunderstood the requirements needed to implement :target
pseudo-class.
Two <a>
nchor tags and a tag of any type as the target.
<a>ON</a> <a>OFF</a> <section>SECTION</section>
One
<a>
will "turn on" the new<section>
style and the other<a>
will "turn it off".
Next, the <section>
needs an #id
. Both <a>
need an href
attribute. The values of each href
is different from the other and is specific (see comment below this example):
<a href="">ON</a> <a href="">OFF</a> <section id="S">SECTION</section>
ON: Must be ☝ OFF: Must be a ☝
the #id of target:#S
"non-jumping" value#/
In the CSS, add two rule sets:
#S { width: 44vw; height: 44vw; border: 4px solid #444 }
:target
pseudo-class:
#S:target { text-shadow: 4px 4px 4px 4px #444; }
Here's what the HTML layout should look like more or less:
<a href="#S">ON</a> <a href="#/">OFF</a> <section id="S">SECTION</section>
html,
body {
font: 900 10vh/1 Consolas;
}
a {
color: blue;
}
a:hover,
a:active {
color: cyan;
}
#B {
box-shadow: 12px 5px 8px 10px inset rgba(0, 0, 0, 0.4);
border: 6px inset rgba(0, 0, 0, 0.8);
width: 40vw;
height: 40vh;
font-size: 20vh;
text-shadow: 4px 7px 2px rgba(0, 0, 0, 0.6);
}
#B:target {
box-shadow: 12px -5px 4px 4px rgba(0, 0, 0, 0.4);
text-shadow: 4px -3px 0px #fff, 9px -8px 0px rgba(0, 0, 0, 0.55);
}
<a href="#B" class='on'>ON_</a><a href="#/" class='off'>OFF</a>
<figure id='B' class='box'>
<figcaption>BOX</figcaption>
</figure>
Upvotes: 1