css注釋_CSS注釋示例–如何注釋CSS

css注釋

Comments are used in CSS to explain a block of code or to make temporary changes during development. The commented code doesn’t execute.

CSS中使用注釋來解釋代碼塊或在開發過程中進行臨時更改。 注釋的代碼不執行。

Both single and multi-line comments in CSS begin with /* and end with */, and you can add as many comments to your stylesheet as you like. For example:

CSS中的單行和多行注釋都以/*開頭,并以*/結尾,并且您可以根據需要在樣式表中添加任意數量的注釋。 例如:

/* This is a single line comment*/
.group:after {content: "";display: table;clear: both;
}/*This isa multi-linecomment
*/

You can also make your comments more readable by stylizing them:

您還可以通過設置樣式的風格來使注釋更具可讀性:

/*
***
* SECTION FOR H2 STYLE 
***
* A paragraph with information
* that would be useful for someone
* who didn't write the code.
* The asterisks around the paragraph 
* help make it more readable.
***
*/

用注釋組織CSS (Organizing CSS with comments)

In larger projects, CSS files can quickly grow in size and become difficult to maintain. It can be helpful to organize your CSS into distinct sections with a table of contents to make it easier to find certain rules in the future:

在較大的項目中,CSS文件的大小會快速增長,并且變得難以維護。 將您CSS組織成帶有目錄的不同部分可能會有所幫助,以便將來更輕松地查找某些規則:

/* 
*  CSS TABLE OF CONTENTS
*   
*  1.0 - Reset
*  2.0 - Fonts
*  3.0 - Globals
*  4.0 - Color Palette
*  5.0 - Header
*  6.0 - Body
*    6.1 - Sliders
*    6.2 - Imagery
*  7.0 - Footer
*//*** 1.0 - Reset ***//*** 2.0 - Fonts ***//*** 3.0 - Globals ***//*** 4.0 - Color Palette ***//*** 5.0 - Header ***//*** 6.0 - Body ***/
h2 {font-size: 1.2em;font-family: "Ubuntu", serif;text-transform: uppercase;
}/*** 5.1 - Sliders ***//*** 5.2 - Imagery ***//*** 7.0 - Footer ***/

有關CSS的更多信息: CSS語法和選擇器 (A little bit more about CSS: CSS Syntax and Selectors)

When we talk about the syntax of CSS, we’re talking about how things are laid out. There are rules about what goes where, both so you can write CSS consistently and a program (like a browser) can interpret it and apply it to the page correctly.

當我們談論CSS的語法時,我們在談論事物的布局。 關于去哪里有規則,因此都可以一致地編寫CSS,并且程序(如瀏覽器)可以解釋CSS并將其正確地應用于頁面。

There are two main ways to write CSS.

編寫CSS的主要方法有兩種。

內聯CSS (Inline CSS)

Specifics on CSS Specificity: CSS Tricks

有關CSS特殊性的細節: CSS技巧

Inline CSS applies styling to a single element and its children, until another style overriding the first is encountered.

內聯CSS將樣式應用于單個元素及其子元素,直到遇到另一個覆蓋第一個樣式的樣式。

To apply inline CSS, add the “style” attribute to an HTML element that you’d like to modify. Inside quotes, include a semicolon-delimited list of key/value pairs (each in turn separated by a colon) indicating styles to set.

要應用內聯CSS,請將“樣式”屬性添加到您要修改HTML元素中。 在引號內,包括用分號分隔的鍵/值對列表(每個鍵/值對依次由冒號分隔),以指示要設置的樣式。

Here’s an example of inline CSS. The words “One” and “Two” will have a background color of yellow and text color of red. The word “Three” has a new style that overrides the first, and will have a background color of green and text color of cyan. In the example, we’re applying styles to <div> tags, but you can apply a style to any HTML element.

這是內聯CSS的示例。 單詞“一個”和“第二”將具有黃色的背景色和紅色的文本色。 “三”一詞具有新的樣式,該樣式將覆蓋第一個樣式,并且將具有綠色的背景顏色和青色的文本顏色。 在示例中,我們將樣式應用于<div>標記,但是您可以將樣式應用于任何HTML元素。

<div style="color:red; background:yellow">One<div>Two</div><div style="color:cyan; background:green">Three</div>
</div>

內部CSS (Internal CSS)

While writing an inline style is a quick way to change a single element, there’s a more efficient way to apply the same style to many elements of the page at once.

雖然編寫內聯樣式是更改單個元素的快速方法,但是有一種更有效的方法可將同一樣式同時應用于頁面的許多元素。

The internal CSS has its styles specified in the <style> tag, and it is embedded in the <head> tag.

