Reputation: 875
my function is hide and show div with pure css but when i click open, the button still not disappear.
<a href="#show" id="open" class="btn btn-default btn-sm">Open</a>
<div id="show">
some text...
<a href="#hide" id="close" class="btn btn-default btn-sm">Close</a>
</div>
and the css look like:
<style>
#show {display: none; }
#show:target { display: inline-block; }
#hide:target ~ #show { display: none; }
<style>
when i add this :
#show:target ~ #open { display: none; }
the button #open
still not hiding
anyone can help me.
thanks before :)
Upvotes: 2
Views: 17870
Reputation: 11
Mr_Green Thank you for that code. I modified it for a responsive expanding menu on mobile devices
<input id="menu-toggle" type="checkbox" class="checkbox-toggle" />
<label id="open" for="menu-toggle" class="btn btn-default">Menu</label>
<div id="show">
Some Content
</div>
@media (max-width: 650px) {
input.checkbox-toggle + label {
display: block;
padding:.7em 0;
width:100%;
background:#bbbbbb;
cursor: pointer;
text-align:center;
color:white;
Text-transform:uppercase;
font-family:helvetica, san serif;
}
input.checkbox-toggle:checked + label {
background:#6a6a6a;
}
#show {
display: none;
}
input.checkbox-toggle:checked ~ #show {
display: block;
}
}
input.checkbox-toggle {
display: none;
}
Upvotes: 1
Reputation: 41852
The click functionality can be implemented using Checkbox
for pure css. I modified your HTML as follows:
HTML
<input id="checkbox" type="checkbox" class="checkbox" />
<label id="open" for="checkbox" class="btn btn-default btn-sm"> <span class="show-text"></span>
</label>
<div id="show">some text...
<label for="checkbox" class="second-label btn btn-default btn-sm">Close</label>
</div>
CSS
:checked ~ .btn-default, #show, .checkbox {
display: none;
}
:checked ~ #show {
display: block;
}
.show-text:after {
content:"Open";
}
:checked + .show-text:after {
content:"";
}
.second-label, .show-text {
text-decoration: underline;
cursor: pointer;
}
Upvotes: 3
Reputation: 5670
You could solve it by putting your Open link inside the #show
div
HTML
<div id="show">
<a href="#show" id="open" class="btn btn-default btn-sm">Open</a>
<div id="content">
some text...
<a href="#hide" id="close" class="btn btn-default btn-sm">Close</a>
</div>
</div>
CSS
#content {
display: none;
}
#show:target #content {
display: inline-block;
}
#show:target #open {
display: none;
}
Upvotes: 8