html 计算器界面

其他链接:
https://www.freecodecamp.org/news/how-to-build-an-html-calculator-app-from-scratch-using-javascript-4454b8714b98/
https://codepen.io/pen/tour/welcome/start

计算器

下面展示一些 内联代码片

<!DOCTYPE html>
<html lang="en">
    <!--
    https://www.freecodecamp.org/news/how-to-build-an-html-calculator-app-from-scratch-using-javascript-4454b8714b98/ 
    https://codepen.io/pen/tour/welcome/start 
    -->
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* // NOTE: You don't need to mess around with 
        // CSS to follow the tutorial. Focus on the 
        // JavaScript instead!
        // =========================

        // Some personal resets */
            html {
                box-sizing: border-box;
            }

            *,
            *::before,
            *::after {
            box-sizing: inherit;
            }

            body {
            margin: 0;
            }

            /* Responsive Images */
            embed,
            iframe,
            img,
            object,
            video {
                max-width: 100%;
            }

            h1,
            h2,
            h3,
            h4,
            h5,
            h6,
            ul,
            ol,
            li,
            p,
            pre,
            blockquote,
            figure,
            hr {
                margin: 0;
                padding-right: 0;
                padding-left: 0;
            }

            a {
                text-decoration: none;
            }

            a:focus {
                outline: none;
            }

            h1,
            h2,
            h3,
            h4,
            h5,
            h6 {
                display: block;
            }

            /* Removes all decimals and discs from lists */
            ol,
            ul {
                list-style: none;
            }

            /* 
            * Completely resets form items
            * ----------------------------
            * Super hard reset that removes all borders
            * and radiuses of all form items (including
            * checkboxes and radios)
            */

            input,
            textarea,
            button {
                border: 0;
                border-radius: 0;
                background-color: transparent;
                font-size: inherit;
                font-family: inherit;
                font-weight: inherit;
                outline: none;
                appearance: none;
                text-align: left;
            }

            input:hover,
            input:active,
            input:focus,
            textarea:hover,
            textarea:active,
            textarea:focus,
            button:hover,
            button:active,
            button:focus {
            outline: none;
            }

            :root {
                font-family: Helvetica, Arial, sans-serif;
            }

            html {
                font-size: 175%;
                font-weight: 300;
                line-height: 1.3;
            }

            body {
                align-items: center;
                background-image: linear-gradient(236deg, #74ebd5, #acb6e5);
                display: flex;
                height: 100vh;
                justify-content: center;
            }

            .container {
                max-width: 20em;
            }

            .container > p {
                text-align: center;
            }

            .calculator {
                border-radius: 12px;
                box-shadow: 0 0 40px 0px rgba(0, 0, 0, 0.15);
                margin-left: auto;
                margin-right: auto;
                margin-top: 2em;
                max-width: 15em;
                overflow: hidden;
            }

            .calculator__display {
                background-color: #222222;
                color: #fff;
                font-size: 1.714285714em;
                padding: 0.5em 0.75em;
                text-align: right;
            }

            .calculator__keys {
                background-color: #999;
                display: grid;
                grid-gap: 1px;
                grid-template-columns: repeat(4, 1fr);
            }

            .calculator__keys > * {
                background-color: #fff;
                padding: 0.5em 1.25em;
                position: relative;
                text-align: center;
            }

            .calculator__keys > *:active::before,
            .calculator__keys > .is-depressed::before {
                background-color: rgba(0, 0, 0, 0.2);
                bottom: 0;
                box-shadow: 0 0 6px 0 rgba(0, 0, 0, 0.5) inset;
                content: "";
                left: 0;
                opacity: 0.3;
                position: absolute;
                right: 0;
                top: 0;
                z-index: 1;
            }

            .key--operator {
                background-color: #eee;
            }

            .key--equal {
                background-image: linear-gradient(to bottom, #fe886a, #ff7033);
                grid-column: -2;
                grid-row: 2 / span 4;
            }

    </style>
</head>
<body>
    
    <div class="container">
        
        <div class="calculator">
          <div class="calculator__display">0</div>
    
          <div class="calculator__keys">
            <button class="key--operator" data-action="add">+</button>
            <button class="key--operator" data-action="subtract">-</button>
            <button class="key--operator" data-action="multiply">&times;</button>
            <button class="key--operator" data-action="divide">÷</button>
            <button>7</button>
            <button>8</button>
            <button>9</button>
            <button>4</button>
            <button>5</button>
            <button>6</button>
            <button>1</button>
            <button>2</button>
            <button>3</button>
            <button>0</button>
            <button data-action="decimal">.</button>
            <button data-action="clear">AC</button>
            <button class="key--equal" data-action="calculate">=</button>
          </div>
        </div>
      </div>


      <script>
        console.log("start");
        const calculator = document.querySelector('.calculator');
        console.log(calculator);
        const keys = calculator.querySelector('.calculator__keys');


        keys.addEventListener('click', e => {
            if (e.target.matches('button')) {
                // Do something
                const key = e.target  
                const action = key.dataset.action  // 得到动作  +-*/

                // 如果不是action,则是数字
                if (!action) {
                    console.log('number key!')
                }

                if (
                    action === 'add' ||
                    action === 'subtract' ||
                    action === 'multiply' ||
                    action === 'divide'
                ) {
                console.log('operator key!')
                }
            }
        })

    </script>
</div>

</body>
</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/65497.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

VIM 编辑器: Bram Moolenaar

VIM 用了很长时间&#xff0c; 个人的 VIM 配置文件差不多10年没有更新了。以前写程序的时候&#xff0c; 编辑都用这个。 linux kernel&#xff0c; boost规模的代码都不在话下。现在虽然代码写的少了&#xff0c;依然是我打开文件的首选。 现在用手机了&#xff0c;配个蓝牙键…

Elasticsearch官方测试数据导入

一、数据准备 百度网盘链接 链接&#xff1a;https://pan.baidu.com/s/1rPZBvH-J0367yQDg9qHiwQ?pwd7n5n 提取码&#xff1a;7n5n文档格式 {"index":{"_id":"1"}} {"account_number":1,"balance":39225,"firstnam…

元宇宙3D数字虚拟客服打造年轻化、数字化营销新品牌

融合了元宇宙、AI和云计算等技术的虚拟数字人&#xff0c;成为元宇宙数字内容交互的载体&#xff0c;将现实世界中的人与虚拟数字世界的场景、模型及产品链接起来&#xff0c;特别是为电力企业打造的电力元宇宙平台&#xff0c;带来营销宣传多重好处的同时&#xff0c;树立了数…

Idea小操作

Idea操作 idea提取内容构成一个方法 idea提取内容构成一个方法

计算机网络—HTTP

这里写目录标题 HTTP是什么HTTP常见状态码HTTP常见字段GET与POST的区别Get和Post是安全和幂等吗PUT幂等&#xff0c;不安全DELETE幂等&#xff0c;不是安全 HTTP缓存技术HTTP缓存实现技术 HTTP1.0优缺点和性能HTTP1.1优缺点和性能HTTP2优缺点和性能HTTP3优缺点和性能HTTP和HTTP…

Zabbix监控华为交换机DHCP接口地址池

一、背景 最近工作中遇到一个因为DHCP地址池满载、导致用户无法获取到IP地址的故障&#xff0c;所以在想通过zabbix 监控DHCP地址池的状态、当DHCP 地址池数量小于某个值时触发zabbix告警。 网上找了一下没有相关的文档、和对应的OID值、于是用Python 脚本的方式实现 二、实现效…

RocketMQ基本概念和高级原理

基础概念 消息模型 RocketMQ 主要由 Producer、Broker、Consumer 三部分组成&#xff0c;其中 Producer 负责生产消息&#xff0c;Consumer 负责消费消息&#xff0c;Broker 负责存储消息。Broker 在实际部署过程中对应一台服务器&#xff0c;每个 Broker 可以存储多个 Topic…

【EI复现】基于阶梯碳交易的含P2G-CCS耦合和燃气掺氢的虚拟电厂优化调度(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

【CHI】(一)基础概念

基于CHI issueF 本章介绍了CHI体系结构和术语。它包含以下部分&#xff1a; 体系结构概述拓扑结构术语事务分类一致性概述组件命名读数据来源 一、CHI架构 CHI架构是一个可扩展的、支持一致性的集线器接口和由多个组件使用的片上互连。根据系统要求的PPA&#xff08;perform…

HR专家:未来零代码开发将成求职热门,你准备好了吗?

一名五十五岁的农民&#xff0c;毫无程式设计经验&#xff0c;靠著自己自学零码开发&#xff0c;竟为他的家乡建起了六个数位资讯系统&#xff0c;其中一个更是带动了乡村“厕所革命”。阿里云说&#xff0c;“也许10-15年以前&#xff0c;公司的招聘会要求员工能够使用 WORD, …

Jmeter学习和一个关于jmeter获取X-XSRF-TOKEN时的坑

Jmeter学习和一个关于jmeter获取X-XSRF-TOKEN时的坑 现在想对一个接口做性能测试&#xff0c;需要测试它多个线程并发下的调用 1.新建测试计划和线程组 略 2.新建http接口 一个完整的http接口包含请求头和请求&#xff0c;这里就需要两个组件&#xff1a;HTTP request、HT…

Java 代码重试实现方式

Java 代码重试实现方式 一.方法内直接自动重试二.静态代理方式1.启动类2.接口3.实现4.静态代理5.单元测试类 三.JDK 动态代理1.代理类2.单元测试 四.CGLIB 动态代理1.动态代理类2.单元测试 五.手动 AOP1.自定义注解2.重试注解切面3.测试类4.单元测试方法 六.Spring Retry1.测试…

虚拟机centos7配置网络

虚拟机centos7配置网络 centos7克隆之后需要配置网络才能联网。 实验环境&#xff1a; VMware Workstation Pro 16CentOS 7系统虚拟机主机Windows 11系统 1.VMware网络模式设置为NAT模式 虚拟机–设置–网络适配器– ​​ ‍ 2.查看虚拟机 子网IP和网关IP 编辑–虚拟网…

pytorch Stream 多流处理

CUD Stream https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#c-language-extensions 中指出在kenel的调用函数中最后一个可选参数表示该核函数处在哪个流之中。 - 参数Dg用于定义整个grid的维度和尺寸&#xff0c;即一个grid有多少个block。为dim3类型。…

Openlayers实战:利用turf获取两个多边形的交集、差集、并集

在数据统计方面,通常会涉及到图形间的交集、并集、差集等。在Openlayers的实战中,我们显示两个多边形的交集、并集、差集的表现。通过turf的方式,可以快速的实现我们的数据处理,具体的请参考源代码。 效果图 源代码 /* * @Author: 大剑师兰特(xiaozhuanlan),还是大剑师…

MySQL 事务原理:事务概述、隔离级别、MVCC

文章目录 一、事务1.1 事务概述1.2 事务控制语句1.3 ACID特性 二、隔离级别2.1 隔离级别的分类2.1.1 读未提交&#xff08;RU&#xff09;2.1.2 读已提交&#xff08;RC&#xff09;2.1.3 可重复读&#xff08;RR&#xff09;2.1.4 串行化 2.2 命令2.3 并发读异常2.3.1 脏读2.3…

Redis实战案例25-附近商铺功能

1. GEO数据结构 Redis中Geohash功能应用 添加地理坐标 求两点之间距离 搜索天安门附近10km的火车站&#xff0c;按升序 2. 导入店铺数据到GEO Redis中存储店铺的信息&#xff0c;将店铺的id和经纬度坐标存到GEO数据类型中去&#xff0c;其中member存id&#xff0c;经纬度对应…

Docker实战-操作Docker容器实战(二)

导语   上篇分享中,我们介绍了关于如何创建容器、如何启动容器、如何停止容器。这篇我们来分享一下如何操作容器。 如何进入容器 可以通过使用-d参数启动容器后会进入后台运行,用户无法查看容器中的信息,无法对容器中的信息进行操作。 这个时候如果我们需要进入容器对容器…

C语言经典小游戏之扫雷(超详解释+源码)

“少年气&#xff0c;是历尽千帆举重若轻的沉淀&#xff0c;也是乐观淡然笑对生活的豁达&#xff01;” 今天我们学习一下扫雷游戏怎么用C语言来实现&#xff01; 扫雷小游戏 1.游戏介绍2.游戏准备3.游戏实现3.1生成菜单3.2游戏的具体实现3.2.1初始化棋盘3.2打印棋盘3.3布置雷…

黑马头条项目学习--Day1: 环境搭建、SpringCloud微服务(注册发现、网关)

Nacos注册发现、网关 a. 项目介绍b. app登录1) 需求分析2) 表结构分析3) 手动加密&#xff08;md5随机字符串&#xff09;4) 用户端微服务搭建5) 功能实现6) app网关7) 网关校验jwt8) 前端集成, 配置nginx a. 项目介绍 业务说明 技术栈说明 [外链图片转存失败,源站可能有防盗…
最新文章