html 计算器界面

news2024/10/5 13:43:31

其他链接:
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.coloradmin.cn/o/846228.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

使用Spring Initializr方式构建Spring Boot项目

除了可以使用Maven方式构建Spring Boot项目外&#xff0c;还可以通过Spring Initializr方式快速构建Spring Boot项目。从本质上说&#xff0c;Spring lnitializr是一个Web应用&#xff0c;它提供了一个基本的项目结构&#xff0c;能够帮助我们快速构建一个基础的Spring Boot项目…

Effective Java笔记(28)列表优于数组

数组与泛型相比&#xff0c;有两个重要的不同点 。 首先&#xff0c;数组是协变的&#xff08; covariant &#xff09; 。 这个词听起来有点吓人&#xff0c;其实只是表示如果 Sub 为 Super 的子类型&#xff0c;那么数组类型 Sub[ ]就是Super[ ]的子类型。 相反&#xff0c;泛…

HTML 元素的 class 和 id 属性有何区别?

聚沙成塔每天进步一点点 ⭐ 专栏简介⭐ 唯一性⭐ 选择器权重⭐ JS操作⭐ CSS和JavaScript引用⭐ 写在最后 ⭐ 专栏简介 前端入门之旅&#xff1a;探索Web开发的奇妙世界 记得点击上方或者右侧链接订阅本专栏哦 几何带你启航前端之旅 欢迎来到前端入门之旅&#xff01;这个专栏…

【网络】自定义协议 | 序列化和反序列化 | 以tcpServer为例

本文首发于 慕雪的寒舍 以tcpServer的计算器服务为例&#xff0c;实现一个自定义协议 阅读本文之前&#xff0c;请先阅读 tcpServer 本文完整代码详见 Gitee 1.重谈tcp 注意&#xff0c;当下所对tcp的描述都是以简单、方便理解起见&#xff0c;后续会对tcp协议进行深入解读 …

威纶通触摸屏插入U盘自动登录,拔出U盘自动注销

威纶通触摸屏官网的 Easybuilder Pro 手册 第十章有该功能的使用方法。 在工程文件中设置好账号密码&#xff0c;启用USB登录。 将 U 盘插入电脑&#xff0c;在 EBPro 的安装路径下找到 Administrator Tools&#xff0c;打开 设置账号密码&#xff0c;储存到U盘&#xff0c;之…

你知道函数栈帧的创建和销毁吗?

文章目录 前言观图有感一、概述二、寄存器三、汇编指令四、函数栈帧的创建4.1 main函数栈帧的创建push ebpmov ebp,espsub esp,0E4hpush ebx / esi /edilea edi,[ebp-24h] 、mov ecx,9、mov eax,0CCCCCCCCh、rep stos dword ptr es:[edi]main函数中变量的创建 4.2 在main函数中…

Focal and Global Knowledge Distillation for Detectors(CVPR 2022)原理与代码解析

paper&#xff1a;Focal and Global Knowledge Distillation for Detectors official implementation&#xff1a;https://github.com/yzd-v/FGD 存在的问题 如图1所示&#xff0c;前景区域教师和学生注意力之间的差异非常大&#xff0c;背景区域则相对较小。此外通道注意力…

【错误记录】Uncaught SyntaxError: Not available in legacy mode

错误记录&#xff1a;Uncaught SyntaxError: Not available in legacy mode 错误描述&#xff1a;在vite脚手架项目当中&#xff0c;使用vue-i18n插件进行国际化多语言时&#xff0c;报错 解决方案&#xff1a; 在引入vue-i18n 处&#xff0c;添加 legacy: false 如果对项目…

玩转Vue3:计算属性和监视属性深度解析

计算属性computed Vue中的计算属性是一种特殊的属性&#xff0c;它可以根据依赖的数据动态计算并返回结果。计算属性的值是通过getter函数计算得到的&#xff0c;当依赖的数据发生变化时&#xff0c;计算属性会自动重新计算并更新视图。计算属性具有缓存机制&#xff0c;只有当…

SSM的知识点考试系统java在线问答试卷管理jsp源代码mysql

