color
設置字體顏色以前,咱們首先了解color
在CSS
中有幾種取值方式,一共有4種方式,如有不全還請在評論區告知謝謝,4種方式以下:class
屬性值爲.box
中的字體顏色設置爲紅色。代碼塊css
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>設置字體顏色</title> <style> .box{ color: #FF0000; } </style> </head> <body> <h2 class="box">成功不是擊敗別人,而是改變本身</h2> </body> </html>
結果圖html
代碼塊瀏覽器
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>設置字體顏色</title> <style> .box{ color: rgb(250,0, 0) } </style> </head> <body> <h2 class="box">成功不是擊敗別人,而是改變本身</h2> </body> </html>
代碼塊字體
十進制表示顏色的方式在
CSS
中沒有瀏覽器兼容性問題。ui
代碼塊ssr
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>設置字體顏色</title> <style> .box{ color:red; } </style> </head> <body> <h2 class="box">成功不是擊敗別人,而是改變本身</h2> </body> </html>
結果圖code
代碼塊htm
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>設置字體顏色</title> <style> .box{ color: #F00; } </style> </head> <body> <h2 class="box">成功不是擊敗別人,而是改變本身</h2> </body> </html>
結果圖blog