ล่าสุดการพัฒนาเว็บบทเรียน
×

CSS การอ้างอิง

CSS การอ้างอิง CSS selectors CSS ฟังก์ชั่น CSS หูอ้างอิง CSS ปลอดภัยเว็บแบบอักษร CSS Animatable CSS หน่วย CSS PX-EM แปลง CSS สี CSS สี ค่า CSS3 สนับสนุนเบราว์เซอร์

CSS คุณสมบัติ

align-content align-items align-self all animation animation-delay animation-direction animation-duration animation-fill-mode animation-iteration-count animation-name animation-play-state animation-timing-function backface-visibility background background-attachment background-blend-mode background-clip background-color background-image background-origin background-position background-repeat background-size border border-bottom border-bottom-color border-bottom-left-radius border-bottom-right-radius border-bottom-style border-bottom-width border-collapse border-color border-image border-image-outset border-image-repeat border-image-slice border-image-source border-image-width border-left border-left-color border-left-style border-left-width border-radius border-right border-right-color border-right-style border-right-width border-spacing border-style border-top border-top-color border-top-left-radius border-top-right-radius border-top-style border-top-width border-width bottom box-shadow box-sizing caption-side clear clip color column-count column-fill column-gap column-rule column-rule-color column-rule-style column-rule-width column-span column-width columns content counter-increment counter-reset cursor direction display empty-cells filter flex flex-basis flex-direction flex-flow flex-grow flex-shrink flex-wrap float font @font-face font-family font-size font-size-adjust font-stretch font-style font-variant font-weight hanging-punctuation height justify-content @keyframes left letter-spacing line-height list-style list-style-image list-style-position list-style-type margin margin-bottom margin-left margin-right margin-top max-height max-width @media min-height min-width nav-down nav-index nav-left nav-right nav-up opacity order outline outline-color outline-offset outline-style outline-width overflow overflow-x overflow-y padding padding-bottom padding-left padding-right padding-top page-break-after page-break-before page-break-inside perspective perspective-origin position quotes resize right tab-size table-layout text-align text-align-last text-decoration text-decoration-color text-decoration-line text-decoration-style text-indent text-justify text-overflow text-shadow text-transform top transform transform-origin transform-style transition transition-delay transition-duration transition-property transition-timing-function unicode-bidi vertical-align visibility white-space width word-break word-spacing word-wrap z-index



 

ค่าสี CSS กฎหมาย


สี CSS

สีใน CSS สามารถระบุได้โดยวิธีการดังต่อไปนี้:

  • สีเลขฐานสิบหก
  • สี RGB
  • สี RGBA
  • สี HSL
  • สี HSLA
  • ชื่อสีที่กำหนดไว้ล่วงหน้า / เบราว์เซอร์

สีเลขฐานสิบหก

ค่าสีฐานสิบหกได้รับการสนับสนุนในเบราว์เซอร์ที่สำคัญทั้งหมด

สีฐานสิบหกมีการระบุด้วย: # RRGGBB ที่ RR (red) , GG (green) และบีบี (blue) เลขฐานสิบหกระบุส่วนประกอบของสี ค่าทั้งหมดจะต้องอยู่ระหว่าง 00 และ FF

ตัวอย่างเช่นค่า # 0000FF จะกลายเป็นสีฟ้าเพราะองค์ประกอบสีฟ้าถูกตั้งค่าสูงสุด (ff) และคนอื่น ๆ มีการกำหนดให้ 00

ตัวอย่าง

กำหนดสี HEX แตกต่างกัน:

#p1 {background-color: #ff0000;}   /* red */
#p2 {background-color: #00ff00;}   /* green */
#p3 {background-color: #0000ff;}   /* blue */
ลองตัวเอง»

สี RGB

ค่าสี RGB ได้รับการสนับสนุนในเบราว์เซอร์ที่สำคัญทั้งหมด

ค่าสี RGB จะถูกระบุด้วย: rgb(red, green, blue) แต่ละพารามิเตอร์ (สีแดง, สีเขียวและสีน้ำเงิน) กำหนดความเข้มของสีและสามารถเป็นจำนวนเต็มระหว่าง 0 และ 255 หรือค่าเปอร์เซ็นต์ (from 0% to 100%)

ยกตัวอย่างเช่น rgb(0,0,255) ค่าการแสดงผลเป็นสีฟ้าเพราะพารามิเตอร์สีฟ้าถูกตั้งค่าสูงสุด (255) และคนอื่น ๆ ที่มีการตั้งค่าเป็น 0

