首页 > Web开发 > 详细

Css 变量

时间:2017-06-21 15:44:16      阅读:274      评论:0      收藏:0      [点我收藏+]

之前从来没有这样用过,感觉也是很惊奇啊,像less“变量”一样;

.Variables{
  --color:red;
  background: var(--color);
  width: 100px;
  height: 50px;
}
<div class=‘Variables‘></div>

 

.button-gradient {
  background: linear-gradient(var(--gradientAngle), var(--gradientStart),var(--gradientStop));

  --gradientAngle: 60deg;
  --gradientStart: lightpink;
  --gradientStop: lightyellow;
  height: 50px;
  width: 200px;
  line-height: 50px;
  font-weight: 700;
  font-size: 20px;
  text-align: center;
}

.button-gradient:hover {
  --gradientAngle: 0deg;
}

<div class=‘button-gradient‘>Gradient Button</div>

 

 

// Variables
:root {
  --primaryColor: lightgreen;
  --buttonBgColor: var(--primaryColor);
}

.button {
  background: var(--buttonBgColor);
}

.button--blue {
  --buttonBgColor: lightblue;
}
.btn{
  height: 50px;
  width:100px;
  margin: 10px;
}

<div class=‘button btn‘></div>
<div class=‘button--blue btn‘></div>

如果我想更新加载器栏的宽度来表示加载时间的百分比,我可以这样做:

function calculateLoadProgress() { let loadProgress = 0; // codes to update loadProgress here return loadProgress; } // Set width of progress bar document.documentElement.style.setProperty(‘--progressBarWidth‘, calculateLoadProgress());

Css 变量

原文:http://www.cnblogs.com/peiyao/p/7059868.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!