初學者css常見問題_5分鐘內學習CSS-初學者教程

初學者css常見問題

關于網絡設計語言的快速教程。 (A quick tutorial on the design language of the web.)

CSS (Cascading Style Sheets) is what makes web pages look good and presentable. It’s an essential part of modern web development and a must-have skill for any web designer and developer.

CSS(級聯樣式表)是使網頁看起來不錯且易于呈現的要素。 它是現代Web開發的重要組成部分,并且是任何Web設計人員和開發人員必須具備的技能。

In this article, I’ll give you a quick introduction to help you get started with CSS.

在本文中,我將為您提供快速入門,以幫助您開始使用CSS。

We’ve also launched a free full-length CSS course on Scrimba. Click here to check it out.

我們還在Scrimba上推出了免費的全長CSS課程。 點擊這里查看。

I’m assuming that you have a basic understanding of HTML, but other than that there are no prerequisites for this tutorial.

我假設您對HTML有基本的了解,但除此之外,本教程沒有任何先決條件。

入門 (Getting Started)

Let’s start with learning how we can include CSS in our projects. There are typically three ways we do that.

讓我們開始學習如何在項目中包含CSS。 我們通常采用三種方式。

1.內聯CSS (1. Inline CSS)

First off, we can include CSS directly in our HTML elements. For this, we make use of the style attribute and then we provide properties to it.

首先,我們可以將CSS直接包含在HTML元素中。 為此,我們使用style屬性,然后為其提供屬性。

<h1 style="color: blue"> Hello world! </h1>

Here we’re giving it the property of color, and setting the value to blue, which results in the following:

在這里,我們賦予它color的屬性,并將其值設置為blue ,結果如下:

We can also set multiple properties inside the style tag if we wanted. However, I don’t want to continue down this path, as things start to get messy if our HTML is cluttered with lots of CSS inside it.

如果需要,我們還可以在style標簽內設置多個屬性。 但是,我不想繼續走這條路,因為如果我們HTML里面雜亂了很多CSS,事情就會變得一團糟。

This is why the second method to include CSS was introduced.

這就是為什么引入第二種包含CSS的方法的原因。

2.內部CSS (2. Internal CSS)

The other way to include CSS is using the style element in the head section of the HTML document. This is called internal styling.

包含CSS的另一種方法是使用HTML文檔headstyle元素。 這稱為內部樣式。

<head>  <style>  h1 {  color: blue;  }  </style>  
</head>

In the style element, we can give the styling to our HTML elements by selecting the element(s) and provide styling attributes. Just like we applied thecolorproperty to the h1 element above.

在style元素中,我們可以通過選擇元素來為HTML元素賦予樣式,并提供樣式屬性。 就像我們將color屬性應用于上面的h1元素一樣。

3.外部CSS (3. External CSS)

The third and most recommended way to include CSS is using an external stylesheet. We create a stylesheet with a .css extension and include its link in the HTML document, like this:

包含CSS的第三種也是最推薦的方法是使用外部樣式表。 我們創建一個擴展名為.css的樣式表,并將其鏈接包含在HTML文檔中,如下所示:

<head>  <link rel="stylesheet" href="style.css">  
</head>

In the code above, we have included the link of style.css file using the link element. We then write all of our CSS in a separate stylesheet called style.css so that it’s easily manageable.

在上面的代碼中,我們使用link元素包括了style.css文件的link 。 然后,我們將所有CSS編寫在一個名為style.css的單獨樣式表中,以便易于管理。

h1 {  color: blue;  
}

This stylesheet can also be imported into other HTML files, so this is great for reusability.

該樣式表也可以導入到其他HTML文件中,因此非常適合重用。

CSS選擇器 (CSS Selectors)

As we discussed earlier, CSS is a design language which is used to style HTML elements. And in order to style elements, you first have to select them. You’ve already seen a glimpse of how this works, but let’s dive a bit deeper into CSS selectors, and look at three different ways you can select HTML elements.

如前所述,CSS是一種用于對HTML元素進行樣式設置的設計語言。 并且為了樣式化元素,您首先必須選擇它們。 您已經看到了它的工作原理,但是讓我們更深入地研究CSS選擇器,并探討選擇HTML元素的三種不同方式。

1.元素 (1. Element)

The first way to select an HTML element is by simply using the name, which is what we did above. Let’s see how it works:

