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

What is flex and a detailed tutorial on flex layout syntax

Flex Layout Flex is the abbreviation of Flexible ...

Using JS to implement binary tree traversal algorithm example code

Table of contents Preface 1. Binary Tree 1.1. Tra...

Manually implement the two-way data binding principle of Vue2.0

In one sentence: Data hijacking (Object.definePro...

Detailed tutorial on how to delete Linux users using userdel command

What is serdel userdel is a low-level tool for de...

JavaScript anti-shake and throttling explained

Table of contents Stabilization Throttling Summar...

A brief discussion on logic extraction and field display of Vue3 in projects

Table of contents Logical Layering Separate busin...

Summary of several implementations of returning to the top in HTML pages

Recently, I need to make a back-to-top button whe...

How to run commands on a remote Linux system via SSH

Sometimes we may need to run some commands on a r...

Detailed explanation of CSS3 text shadow text-shadow property

Text shadow text-shadow property effects: 1. Lowe...

Mysql date formatting and complex date range query

Table of contents Preface Query usage scenario ca...

WeChat applet date and time component (year, month, day, hour, and minute)

This article example shares the specific code of ...

Vue detailed introductory notes

Table of contents 1. Introduction 2. Initial Vue ...

Tutorial on installing mysql5.7.23 on Ubuntu 18.04

This article shares with you the specific method ...