如何计算LESS CSS中的百分比? [英] How to calculate percentages in LESS CSS?

查看:417
本文介绍了如何计算LESS CSS中的百分比?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以百分比计算子容器(div等)的宽度,具体取决于具有 LESS CSS 的父容器。

I would like to calculate the width of child-container (div etc) in percentages depending on the parent container with LESS CSS.

我使用的是Ethan Marcotte的论坛: target / context = result

I am using the forumula by Ethan Marcotte: target / context = result.

container:620px

子容器:140像素

Parent container: 620px
Child container: 140px

我使用此计算:

div.child-container {
    width: (140/620)*100%;
}

但是输出是:

div.child-container {
    width: 0.2258064516129;
}

我想移动小数点两位数并添加%这:

I would like to move the decimal point two digits and add the %, like this:

div.child-container {
    width: 22.58064516129%;
}

任何提示都非常感激。

推荐答案

阅读 LESS CSS网站后,您需要更改您的方程

After reading the LESS CSS website, you need to change the order of your equation


输出几乎是您期望的 - LESS可以理解颜色和单位之间的差异。如果在操作中使用单位,如:

The output is pretty much what you expect—LESS understands the difference between colors and units. If a unit is used in an operation, like in:

@var: 1px + 5;

LESS将使用该单位进行最终输出 - 6px 在这种情况下。

LESS will use that unit for the final output—6px in this case.

应该是:

width: 100%*(140/620);

这篇关于如何计算LESS CSS中的百分比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