選擇HTML元素的第一種方法是簡單地使用名稱,這就是我們上面所做的。 讓我們看看它是如何工作的:

h1 {  font-size: 20px;  
}  
p {  color: green;  
}  
div {  margin: 10px;  
}

The example above is almost self-explanatory. We are selecting different elements like h1, p, div and giving them different style attributes. The font-size controls the size of the text, color sets the text color, and margin adds spacing around the element.

上面的示例幾乎是不言自明的。 我們正在選擇h1pdiv類的不同元素,并為其賦予不同的樣式屬性。 font-size控制文本的大小, color設置文本的顏色, margin增加元素周圍的間距。

2.班級 (2. Class)

Another way of selecting HTML elements is by using the class attribute. In HTML, we can assign different classes to our elements. Each element can have multiple classes, and each class can also be applied to multiple elements as well.

選擇HTML元素的另一種方法是使用class屬性。 在HTML中,我們可以為元素分配不同的類。 每個元素可以具有多個類,并且每個類也可以應用于多個元素。

Let’s see it in action:

讓我們來看看它的作用:

<div class='container'>  <h1> This is heading </h1>  
</div>
.container {  margin: 10px;  
}

In the code above, we have assigned the class of container to the div element. In the stylesheet, we select our class using .className format and giving it a 10px margin.

在上面的代碼中,我們已將container類分配給div元素。 在樣式表中,我們使用.className格式選擇類,并為其設置10px邊距。

3. ID (3. ID)

Like classes, we can also use IDs to select HTML elements and apply styling to them. The only difference between class and ID is that one ID can be assigned to only one HTML element.

像類一樣,我們也可以使用ID來選擇HTML元素并將樣式應用于它們。 類和ID之間的唯一區別是,一個ID只能分配給一個HTML元素。

<div>  <p id='para1'> This is a paragraph </p>  
</div>
#para1 {  color: green;  font-size: 16px;  
}

The example above displays how we assign an ID to the paragraph element and later use the ID selector in the stylesheet to select the paragraph and apply the style to it.

上面的示例顯示了我們如何為段落元素分配ID,然后如何在樣式表中使用ID選擇器來選擇段落并將樣式應用于該段落。

字體和顏色 (Fonts & Colors)

CSS provides us with literally hundreds of options for playing around with fonts and colors and making our HTML elements look pretty. We can choose from two types of font family names:

CSS實際上為我們提供了數百種選擇,可以選擇使用字體和顏色并使HTML元素看起來更漂亮。 我們可以從兩種字體家族名稱中進行選擇:

1. Generic Family: a group of font families with a similar look (like ‘Serif’ or ‘Monospace’)

1.通用族:外觀相似的一組字體族(例如“ Serif”或“ Monospace”)

2. Font Family: a specific font family (like ‘Times New Roman’ or ‘Arial’)

2.字體家族:特定的字體家族(例如“ Times New Roman”或“ Arial”)

For colors, we can use predefined color names, or RGB, HEX, HSL, RGBA, HSLA values.

對于顏色,我們可以使用預定義的顏色名稱或RGB,HEX,HSL,RGBA,HSLA值。

<div class='container'>  <h1 class='heading1'>  CSS is Coooooool!!!!  </h1>  
</div>
.container {  width: 500px;  height: 100px;  background-color: lightcyan;  text-align: center;  
}.heading1 {  font-family: 'Courier New';  color: tomato;  
}

As you can see in the above example, we have a div element with the class of container. Inside this div, there is an h1 tag with some text inside it.

如您在上面的示例中看到的,我們有一個div元素,其類為container 。 在此div內,有一個帶有一些文本的h1標簽。

In the stylesheet, we select the container class and set its width, height, background-color, and text-align.

在樣式表中,我們選擇容器類并設置其widthheightbackground-colortext-align

Finally, we select the .heading1 class?—?which is applied to the h1 tag?—?and give it the attributes of font-family and color.

最后,我們選擇.heading1類(將其應用于h1標簽),并為其賦予font-familycolor屬性。

結論 (Conclusion)

You might feel a bit overwhelmed by all this information, but don’t worry.

您可能會對所有這些信息感到不知所措,但是不用擔心。

Just check out our free Intro to CSS course on Scrimba and you’ll be a web design ninja in less than an hour.

