CSS Property Value How to - Switch elements with CSS








Question

We would like to know how to switch elements with CSS.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.spoiler {<!--from www.  j a va  2 s . c  o  m-->
  display: none;
}

.trigger.close {
  display: none;
}

.trigger.open:target {
  display: none;
}

.trigger.open:target+.trigger.close {
  display: inline;
}

.trigger.open:target+.trigger.close+.spoiler {
  display: block;
}
</style>
</head>
<body>
  <a href="#spoiler-open-1" id="spoiler-open-1" class="trigger open">Open</a>
  <a href="#spoiler-close-1" id="spoiler-close-1" class="trigger close">Close</a>
  <div class="spoiler">this is a test</div>
</body>
</html>

The code above is rendered as follows: