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

Detailed explanation of overflow:auto usage

Before starting the main text, I will introduce s...

Vue echarts realizes dynamic display of bar chart

This article shares the specific code of vue echa...

Linux concurrent execution is simple, just do it this way

Concurrency Functions time for i in `grep server ...

Introduction and usage examples of ref and $refs in Vue

Preface In JavaScript, you need to use document.q...

How to Completely Clean Your Docker Data

Table of contents Prune regularly Mirror Eviction...

Full analysis of MySQL INT type

Preface: Integer is one of the most commonly used...

Tips for viewing text in Linux (super practical!)

Preface In daily development, we often need to pe...

Vue implements student management function

This article example shares the specific code of ...

How to prevent computer slowdown when WIN10 has multiple databases installed

Enable the service when you need it, and disable ...

An example of implementing a simple infinite loop scrolling animation in Vue

This article mainly introduces an example of Vue ...

MySQL Series 12 Backup and Recovery

Table of contents Tutorial Series 1. Backup strat...

Graphic tutorial on installing Ubuntu 18.04 on VMware 15 virtual machine

In the past few years, I have been moving back an...

How to deploy and start redis in docker

Deploy redis in docker First install Docker in Li...

Detailed explanation of grep and egrep commands in Linux

rep / egrep Syntax: grep [-cinvABC] 'word'...