css - 为什么在 Vue 组件的样式中添加 lang=less 会改变现有行为?
问题描述
我有一个 Vue 组件,并想确定它的 CSS 范围。在发现正确的方法(通过scoped
属性)之前,我有一个计划用来less
封装我的 CSS 条目。
我有一个按预期工作的初始部分:
<style>
#weather {
display: grid;
grid-template-columns: repeat(8, 1fr);
grid-template-rows: auto auto auto;
text-align: center;
grid-column-gap: 5px;
}
.hour {
font-family: 'Open Sans', sans-serif;
font-size: 20px;
font-weight: bold;
justify-self: start;
padding: 0 5px 0 5px;
color: white !important;
}
.date {
font-family: 'Open Sans', sans-serif;
font-size: 30px;
}
.today {
grid-column: 1 / 5;
font-weight: bold;
}
.tomorrow {
grid-column: 5 / 9;
}
</style>
在将第一行更改为之后<style lang=less>
,我预计还没有任何更改。我认为 less 与 CSS 向后兼容,如果我不使用任何特定于 的东西less
,我会以相同的 CSS 结束。
事实并非如此,我的页面被打扰了。DevTools 显示
这表明不再display
是grid
,因此grid-column
没有意义。
lang=less
添加到有什么变化<style>
?具体来说:为什么在 CSS 代码还没有改变的情况下对 CSS 进行不同的处理?
解决方案
您应该使用e
function for grid-column
value 来防止 less 编译1 / 5
为0.2
.
.today {
grid-column: e("1 / 5");
font-weight: bold;
}
.tomorrow {
grid-column: e("5 / 9");
}
或者你可以简单地这样做:
.today {
grid-column: ~"1 / 5";
font-weight: bold;
}
.tomorrow {
grid-column: ~"5 / 9";
}
有关更多信息,您可以在 less 中查看转义主题。
推荐阅读
- python - 如何使用条件选择数据框中的前 N 列
- sql - Redshift SQL 结果集 100s 行宽效率(从长到宽)
- python - TypeError:falling_distance(我的方法)缺少1个必需的位置参数:'seconds'
- python - 如何在不导入的情况下实例化属于另一个类的对象
- swift - Swift UI - 如何检查文本字段是否输入了特定文本,以便我可以返回“那是正确答案”或“那是错误答案”
- javascript - 在什么情况下更改 javascript 数组的长度而不实际添加新元素会很有用
- html - CSS 仅在样式属性中本地有效,而在外部样式表中无效
- c - C中的“\r”在它之前停止输出
- javascript - 我应该担心这里的比赛条件吗?
- node.js - 安装 ETHERS.JS