你怎么评论css?(How should you comment CSS? [closed])

编程入门 行业动态 更新时间:2024-10-26 18:23:26
你怎么评论css?(How should you comment CSS? [closed])

在开发过程中,除了偶尔的标题之外,我与之交互的大部分CSS都没有注释。 结果,我养成了不评论我的CSS的习惯。

但是,我经常发现在我正在使用的css中发表评论会很有用。 你应该评论css除了表示作者的标题吗? 如果是这样,怎么样?

编辑:我不是在询问如何评论的过程,而是最佳实践。

While developing, most of the CSS I interact with does not have comments, besides the occasional header. As a result, I have gotten in the habit of not commenting my CSS.

However, I often find it would be useful to have comments in CSS that I am working with. Should you comment CSS besides a header indicating an author? If so, how?

I am not asking the process of how to comment, but rather the best practice.

最满意答案

我认为通常有两种情况应该使用评论:

如果你正在使用黑客攻击。 为了说明页面结构。

这可能是不可能的,但你首先应该问: 如何构建CSS?

通过适当的结构,注释可以轻松导航和定位页面中的部分,例如

/*************** * UI Elements * ***************/ h1, h2, h3, p { ... } table, form, input, textarea { ... } /* Custom Radio button hack: use background-image/position on label */ input[type=radio] { display:none; } input[type=radio] + label { background-image: url(...); } input[type=radio]:checked + label { background-image: url(...); } /********** * Header * **********/ #site-header { ... } #logo { ... } /*********** * Sidebar * ***********/ #sidebar { ... } .article-in-sidebar { ... } /********** * Footer * **********/ #site-footer { ... }

任何触摸CSS的人都应该相信,在标题部分中编辑内容不会影响页面上的任何其他内容。 如果所有页面和部分都需要对元素样式进行根本性更改,那么您需要做的就是编辑UI元素中的相关元素。

当然,这仍然取决于您的标记是否写得好并且与演示文稿完全分开。 如果您的HTML受到div-itis的影响,那么没有任何评论可以帮助您保存CSS。

I think there are generally two cases where comments should be used:

If you are using hacks. To illustrate the page structure.

This may be beyond the question, but you should first ask: how to structure CSS?

With a proper structure, comments make it a breeze to navigate and locate the sections in your page, e.g.

/*************** * UI Elements * ***************/ h1, h2, h3, p { ... } table, form, input, textarea { ... } /* Custom Radio button hack: use background-image/position on label */ input[type=radio] { display:none; } input[type=radio] + label { background-image: url(...); } input[type=radio]:checked + label { background-image: url(...); } /********** * Header * **********/ #site-header { ... } #logo { ... } /*********** * Sidebar * ***********/ #site-sidebar { ... } .item-in-sidebar { ... } /********** * Footer * **********/ #site-footer { ... }

Anyone touching the CSS should have the confidence that editing something in, say, the header section won't affect anything else on the page. If a fundamental change in an element's style is required across all pages and sections, all you need to do is edit the relevant element in the UI Elements portion of CSS.

Needless to say, good CSS structure depends on your markup being well-written and cleanly separated from presentation. If your HTML is afflicted with div-itis, no amount of comments can help save your CSS.

更多推荐

本文发布于:2023-08-02 19:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1379698.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:你怎么   css   comment   CSS   closed

发布评论

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

>www.elefans.com

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