On Click Hide This (button Link) Pure Css
my function is hide and show div with pure css but when i click open, the button still not disappear. Open
Solution 1:
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;
}
Solution 2:
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" />
<labelid="open"for="checkbox"class="btn btn-default btn-sm"><spanclass="show-text"></span></label><divid="show">some text...
<labelfor="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;
}
Solution 3:
Mr_Green Thank you for that code. I modified it for a responsive expanding menu on mobile devices
HTML
<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>
CSS
@media (max-width: 650px) {
input.checkbox-toggle + label {
display: block;
padding:.7em0;
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;
}
Post a Comment for "On Click Hide This (button Link) Pure Css"