首页 > 其他分享 >每日一题:通过css变量来控制主题

每日一题:通过css变量来控制主题

时间:2023-11-17 15:07:53浏览次数:34  
标签:font 变量 -- 每日 dark color theme document css

1、定义不同主题颜色

:root{
      --theme-color: blue;
      --font-size: 18px;;
    }
    html[theme="dark"]{
        --theme-color: #000;

2、通过切换html自定义属性来控制主题

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
  <div class="theme">

  </div>
<button>改变主题</button>
</body>
<script>
    document.getElementsByTagName('button')[0].addEventListener('click',changeTheme,false);
    function changeTheme(){
        console.log('changeTheme')
        if(document.documentElement.getAttribute('theme') === 'dark'){
            document.documentElement.setAttribute('theme','light');
        }else{
            document.documentElement.setAttribute('theme','dark');
        }
    }
</script>
</html>
<style>
    :root{
      --theme-color: blue;
      --font-size: 18px;;
    }
    html[theme="dark"]{
        --theme-color: #000;
        --font-size: 13px;
    }
    .theme{
        width: 700px;
        height: 700px;
        background: var(--theme-color);
    }
</style>

长风破浪会有时,直挂云帆济沧海



标签:font,变量,--,每日,dark,color,theme,document,css
From: https://blog.51cto.com/u_15961676/8447433

相关文章

  • Spring Boot 访问静态资源css/js
    一、前言我们用SpringBoot搭建Web应用时(如搭建一个博客),经常需要在Html中访问一些静态资源,比如:css样式;js脚本;favicon.ico图标等;而在SpringBoot中如果没有做任何配置,是无法直接访问静态资源的,通常会报404错误二、SpringBoot访问静态资源的默认目录SpringBoot访问......
  • 2023.11.17——每日总结
    学习所花时间(包括上课):9h代码量(行):0行博客量(篇):1篇今天,上午学习,下午学习;我了解到的知识点:1.mybatis2.flash明日计划:学习......
  • 软件设计模式学习每日总结-第五天
    第五天学习原型模式:复制创建新 浅克隆:复制对象.深克隆:复制对象及其成员。 ......
  • 每日总结2023年11月17日
    AccesstoXMLHttpRequestat'http://localhost:8090/user/list'fromorigin'http://localhost:8080'hasbeenblockedbyCORSpolicy:No'Access-Control-Allow-Origin'headerispresentontherequestedresource.这是今天做SpringBoot+......
  • Linux 中 sed命令替换 带有 斜杠的变量
     001、测试(错误做法)(base)[root@pc1test]#lsa.txt(base)[root@pc1test]#cata.txt##测试数据12345678910(base)[root@pc1test]#sed"s/5/$PWD/"a.txt##直接替换报错sed:-eexpression#1,char6:un......
  • 11.16 基本完成个人任务管理系统项目后重新复习JavaScript高级程序设计——声明var与l
    我看的是js高级程序设计第四版,前两章快速了解了一下,第三章开始慢啃,虽然内容枯燥,很多东西自己也知道了,但还是有一些收获的。比如,声明变量的三个关键词:var、let、const;var以前经常用但是会出问题,相比let没有那么严谨(var声明范围函数作用域,而let声明范围块级作用域)。看个例子:这是v......
  • 所见即所得的动画效果:Animate.css
    我们可以在集成Animate.css来改善界面的用户体验,省掉大量手写css动画的时间。官网:Animate.css使用1、安装依赖npminstallanimate.css--save2、引入依赖import'animate.css';3、在项目中使用在class类名上animate__animated是必须的,animate__flipInX为你应用的动画效......
  • 11.16每日总结
    今天准备好明天的测试了,但是由于上周的作业太复杂了,于是又推迟了一周,但是今天上课我们进行了讨论。目前的状况是我们的原型已经搭建起来了要做的就是要把相应流程图和用例图搞明白流程还是不太熟悉,因为中间涉及到很多环节。 ......
  • JS判断变量的具体数据类型封装函数
    封装函数为://返回传入值的数据类型functionGetValueType(val){vartype=typeofval//object需要使用Object.prototype.toString.call判断if(type==='object'){vartypeStr=Object.prototype.toString.call(val)//解析[objectStr......
  • css_使用backdrop-filter实现磨玻璃效果
    <divid="container"><divid="mask"></div></div>#container{width:500px;height:300px;position:relative;border:1pxsolid#ccc;background-image:url('http://thetest.com/vokax3ygw......