內部CSS在<style>標記中指定了其樣式,并且將其嵌入在<head>標記中。

Here’s an example that has a similar effect as the “inline” example above, except the CSS has been extracted to its own area. The words “One” and “Two” will match the div selector and be red text on a yellow background. The words “Three” and “Four” will match the div selector too, but they also match the .nested_div selector which applies to any HTML element that references that class. This more specific selector overrides the first, and they end up appearing as cyan text on a green background.

這是一個與上述“內聯”示例具有相似效果的示例,只是CSS已被提取到其自己的區域。 單詞“ One”和“ Two”將與div選擇器匹配,并在黃色背景上為紅色文本。 單詞“三”和“四”也將與div選擇器匹配,但是它們也與.nested_div選擇器匹配,該選擇器適用于引用該類的任何HTML元素。 這個更具體的選擇器會覆蓋第一個選擇器,最終它們在綠色背景上顯示為青色文本。

<style type="text/css">div { color: red; background: yellow; }.nested_div { color: cyan; background: green; }
</style><div>One<div>Two</div><div class="nested_div">Three</div><div class="nested_div">Four</div>
</div>

The selectors shown above are extremely simple, but they can get quite complex. For example, it’s possible to apply styles only to nested elements; that is, an element that’s a child of another element.

上面顯示的選擇器非常簡單,但是會變得非常復雜。 例如,可以僅將樣式應用于嵌套元素; 也就是說,一個元素是另一個元素的子元素。

Here’s an example where we’re specifying a style that should only be applied to div elements that are a direct child of other div elements. The result is that “Two” and “Three” will appear as red text on a yellow background, but “One” and “Four” will remain unaffected (and most likely black text on a white background).

這里就是我們指定只應適用于一種風格的例子div是其他的直接子元素div元素。 結果是“兩個”和“三個”將在黃色背景上顯示為紅色文本,但“一個”和“四個”將不受影響(并且很可能在白色背景上顯示為黑色文本)。

<style type="text/css">div > div { color: red; background: yellow; }
</style><div>One<div>Two</div><div>Three</div>
</div>
<div>Four
</div>

外部CSS (External CSS)

All the styling has its own document which is linked in the <head> tag. The extension of the linked file is .css

所有樣式都有自己的文檔,該文檔鏈接在<head>標記中。 鏈接文件的擴展名為.css

翻譯自: https://www.freecodecamp.org/news/comments-in-css/

css注釋

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390578.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390578.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390578.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

r軟件時間序列分析論文_高度比較的時間序列分析-一篇論文評論

r軟件時間序列分析論文數據科學 &#xff0c; 機器學習 (Data Science, Machine Learning) In machine learning with time series, using features extracted from series is more powerful than simply treating a time series in a tabular form, with each date/timestamp …

leetcode 168. Excel表列名稱

題目 給你一個整數 columnNumber &#xff0c;返回它在 Excel 表中相對應的列名稱。 例如&#xff1a; A -> 1 B -> 2 C -> 3 … Z -> 26 AA -> 27 AB -> 28 … 示例 1&#xff1a; 輸入&#xff1a;columnNumber 1 輸出&#xff1a;“A” 示例 2&…

飛機訂票系統

1 #include <stdio.h>2 #include <stdlib.h>3 #include <string.h>4 #include <conio.h>5 typedef struct flightnode{6 char flight_num[10]; //航班號7 char start_time[10]; //起飛時間8 char end_time[10]; //抵達時間9 char st…

解決Mac10.13 Pod報錯 -bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.fram

升級10.13以后Pod命令失效&#xff0c;解決辦法如下&#xff1a; 終端執行 brew link --overwrite cocoapods 復制代碼嘗試 Pod 命令是否已經恢復 若報錯繼續執行 brew reinstall cocoapodsbrew install rubybrew link --overwrite cocoapods 復制代碼嘗試 Pod 命令是否已經恢復…

angular示例_用示例解釋Angular動畫

angular示例為什么要使用動畫&#xff1f; (Why use Animations?) Modern web components frequently use animations. Cascading Style-sheets (CSS) arms developers with the tools to create impressive animations. Property transitions, uniquely named animations, mu…

selenium抓取_使用Selenium的網絡抓取電子商務網站

selenium抓取In this article we will go through a web scraping process of an E-Commerce website. I have designed this particular post to be beginner friendly. So, if you have no prior knowledge about web scraping or Selenium you can still follow along.在本文…

劍指 Offer 37. 序列化二叉樹

