热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用SCSS/SASS计算百分比-CalculateapercentwithSCSS/SASS

Iwanttosetawidthinpercentageinscssviacalculation,butitgivesmeerrors..我想通过计算在scss中设置

I want to set a width in percentage in scss via calculation, but it gives me errors..

我想通过计算在scss中设置一个百分比的宽度,但是它给了我错误。

Invalid CSS after "...-width: (4/12)%": expected expression (e.g. 1px, bold), was ";"

无效的CSS后”……-width: (4/12)%": expected expression(例如,1px,粗体),is ";"

I want to do something like

我想做一些类似的事情

$my_width: (4/12)%;

div{
width: $my_width;
}

how do I add the % sign in there?

如何添加%符号?

Same question with px and em

px和em也有同样的问题

2 个解决方案

#1


168  

Have you tried the percentage function ?

你试过百分比函数吗?

$my_width: percentage(4/12);
div{
width: $my_width;
}

#2


22  

Another way:

另一种方法:

$my_width: 4/12*100%;

div{
width: $my_width; // 33.33333%
}

Sass will output the value in %.

Sass将输出%的值。


推荐阅读
author-avatar
mou377
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有