本项目为前几天收费帮学妹做的一个项目&#xff0c;Java EE JSP项目&#xff0c;在工作环境中基本使用不到&#xff0c;但是很多学校把这个当作编程入门的项目来做&#xff0c;故分享出本项目供初学者参考。 一、项目描述 SSM的知识点考试系统 系统1权限&#xff1a;管理员 …

把大模型装进手机,分几步?

点击关注 文 | 姚 悦 编 | 王一粟 大模型“跑”进手机&#xff0c;AI的战火已经从“云端”烧至“移动终端”。 “进入AI时代&#xff0c;华为盘古大模型将会来助力鸿蒙生态。”8月4日&#xff0c;华为常务董事、终端BG CEO、智能汽车解决方案BU CEO 余承东介绍&#xff0c…

【计算机网络】UDP服务器实现网络聊天室

前言 上一篇文章我们简单了解了一下什么是套接字编程&#xff0c;这篇文章我们利用UDP套接字来实现一个简单的网络聊天室。 编写UDP套接字服务器 成员变量 // 1. socket的id&#xff0c;相当于文件id int _sock; // 2. port uint16_t _port;// 3 一个线程负责收放消息&…

JUC并发、JVM相关

文章目录 JUC并发synchronized锁对象底层原理 synchronized锁升级reentrantlock公平锁和非公平锁可重入锁 / 递归锁 死锁死锁产生条件如何排查死锁?如果解决死锁&#xff1f; LockSupport与中断机制中断机制中断相关的三大API如何中断运行中的线程&#xff1f; LockSupportLoc…

【C++】C++11--- 线程库及详解lock_guard与unique_lock

目录 一、thread类的介绍二、线程函数参数三、 原子性操作库四、lock_guard与unique_lock4.1、mutex的种类4.2 lock_guard4.3 unique_lock 一、thread类的介绍 在C11之前&#xff0c;涉及到多线程问题&#xff0c;都是和平台相关的&#xff0c;比如**windows和linux下各有自己…

【css】属性选择器

有些场景中需要在相同元素中获取具有特定属性的元素&#xff0c;比如同为input&#xff0c;type属性有text、button&#xff0c;可以通过属性选择器设置text和button的不同样式。 代码&#xff1a; <style> input[typetext] {width: 150px;display: block;margin-bottom…

自动配置要点解读

目录 要点1&#xff1a;什么是自动配置&#xff1f; 要点2&#xff1a;配置文件与默认配置 要点3&#xff1a;自动配置设置思想来源 要点4&#xff1a;spring.factories文件作用 要点5&#xff1a;自动配置的核心 本文只对自动配置的思想进行基本的解读&#xff0c;不涉…

21、p6spy输出执行SQL日志

文章目录 1、背景2、简介3、接入3.1、 引入依赖3.2、修改database参数&#xff1a;3.3、 创建P6SpyLogger类&#xff0c;自定义日志格式3.4、添加spy.properties3.5、 输出样例 4、补充4.1、参数说明 1、背景 在开发的过程中&#xff0c;总希望方法执行完了可以看到完整是sql语…

通用人工智能操作系统

随着科技的飞速发展&#xff0c;人工智能已经成为了当今世界最热门的技术领域之一。从智能手机、自动驾驶汽车到智能家居系统&#xff0c;人工智能技术已经渗透到了我们生活的方方面面。然而&#xff0c;尽管人工智能在很多领域取得了显著的成果&#xff0c;但它仍然存在一些局…

matplotlib+tkinter实现一个简单的绘图系统

文章目录 封装成类布局实现绘图功能 绘图系统系列&#xff1a;将matplotlib嵌入到tkinter 封装成类 在理解matplotlib嵌入到tkinter中的原理之后&#xff0c;就已经具备了打造绘图系统的技术基础&#xff0c;接下来要做的&#xff0c;就是做一个较有可读性的绘图类&#xff0…

Java异常体系总结(下篇)

目录 1. 异常处理的三种方法 1.1 JVM 默认处理异常 1.2 通过 try...catch...自己处理异常 1.3 使用 throws和throw 抛出异常 1.3.1 使用 throws 抛出异常 1.3.2 使用 throw 抛出异常 2. try...catch.. 捕获到异常之后代码的执行顺序&#xff1f; 3. try...catch... 相关…