CSS mimics remote control buttons

CSS mimics remote control buttons

Note: This demo is tested in the mini program environment and is applicable to other h5 and pc web pages. You only need to change the mini program unit and tag name to the universal ones and adapt it according to your needs.

The general idea is to lay out four identical squares in a T-shaped pattern and combine them with the rotation attribute.

HTML structure

<view class="button-group">
  <view class="outter-circle">
    <view class="inner-parts brown" bindtap="button" data-type="volAdd">
      <text class="rotate">+</text>
    </view>
    <view class="inner-parts silver" bindtap="button" data-type="chaAdd">
      <text class="rotate">+</text>
    </view>
    <view class="inner-parts blue" bindtap="button" data-type="chaDes">
      <text class="rotate">-</text>
    </view>
    <view class="inner-parts gold" bindtap="button" data-type="volDes">
      <text class="rotate">-</text>
    </view>

    <view class="inner-circle" bindtap="button" data-type="ok">
      <text class="ok rotate">ok</text>
    </view>
  </view>
</view>

CSS Styles

.button-group {
  padding-top: 20rpx;
  width: 300rpx;
  height: 300rpx;
  background-color: pink;
}
.outter-circle {
  position: relative;
  margin-left: 10rpx;
  width: 280rpx;
  height: 280rpx;
  background-color: lightcyan;
  border-radius: 100%;
  overflow: hidden;
  transform-origin: center;
  transform: rotate(45deg);
}
.inner-parts {
  float: left;
  width: 140rpx;
  height: 140rpx;
  line-height: 140rpx;
  text-align: center;
}
.silver {
  background-color: silver;
}
.gold {
  background-color: gold;
}
.blue {
  background-color: blue;
}
.brown {
  background-color: brown;
}
.inner-circle {
  position: absolute;
  margin-top: 70rpx;
  margin-left: 70rpx;
  width: 140rpx;
  height: 140rpx;
  line-height: 140rpx;
  text-align: center;
  border-radius: 100%;
  background-color: lightblue;
}
.rotate {
  display: inline-block;
  transform: rotate(-45deg);
}

Note: If the text area is not inline-block, the rotation property will not take effect!

Button click event

button: function(e) {
    var buttonType = e.currentTarget.dataset.type
    console.log(buttonType)
    switch (buttonType) {
      case 'chaAdd':
        console.log('backward the channel')
      break
      case 'chaDes':
        console.log('forward the channel')
      break
      case 'volAdd':
        console.log('strengthen the volume')
      break
      case 'volDes':
        console.log('weaken the volume')
      break
      default:
        console.log('ok')
    }
  }

Operation effect

Summarize

The above is the CSS imitation remote control button introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

<<:  Demystifying the HTML 5 Working Draft

>>:  VUE Getting Started Learning Event Handling

Recommend

Three useful codes to make visitors remember your website

Three useful codes to help visitors remember your...

Implementation of CSS circular hollowing (coupon background image)

This article mainly introduces CSS circular hollo...

MySql development of automatic synchronization table structure

Development Pain Points During the development pr...

Implementation of two basic images for Docker deployment of Go

1. golang:latest base image mkdir gotest touch ma...

border-radius is a method for adding rounded borders to elements

border-radius:10px; /* All corners are rounded wi...

Navicat Premium operates MySQL database (executes sql statements)

1. Introduction to Navicat 1. What is Navicat? Na...

How to connect to MySQL database using Node-Red

To connect Node-red to the database (mysql), you ...

The ultimate solution for writing bash scripts with nodejs

Table of contents Preface zx library $`command` c...

A Brief Discussion on the Navigation Window in Iframe Web Pages

A Brief Discussion on the Navigation Window in If...

Detailed explanation of jquery tag selector application example

This article example shares the specific code of ...

Detailed explanation of mysql partition function and example analysis

First, what is database partitioning? I wrote an ...

Mysql 5.6 adds a method to modify username and password

Log in to MySQL first shell> mysql --user=root...

Example code of vue icon selector

Source: http://www.ruoyi.vip/ import Vue from ...