Example code for implementing a pure CSS pop-up menu using transform

Example code for implementing a pure CSS pop-up menu using transform

Preface

When making a top menu, you will be required to make a pop-up secondary menu. The previous approach was to use jQuery to control the display and transition animation of the secondary menu, but after using the transform property in CSS3, everything becomes extremely simple.

First the effect

Preparation method

The core is to use the regional displacement method of transform, combined with the hover pseudo class and animation delay of the li tag, so as to simply realize the display of the submenu

<nav>
  <ul>
    <li>
      <strong>home</strong>
      <div>
        cms
        <a href="">crm</a>
      </div>
    </li>
    <li>
      <strong>live</strong>
      <div>
        <a href="">java</a>
        <a href="">php</a>
      </div>
    </li>
    <li>
      <strong>pictrue</strong>
      <div>
        <a href="">mm</a>
        <a href="">dd</a>
      </div>
    </li>
  </ul>
</nav>
 *{
    padding: 0;
    margin: 0;
    box-sizing: border-box;
  }
  body{
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
  }
  nav{
    margin: 10px;
  }
  nav ul {
    list-style-type: none;
    height: 32px;
    display: flex;
  }
  nav ul li{
    margin-right: 10px;
  }
  nav ul li strong{
    text-transform:uppercase;
    background-color: #9b59b6;
    color: white;
    padding: 5px 30px;
    line-height: 30px;
    cursor: pointer;
  }
  nav ul li strong+div{
    display: flex;
    flex-direction: column;
    background-color: #3498db;
    padding: 10px;
    transform: translateY(-110%);
    opacity: 0;
    transition: .3s;
    transform-origin: top;
  }
  nav ul li:hover div{
    transform: translateY(0);
    opacity: 1;
  }
  nav ul li strong+div a{
    color: white;
    text-decoration: none;
    text-transform:uppercase;
    padding: 5px 0;
  }

This concludes this article on using transform to implement a pure CSS pop-up menu sample code. For more related pure CSS pop-up menu content, please search 123WORDPRESS.COM’s previous articles or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  Detailed explanation of the six common constraint types in MySQL

>>:  Detailed description of component-based front-end development process

Recommend

How to delete garbled or special character files in Linux

Due to encoding reasons, garbled characters will ...

Summary of nginx configuration location method

location matching order 1. "=" prefix i...

Learn more about using regular expressions in JavaScript

Table of contents 1. What is a regular expression...

Use pure CSS to disable the a tag in HTML without JavaScript

In fact, this problem has already popped up when I...

Try Docker+Nginx to deploy single page application method

From development to deployment, do it yourself Wh...

Detailed explanation of Linux Namespace User

User namespace is a new namespace added in Linux ...

Vue implements online preview of PDF files (using pdf.js/iframe/embed)

Preface I am currently working on a high-quality ...

Detailed analysis of the difference between Ref and Reactive in Vue3.0

Table of contents Ref and Reactive Ref Reactive T...

An example of how JavaScript can prevent duplicate network requests

Preface During development, we often encounter va...

Ten Experiences in Web Design in 2008

<br />The Internet is constantly changing, a...

Implementation of mysql backup strategy (full backup + incremental backup)

Table of contents Design scenario Technical Point...

Best Practices for MySQL Upgrades

MySQL 5.7 adds many new features, such as: Online...

Vue implements small form validation function

This article example shares the specific code of ...

In-depth understanding of MySQL slow query log

Table of contents What is the slow query log? How...

Understanding flex-grow, flex-shrink, flex-basis and nine-grid layout

1. flex-grow, flex-shrink, flex-basis properties ...