只要查看我們在Scrimba上免費CSS入門課程 ,您就可以在不到一個小時的時間內成為一名網頁設計忍者。



Thanks for reading! My name is Per Borgen, I'm the co-founder of Scrimba – the easiest way to learn to code. You should check out our responsive web design bootcamp if want to learn to build modern website on a professional level.

謝謝閱讀! 我叫Per Borgen,我是Scrimba的共同創始人–學習編碼的最簡單方法。 如果要學習以專業水平構建現代網站,則應查看我們的響應式Web設計新手訓練營 。

翻譯自: https://www.freecodecamp.org/news/get-started-with-css-in-5-minutes-e0804813fc3e/

初學者css常見問題

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

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

相關文章

leetcode39. 組合總和(回溯)

給定一個無重復元素的數組 candidates 和一個目標數 target &#xff0c;找出 candidates 中所有可以使數字和為 target 的組合。 candidates 中的數字可以無限制重復被選取。 說明&#xff1a; 所有數字&#xff08;包括 target&#xff09;都是正整數。 解集不能包含重復的…

一臉懵逼學習基于CentOs的Hadoop集群安裝與配置(三臺機器跑集群)

1&#xff1a;Hadoop分布式計算平臺是由Apache軟件基金會開發的一個開源分布式計算平臺。以Hadoop分布式文件系統&#xff08;HDFS&#xff09;和MapReduce&#xff08;Google MapReduce的開源實現&#xff09;為核心的Hadoop為用戶提供了系統底層細節透明的分布式基礎架構。 注…

linux批量去掉文件名前綴,linux 批量刪除某個前綴文件

