Pure CSS Toggle Function

Simple method for creating a toggle function using only CSS - no JS required. What is a pure css toggle function How do you make a pure css toggle function? This script and codes were developed by James Zedd on 15 December 2021, Wednesday.

How do I make an pure css toggle function?
  1. Pure CSS Toggle Function Previews
  2. Pure CSS Toggle Function HTML Codes
  3. Pure CSS Toggle Function CSS Codes
  4. Pure CSS Toggle Function JS Codes
Pure CSS Toggle Function Previews

Pure CSS Toggle Function HTML Codes

<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>Pure CSS Toggle Function</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>
  <div class="container">
  <div class="site-title">
    <h1>Elite World Explorer</h1>
  </div>
  <div class="content">
    <h1>5 Best Desinations in the World</h1>
    <img src="https://placehold.it/700x250" alt="" class="" />
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eget nulla mollis, efficitur urna nec, viverra dolor. Nulla facilisi. Interdum et malesuada fames ac ante ipsum primis in faucibus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Praesent efficitur finibus eros sit amet sagittis. Ut sollicitudin sodales neque et volutpat. Curabitur dictum ante vel fermentum volutpat. Curabitur ac neque et erat viverra egestas.</p>
    <label for="showToggle">Show Toggle</label>
    <input type="checkbox" id="showToggle" />
    <div class="toggle-box">
      <h2>Sign up for our mailing list</h2>
      <input type="text" placeholder="First Name" />
      <input type="text" placeholder="Email Address" />
      <button type="submit">Submit</button>
    </div>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eget nulla mollis, efficitur urna nec, viverra dolor. Nulla facilisi. Interdum et malesuada fames ac ante ipsum primis in faucibus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Praesent efficitur finibus eros sit amet sagittis. Ut sollicitudin sodales neque et volutpat. Curabitur dictum ante vel fermentum volutpat. Curabitur ac neque et erat viverra egestas.</p>
  </div>
</div>
  
    <script src="js/index.js"></script>

</body>
</html>

Pure CSS Toggle Function CSS Codes

.container {
  padding: 20px;
  font-family: 'Lato', arial, sans-serif;
  max-width: 700px;
  margin: 0 auto;
}

.site-title {
  text-align: center;
  border-bottom: 1px solid #111111;
  margin-bottom: 24px;
}

.site-title h1 {
  font-weight: 300;
  text-transform: uppercase;
  letter-spacing: 10px;
}

img {
  width: 100%;
}

.content p {
  line-height: 1.6em;
  margin-bottom: 24px;
}

label {
  cursor: pointer;
  padding: 12px 18px;
  border-radius: 12px;
  background: #31b0d5;
  color: #ffffff;
  transition: all 300ms ease-in-out;
}

label:hover {
  background: #269abc;
}

#showToggle {
  display: none;
}

.toggle-box {
  border-radius: 12px;
  margin-top: 18px;
  padding: 0 18px;
  background: #f1f1f1;
  height: 0;
  overflow: hidden;
  transition: all 300ms linear;
}

.toggle-box h2 {
  margin-top: 0;
}

.toggle-box input {
  text-indent: 4px;
  padding: 4px 0;
  border-radius: 4px;
  border: 2px solid #ffffff;
  margin-bottom: 12px;
}

/*-- The Magic --*/
#showToggle:checked + .toggle-box {
  padding: 24px 18px;
  height: 90px;
}

/* -- */

@media (max-width: 550px) {
  
  .toggle-box input {
    display: block;
    width: 100%;
    box-sizing : border-box;
  }
  
  #showToggle:checked + .toggle-box {
  padding: 24px 18px;
  height: 180px;
}
  
}

Pure CSS Toggle Function JS Codes

// nothing to see here :P
Do you want hide your ip address?Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup.