- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在 CSS 中编码时,为元素的宽度和高度使用较短的属性会不会更快?
截至目前,我必须输入:
selector {width: 100px; height: 250px;}
虽然速度很快,但我认为这会更快:
selector {dimension: 100px 250px;}
是否已经有可以实现此目的的 CSS 预处理器?似乎在处理大量宽度和高度时会节省一些时间。
一个很好的例子就是 CSS Grid属性:
grid-template-columns: 100px 100px;
grid-template-rows: 100px 100px;
相当于:
grid-template: 100px 100px / 100px 100px;
最佳答案
简短回答:CSSWG 尚未就速记属性的名称达成一致。
这个想法并不新鲜,很多人多年来不时地提出过这个想法。但是,目前有一个提案 [css-sizing] Adding a 'size' shorthand for 'width'/'height'来自 CSSWG (CSS 工作组)。
很多事情已经讨论过了,但还有一些没有解决。以下是一些示例:
什么是专有名称?
建议的一些名称:
size
:与@page
的size
属性尺寸
:可能太长或难以拼写box-size
:可能太接近box-sizing
它将如何运作?
应该是:
<box-size>: <width> <height>?
...或更接近于其他属性,如 padding
或 margin
:
<box-size>: <height> <width>?
另外:它是否应该支持一个额外的参数来保持纵横比?
谁会支持它?
如您所见,正如 CSSWG 最近在其 Minutes Telecon on 2017-08-16 中所说, future 可能会出现速记符号。 :
The group agreed that a shorthand for ‘width’/’height’ would be good, but shouldn’t be called ‘size’. However, there wasn’t time to come up with a different name.
话虽如此,您当然可以使用 CSS 预处理器,让您的生活更轻松。例如,我在 LESS 中有一个 mixin,看起来像这样:
.size(@a: null, @b: null) {
& when not (null = @a) {
width: @a;
}
& when (null = @b) {
height: @a;
}
& when not (null = @b) {
height: @b;
}
}
就这么简单:
.size(100%, 50%);
width: 100%;
height: 50%;
…它也支持方形元素:
.size(100%);
width: 100%;
height: 100%;
关于css - 为什么 CSS 中没有宽度和高度的简写属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47251011/
考虑以下示例: if (cache) { x = cache; } else { x = cache = someMethod(); } 无论如何要使它比 cache 更短? x =
我有一个字符串,我想将它附加到其他字符串。比方说: $my_string = 'Hello'; $my_string .= ' there'; 这将返回“你好”。 我想像这样设置条件: $my_str
有没有办法执行以下操作,但简而言之 if/then 语法: if($method->isAbstract()) { $details['abstract'] = true; } 如果我这样做:
我很好奇,有没有更简单的说法 if(myVar == myVal || myVar == myOtherVal){ /*...*/ } 如: if(myVar == myVal || myOtherV
我正在寻找一种方法来最小化数组的创建,其中所有索引都具有相同的值。这可能不可能,但我会发现它非常方便。 考虑: var layer = []; layer['game'] = new Kinetic.
我想知道是否有办法将简写 if/else 与简写 += 合并 类似这样的事情: var value; $.each(data.events, function(index, element) {
我需要用 JQuery 做一个速记 IF-ELSE。我的代码: $('#somediv').val() != 0 ? $('#somediv').toggleClass('class1') :
我觉得这一定是重复的,但我找不到任何东西,可能是由于措辞不同,或者只是因为确实没有更好的东西。 我正在生成大量的 JS 代码,其中“OR”对象属性与变量,而标识符不一定匹配。看起来像这样(值为 boo
这个问题在这里已经有了答案: Shorthand if/else statement Javascript (7 个答案) 关闭 9 年前。 下面的简写等价物是什么? if (windowwidth
以下的 JS 简写是什么: if (typeof bfMax !== 'undefined') { options.max = bfMax; } 最佳答案 有条件地赋值
假设我有父类 - “Parent”,我想从中创建三个对象 - o1、o2、o3。 因此,如果有一个简略的方法或一种漂亮的方法来执行以下操作: o1=Parent() o2=Parent() o3=Pa
这个问题已经有答案了: Check variable equality against a list of values (16 个回答) 已关闭 5 年前。 我觉得我经常遇到这种情况,直觉上应该有一
我是 Swift 的新手,我想知道是否有一种“速记”形式,可以在不执行 if nil 检查的情况下将可选值分配给非可选值。 例如,如果我有一个可选的闭包: var onTap: (() -> Void
这个问题在这里已经有了答案: Why does the expression 0 < 0 == 0 return False in Python? (9 个回答) 关闭 4 年前。 if x ==
这个问题在这里已经有了答案: CSS select multiple descendants of another element (3 个答案) 关闭 5 年前。
假设我正在使用一些 python 包中的类,如下所示 class foo(object): def __init__(self): self.a = None
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 8 年前。 Improve t
top right bottom left 或 width 有任何简写和高度 ? 我有很多这样的CSS #topDiv { position:absolute; top:0px;
这个问题在这里已经有了答案: 关闭9年前。 Possible Duplicate: Ternary conditional operator in Python 我想在 python 中做以下事情:
if-else 的 JavaScript 简写可以从函数中返回吗?如果是这样,这将如何运作。 例如。我有这个: if(boolean){ return; } 我想这样写: (value)? retu
我是一名优秀的程序员,十分优秀!