1. 命令 (參考&#xff1a;https://blog.csdn.net/kl28978113/article/details/80271831)find ./ -name updatesites*-* -exec rm {} \;2. 舉例[rootadmin batch-create-sites]# ls2020-02-13-10-10.out logs-2020-04-07-08-00.out updatesites-2020-02-12-01-49-25.xlsx updat…

Docker - 避免啟動container后運行shell腳本執行完成后docker退出container

問題 最近在使用 Dockerfile 啟動容器&#xff0c;發現使用Dockerfile調用容器里面的shell&#xff0c;當shell執行完成以后&#xff0c;docker會退出容器。 分析 Docker 在執行shell的時候&#xff0c;是在后臺執行的&#xff1b;因此&#xff0c;在shell執行完成以后&#xf…

css畫橫線箭頭_用CSS繪制三角形箭頭

用CSS繪制三角形箭頭。使用純CSS&#xff0c;你只需要很少的代碼就可以創作出各種瀏覽器都兼容的三角形箭頭&#xff01;CSS代碼:/* create an arrow that points up */div.arrow-up {width: 0;height: 0;border-left: 5px solid transparent; /* left arrow slant */border-ri…

Jmeter參數化的理解

jmeter參數化有兩種情況&#xff1a; jmeter執行的sql語句中值的參數化&#xff08;如select過濾條件&#xff09;csv data set config參數表示方式${zjhm}jmx腳本的設置屬性參數化&#xff0c;方便命令行調用時修改參數&#xff08;如并發量、執行時間&#xff09;在腳本中調用…

leetcode216. 組合總和 III(回溯)

找出所有相加之和為 n 的 k 個數的組合。組合中只允許含有 1 - 9 的正整數&#xff0c;并且每種組合中不存在重復的數字。 說明&#xff1a; 所有數字都是正整數。 解集不能包含重復的組合。 示例 1: 輸入: k 3, n 7 輸出: [[1,2,4]] 代碼 class Solution {List<List…

linux內核epub,Android底層開發技術實戰詳解——內核、移植和驅動(第2版)[EPUB][MOBI][AZW3][42.33MB]...

內容簡介本書從底層原理開始講起&#xff0c;結合真實的案例向讀者詳細介紹了Android內核、移植和驅動開發的整個流程。全書分為21章&#xff0c;依次講解驅動移植的必要性&#xff0c; Goldfish、OMAP內核和驅動解析&#xff0c;顯示系統、輸入系統、振動器系統、音頻系統、視…

機器學習崗位太少_太多的東西要學習,很少的時間

機器學習崗位太少by Rick West由里克韋斯特(Rick West) 太多的東西要學習&#xff0c;很少的時間 (So much to learn, so little time) 我學習&#xff0c;保持動力并實現目標的主要技巧 (My top tips for learning, staying motivated, and achieving your goals) One of the…

用9種辦法解決 JS 閉包經典面試題之 for 循環取 i

2017-01-06Tomson JavaScript轉自 https://segmentfault.com/a/1190000003818163 閉包 1.正確的說,應該是指一個閉包域,每當聲明了一個函數,它就產生了一個閉包域(可以解釋為每個函數都有自己的函數棧),每個閉包域(Function 對象)都有一個 function scope(不是屬性),function s…

bzoj 2296: 【POJ Challenge】隨機種子

Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeDescription1tthinking除了隨機算法&#xff0c;其他什么都不會。但是他還是可以ac很多題目&#xff0c;他用的是什么呢&#xff1f;他會選擇一個好的隨機種子&#xff0c;然后輸出答案。往往他選擇的一個好的種子可…

英特爾第十代處理器為什么不支持win7_5GHz動力澎湃 高主頻多核處理器成就巔峰玩家...

頻率之爭永遠是處理器領域無法回避的話題。高主頻在游戲中所帶來的高速運行&#xff0c;穩定幀數等特性永遠是玩家們所追求的目標。隨著英特爾第十代桌面及移動版酷睿處理器的發布&#xff0c;無論是臺式整機或是筆記本平臺&#xff0c;都已全面進入了5GHz時代。選擇英特爾處理…

leetcode46. 全排列(回溯)

給定一個 沒有重復 數字的序列&#xff0c;返回其所有可能的全排列。 示例: 輸入: [1,2,3] 輸出: [ [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1] ] 代碼 class Solution {List<List<Integer>> cListnew ArrayList<>();public List<List<…

初級算法-12.反轉字符串

題目描述: 編寫一個函數&#xff0c;其作用是將輸入的字符串反轉過來。輸入字符串以字符數組 char[] 的形式給出。 不要給另外的數組分配額外的空間&#xff0c;你必須原地修改輸入數組、使用 O(1) 的額外空間解決這一問題。 你可以假設數組中的所有字符都是 ASCII 碼表中的可打…

linux python源碼目錄結構,TensorFlow0.8源碼閱讀 -- 代碼目錄結構講解

TensorFlow0.8發布以來受到了大量機器學習領域愛好者的關注&#xff0c;目前其項目在github上的follow人數在同類項目中排名第一。作為google的第一個開源項目&#xff0c;TensorFlow的源碼結構較為清晰&#xff0c;相關的代碼注釋覆蓋較全。本文首先從代碼結構入手&#xff0c…

在VirtualBox里復制VDI文件[轉]

原文地址:http://blog.sina.com.cn/s/blog_591a2c940100aree.html 在VirtualBox的快速修復界面里&#xff0c;可以隨時生成當前狀態的備份。當生成了備份之后&#xff0c;會在Snapshots目錄下創建一個新的VDI文件&#xff0c;之后對當前狀態所做的一切操作都將針對最新的VDI文件…

軟件開發重要性_在軟件開發中考慮時間的重要性

軟件開發重要性by Crunch Tech通過Crunch Tech 在軟件開發中考慮時間的重要性 (The importance of time to think in Software Development) Modern Technology teams operate in a fast-paced environment. With a Technology team of only 35 people, we average over 50 re…

自動登錄360,百度

方便登錄&#xff0c;寫的小工具 1 import win.ui;2 import web.ui;3 /*DSG{{*/4 var winform ..win.form(text"AAuto Form";right599;bottom399)5 winform.add(6 button{cls"button";text"百度";left41;top25;right163;bottom59;z1};7 button2…

arm linux 開機電路_【技術角度看問題之一】ARM到底是個啥?

【小宅按】近期公司推出來基于ARM芯片的服務器&#xff0c;本文就一些基本概念&#xff0c;比如ARM&#xff0c; ARM64, ARMv8, ARM7&#xff0c;ARMv7, 64位等讓人費解的概念進行了粗淺地分析&#xff0c;涉及的關鍵字已用粗體標出。文中觀點僅僅是一家之言&#xff0c;拙劣之…

leetcode77. 組合(回溯)

給定兩個整數 n 和 k&#xff0c;返回 1 … n 中所有可能的 k 個數的組合。 示例: 輸入: n 4, k 2 輸出: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] 代碼 class Solution {List<List<Integer>> cListnew ArrayList<>();public List<List<I…