題目 序列化是將一個數據結構或者對象轉換為連續的比特位的操作&#xff0c;進而可以將轉換后的數據存儲在一個文件或者內存中&#xff0c;同時也可以通過網絡傳輸到另一個計算機環境&#xff0c;采取相反方式重構得到原數據。 請設計一個算法來實現二叉樹的序列化與反序列化…

ie8 ajaxSubmit 上傳文件提示下載

轉載 解決ie下ajaxsubmit上傳文件提示下載文件問題 主要是應為放回類型為json&#xff0c;返回text/html轉載于:https://www.cnblogs.com/yang-C-J/p/8963278.html

一個簡單的 js 時間對象創建

JS中獲取時間很常見&#xff0c;湊湊熱鬧&#xff0c;也獲取一個時間對象試試 首先&#xff0c;先了解js的獲取時間函數如下&#xff1a; var myDate new Date(); //創建一個時間對象 myDate.getYear(); // 獲取當前年份&#xff08;2位&#x…

裁判打分_內在的裁判偏見

裁判打分News flash: being an umpire is hard. Their job is to judge whether a ball that’s capable of moving upwards of 100 MPH or breaking 25 inches crossed through an imaginary zone before being caught. I don’t think many would argue that they have it ea…

數據庫sql課程設計_SQL和數據庫-初學者完整課程

數據庫sql課程設計In this course, Mike Dane will teach you database management basics and SQL.在本課程中&#xff0c;Mike Dane將教您數據庫管理基礎知識和SQL。 The course starts off with Mike helping you install MySQL on Windows or Mac. Then he explores topic…

LCP 07. 傳遞信息

小朋友 A 在和 ta 的小伙伴們玩傳信息游戲&#xff0c;游戲規則如下&#xff1a; 有 n 名玩家&#xff0c;所有玩家編號分別為 0 &#xff5e; n-1&#xff0c;其中小朋友 A 的編號為 0 每個玩家都有固定的若干個可傳信息的其他玩家&#xff08;也可能沒有&#xff09;。傳信息…

微信公眾號自動回復加超鏈接最新可用實現方案

你在管理微信號時是否會有自動回復或者在關鍵字觸發自動回復加一個超鏈接的需求呢&#xff1f;例如下圖像王者榮耀這樣&#xff1a; 很多有開發經驗的朋友都知道微信管理平臺會類似富文本編輯器&#xff0c;第一想到的解決方案會是在編輯框中加<a href網址 >顯示文字<…

devops開發模式流程圖_2020 Web開發人員路線圖–成為前端,后端或DevOps開發人員的視覺指南

devops開發模式流程圖There are many ways you can go about picking up the skills you need to become a developer.您可以采用多種方法掌握成為開發人員所需的技能。 There are linear curriculums that teach you a bit of everything - like freeCodeCamps full stack de…

從Jupyter Notebook切換到腳本的5個理由

意見 (Opinion) 動機 (Motivation) Like most people, the first tool I used when started learning data science is Jupyter Notebook. Most of the online data science courses use Jupyter Notebook as a medium to teach. This makes sense because it is easier for be…

leetcode 1833. 雪糕的最大數量

夏日炎炎&#xff0c;小男孩 Tony 想買一些雪糕消消暑。 商店中新到 n 支雪糕&#xff0c;用長度為 n 的數組 costs 表示雪糕的定價&#xff0c;其中 costs[i] 表示第 i 支雪糕的現金價格。Tony 一共有 coins 現金可以用于消費&#xff0c;他想要買盡可能多的雪糕。 給你價格…

MVC架構 -- 初學試水選課管理系統

項目文件網站地址&#xff1a;http://www.gegecool.cn:90/ 第一次對MVC 進行轉載于:https://www.cnblogs.com/wtusoso/p/8032120.html

rest api 示例2_REST API教程– REST Client,REST Service和API調用通過代碼示例進行了解釋

rest api 示例2Ever wondered how login/signup on a website works on the back-end? Or how when you search for "cute kitties" on YouTube, you get a bunch of results and are able to stream off of a remote machine?有沒有想過網站上的登錄/注冊在后端如…

win10子系統linux編譯ffmpeg

android-ndk-r14b(linux版) ffmpeg-4.0 開啟win10子系統&#xff08;控制面板-》程序和功能-》啟用或關閉Windows功能 然后在 適用與 Linux 的 Windows 子系統前面打勾&#xff09; 然后點擊確定&#xff0c;等待安裝&#xff0c;電腦會重啟 然后在win10應用商店 搜索ubuntu安裝…

ip登錄打印機怎么打印_不要打印,登錄。

ip登錄打印機怎么打印Often on Python, especially as a beginner, you might print( ) a variable in order to see what is happening in your program. It is possible if you rely on too many print statements throughout your program you will face the nightmare of h…