简体   繁体   English

创建标签时如何更改属性顺序?

[英]How to change the sequence of attributes when creating a tag?

When creating a tag, I need the attribute class to always be the first.创建标签时,我需要属性类始终是第一个。 If i create a tag like: a.link the result is this <a href="" class="link"></a> or img.header__img <img src="" alt="" class="header__img"> , how i can change sequence?如果我创建一个标签,如: a.link 结果是<a href="" class="link"></a>或 img.header__img <img src="" alt="" class="header__img"> ,我怎么能改变顺序? Thanks.谢谢。

Update , vscode is adding the ability to reverse attributes through an emmet setting, see https://github.com/microsoft/vscode/issues/110251 (Implement output.reverseAttributes for emmet snippets).更新,vscode 正在添加通过 emmet 设置反转属性的功能,请参阅https://github.com/microsoft/vscode/issues/110251 (实现 emmet 片段的 output.reverseAttributes)。

It is in the Insiders' Build v1.54.它位于 Insiders' Build v1.54 中。 In your settings.json :在您的settings.json

  "emmet.preferences": {
    "output.reverseAttributes": true
  }

Tested in Insider's Build and it is working as you wanted.在 Insider's Build 中进行了测试,它可以按您的意愿工作。 Notes that in the img.header_img case the result is请注意,在img.header_img情况下,结果是

<img class="header__img" src="" alt="">

so the class is first.所以class是第一位的。 I'm not sure that is technically reversed as the src is now the second attribute not the third.我不确定这在技术上颠倒的,因为src现在是第二个属性而不是第三个。 But I think you just wanted the class first and the it is fine if the src is second or third.但我认为你只想要第一个class ,如果src是第二个或第三个就可以了。


Previous answer:上一个答案:

I have a partial answer, maybe someone has something better.我有一个部分的答案,也许有人有更好的东西。 See custom emmet snippets in vscode .请参阅vscode 中的自定义 emmet 片段

Create a snippets.json file.创建一个snippets.json 文件。

Use this setting to point to your snippets.json directory (not the file itself):使用此设置指向您的 snippets.json 目录(不是文件本身):

"emmet.extensionsPath": "C:\\Users\\Mark\\OneDrive\\Test Bed\\.vscode",

In a snippets.json file put something like this:在snippets.json 文件中放置如下内容:

{
  "html": {
      "snippets": {
          "iq": "<img src='${1}' alt='${2}' class='${3}'>",
          "aq": "<a class='${1}' href='${2}'></a>"
      }
  },
  "css": {
      "snippets": {
          "cb": "color: blue",
          "bsd": "border: 1px solid ${1:red}",
          "ls": "list-style: ${1}"
      }
  }
}

You see that iq and aq will now trigger img and a tags with the attribute order you wish.您会看到iqaq现在将触发具有您希望的属性顺序的imga标签。

However, you cannot simply do a aq.someClass and have it populate the class attribute.但是,您不能简单地执行aq.someClass并让它填充 class 属性。 It doesn't work.它不起作用。 Perhaps someone knows how to make that work or to simply override the built-in emmet snippets.也许有人知道如何进行这项工作或简单地覆盖内置的 emmet 片段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM