可以在Less中使用正则表达式吗?(Possible to use regular expressions in Less?)

编程入门 行业动态 更新时间:2024-10-28 14:33:02
可以在Less中使用正则表达式吗?(Possible to use regular expressions in Less?)

可以少用正则表达式吗? 如果没有,我可以通过另一种方式实现以下目标吗?

我想给每个Bootstrap行和列添加一个虚线边框。 鉴于有这么多col-md-12 , col-md-11 ,....我不想输出所有这些,所以我只想说:

.my-canvas { .row, .col-.*-.* { outline: 2px dashed #000; } }

Is it possible to use regular expressions in less? If not is there another way I can achieve the following?

I want to give every Bootstrap row and column a dotted border. Given that theres so many col-md-12, col-md-11, .... I dont want to type out all of them so I just want to say:

.my-canvas { .row, .col-.*-.* { outline: 2px dashed #000; } }

最满意答案

对于这个,您不需要使用Less和正则表达式。 通过使用如下例中的属性选择器,可以使用纯CSS本身。

[class^='col-'],
[class*=' col-'] {
  outline: 2px dotted red;
}
div {
  margin: 10px;
} 
  
<div class='col-md-11'>Something</div>
<div class='col-md-12'>Something</div>
<div class='col-md-21'>Something</div>
<div class='column-md-11'>Something</div>
<div class='some-class col-md-99'>Something</div> 
  
 

You don't need to use Less with regular expressions for this one. It is possible to do with pure CSS itself by using attribute selectors like in the below example.

[class^='col-'],
[class*=' col-'] {
  outline: 2px dotted red;
}
div {
  margin: 10px;
} 
  
<div class='col-md-11'>Something</div>
<div class='col-md-12'>Something</div>
<div class='col-md-21'>Something</div>
<div class='column-md-11'>Something</div>
<div class='some-class col-md-99'>Something</div> 
  
 

更多推荐

本文发布于:2023-04-27 20:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1329018.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正则表达式   regular   expressions

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!