นอกจากนี้ค่าต่อไปนี้กำหนดสีเท่ากับ: rgb(0,0,255) และ rgb(0%,0%,100%)

ตัวอย่าง

กำหนดสี RGB ที่แตกต่างกัน

#p1 {background-color: rgb(255, 0, 0);}   /* red */
#p2 {background-color: rgb(0, 255, 0);}   /* green */
#p3 {background-color: rgb(0, 0, 255);}   /* blue */
ลองตัวเอง»

สี RGBA

ค่าสี RGBA รับการสนับสนุนใน IE9 +, Firefox 3+, Chrome, Safari และ Opera ใน 10+

ค่าสี RGBA เป็นส่วนขยายของค่าสี RGB ที่มีช่องอัลฟา - ซึ่งระบุความทึบแสงของวัตถุ

ค่าสี RGBA ถูกระบุด้วย: rgba(red, green, blue, alpha) พารามิเตอร์อัลฟาเป็นตัวเลขระหว่าง 0.0 (fully transparent) และ 1.0 (fully opaque)

ตัวอย่าง

กำหนดสี RGB ที่แตกต่างกับความทึบ:

#p1 {background-color: rgba(255, 0, 0, 0.3);}   /* red with opacity */
#p2 {background-color: rgba(0, 255, 0, 0.3);}   /* green with opacity */
#p3 {background-color: rgba(0, 0, 255, 0.3);}   /* blue with opacity */
ลองตัวเอง»

สี HSL

ค่าสี HSL รับการสนับสนุนใน IE9 +, Firefox, Chrome, Safari และ Opera ใน 10+

HSL ยืนสำหรับสี, ความอิ่มตัวและความสว่าง - และแสดงให้เห็นถึงรูปทรงกระบอกพิกัดตัวแทนของสี

ค่าสี HSL ถูกระบุด้วย: hsl(hue, saturation, lightness)

เว้เป็นระดับบนวงล้อสี (from 0 to 360) - 0 (or 360) เป็นสีแดงสีเขียว 120, 240 เป็นสีฟ้า อิ่มตัวเป็นค่าเปอร์เซ็นต์; 0% หมายความว่าร่มเงาของสีเทาและ 100% เป็นสีเต็มรูปแบบ ความสว่างยังเป็นเปอร์เซ็นต์; 0% เป็นสีดำ 100% เป็นสีขาว

ตัวอย่าง

กำหนดสี HSL แตกต่างกัน:

#p1 {background-color: hsl(120, 100%, 50%);}   /* green */
#p2 {background-color: hsl(120, 100%, 75%);}   /* light green */
#p3 {background-color: hsl(120, 100%, 25%);}   /* dark green */
#p4 {background-color: hsl(120, 60%, 70%);}    /* pastel green */
ลองตัวเอง»

สี HSLA

ค่าสี HSLA รับการสนับสนุนใน IE9 +, Firefox 3+, Chrome, Safari และ Opera ใน 10+

ค่าสี HSLA เป็นส่วนขยายของค่าสี HSL กับช่องอัลฟา - ซึ่งระบุความทึบแสงของวัตถุ

ค่าสี HSLA ถูกระบุด้วย: hsla(hue, saturation, lightness, alpha) ที่พารามิเตอร์อัลฟากำหนดทึบ พารามิเตอร์อัลฟาเป็นตัวเลขระหว่าง 0.0 (fully transparent) และ 1.0 (fully opaque)

ตัวอย่าง

กำหนดสี HSL ที่แตกต่างกับความทึบ:

#p1 {background-color: hsla(120, 100%, 50%, 0.3);}   /* green with opacity */
#p2 {background-color: hsla(120, 100%, 75%, 0.3);}   /* light green with opacity */
#p3 {background-color: hsla(120, 100%, 25%, 0.3);}   /* dark green with opacity */
#p4 {background-color: hsla(120, 60%, 70%, 0.3);}    /* pastel green with opacity */
ลองตัวเอง»

ที่กำหนดไว้ล่วงหน้า / เบราว์เซอร์ชื่อสี

140 ชื่อสีกำหนดไว้ล่วงหน้าใน HTML CSS และสีสเปค

มองไปที่โต๊ะของ ชื่อสีที่กำหนดไว้ล่วงหน้า