web開發(fā)筆記-css常用屬性(1)

簡(jiǎn)介

這次主要介紹一些css常用屬性

內(nèi)容

1. 顏色屬性:
** color**

  • HEX(十六進(jìn)制色:color: #FFFF00 --> 縮寫:#FF0)
  • RGB(紅綠藍(lán),使用方式:color:rgb(255,255,0)或者 color:rgb(100%,100%,0%))
  • RGBA(紅綠藍(lán)透明度,A是透明度在0~1之間取值。使用方式:color:rgba(255,255,0,0.5))
  • HSL(CSS3有效,H表示色調(diào),S表示飽和度,L表示亮度,使用方式:color:hsl(360,100%,50%))
    HSLA(和HSL相似,A表示Alpha透明度,取值0~1之間。)
    ** transparent**
    全透明,使用方式:color: transparent;
    ** opacity**
    元素的透明度,語(yǔ)法:opacity: 0.5;
    屬性值在0.0到1.0范圍內(nèi),0表示透明,1表示不透明。
    示例:
-css: .colorHEX {
            color: #B0F566;
        }
        
        .colorRGB {
            color: RGB(74, 242, 161);
        }
        
        .colorRGBA {
            color: RGBA(74, 242, 161, .5);
        }
        
        .colorHSL {
            color: HSL(200, 86%, 63%);
        }
        
        .colorHSLA {
            color: hsla(200, 86%, 63%, .5);
        }
-html:
<div class="colorHEX">color: #B0F566</div>
<div class="colorRGB"> color: RGB(74, 242, 161)</div>
<div class="colorRGBA"> color: RGBA(74, 242, 161, .5) </div>
<div class="colorHSL">color: HSL(200, 86%, 63%);</div>
<div class="colorHSLA"> color:HSLA(200, 86%, 63%, .5)</div>
color.png

2. 字體屬性:
** font-style: 用于規(guī)定斜體文本**

  • normal 文本正常顯示
  • italic 文本斜體顯示
  • oblique 文本傾斜顯示
    示例:
-css:
   .normal {
            font-style: normal;
        }
        
        .italic {
            font-style: italic;
            color: HSL(200, 86%, 63%);
        }
        
        .oblique {
            font-style: oblique;
            color: RGB(74, 242, 161);
        }
-html:
        <div class="normal"> font-style: normal</div>
        <div class="italic"> font-style: italic</div>
        <div class="oblique"> font-style: oblique</div>
font-style.png

font-weight: 設(shè)置文本的粗細(xì)

  • normal(默認(rèn))
  • bold(加粗)
  • bolder(相當(dāng)于<strong>和<b>標(biāo)簽)
  • lighter (常規(guī))
  • 100 ~ 900 整百(400=normal,700=bold)
    示例:
-css:
 .bold {
            font-weight: bold;
            color: HSL(200, 86%, 63%);
        }
        
        .bolder {
            font-weight: bolder;
            color: HSL(200, 86%, 63%);
        }
        
        .lighter {
            font-weight: lighter;
            color: HSL(200, 86%, 63%);
        }
        
        ._100 {
            font-weight: 100;
            color: HSL(200, 86%, 63%);
        }
        
        ._600 {
            font-weight: 600;
            color: HSL(200, 86%, 63%);
        }
-html:
 <div class="">font-weight:normal</div>
 <div class="bold">font-weight:bold</div>
 <div class="bolder">font-weight:bolder</div>
 <div class="lighter">font-weight:lighter</div>
<div class="_600">font-weight:600</div>
 <div class="_100">font-weight:100</div>
font-weight.png

font-size: 設(shè)置字體的大小

  • 默認(rèn)值:medium
  • <absolute-size>可選參數(shù)值:xx-small、 x-small、 small、 medium、 large、 x-large、 xx-large
  • <relative-size>相對(duì)于父標(biāo)簽中字體的尺寸進(jìn)行調(diào)節(jié)。可選參數(shù)值:smaller、 larger
  • <percentage>百分比指定文字大小。
  • <length>用長(zhǎng)度值指定文字大小,不允許負(fù)值。
    示例:
-css:
 .xx-small {
            font-size: xx-small;
        }
        
        .xx-large {
            font-size: xx-large;
        }
        
        ._200 {
            font-size: 200%;
        }
        
        .length_30px {
            font-size: 20px;
        }
-html:
    <div class="">font-size: medium</div>
    <div class="xx-large">font-size: xx-large</div>
    <div class="xx-small">font-size: xx-small</div>
    <div class="_200">font-size: 200%</div>
    <div class="length_30px">font-size: 20px</div>
font-size.png

3. 文本屬性:
white-space: 設(shè)置元素中空白的處理方式

  • normal:默認(rèn)處理方式。
  • pre:保留空格,當(dāng)文字超出邊界時(shí)不換行
  • nowrap:不保留空格,強(qiáng)制在同一行內(nèi)顯示所有文本,直到文本結(jié)束或者碰到br標(biāo)簽
  • pre-wrap:保留空格,當(dāng)文字碰到邊界時(shí)換行
  • pre-line:不保留空格,保留文字的換行,當(dāng)文字碰到邊界時(shí)換行
    示例:
-css:
 .pre {
            white-space: pre;
        }
        
        .nowrap {
            white-space: nowrap;
        }
        
        .pre-wrap {
            white-space: pre-wrap;
        }
        
        .pre-line {
            white-space: pre-line;
        }
     -html:
    <div class="box  "> white-space: normal; 任何值得做的,就把它做好。</div>
    <div class="box pre"> white-space: pre; 任何值得做的,就把它做好。</div>
    <div class="box nowrap"> white-space: nowrap;任何值得做的,就把它做好。</div>
    <div class="box pre-wrap"> white-space: pre-wrap; 任何值得做的,就 把 它 做 好。</div>
    <div class="box pre-line"> white-space: pre-line; 任何值得做的, 就 把 它 做 好。</div>
white-space.png

text-align: **文本的水平對(duì)齊方式 **

  • left
  • center
  • right
 -css:
       .text-left {
            text-align: left
        }
        .text-center {
            text-align: center
        }
        .text-right {
            text-align: right
        }
-html:
    <div class="box text-left">text-left</div>
    <div class="box text-center">text-center</div>
    <div class="box text-right">text-right</div>
text-align.png

vertical-align: **文本的垂直對(duì)齊方式 **
可詳見web開發(fā)筆記之vertical-align

結(jié)束

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 深入理解傅里葉變換Mar 12, 2017 這原本是我在知乎上對(duì)傅立葉變換、拉普拉斯變換、Z變換的聯(lián)系?為什么要進(jìn)...
    價(jià)值趨勢(shì)技術(shù)派閱讀 5,938評(píng)論 2 2
  • 1、垂直對(duì)齊 如果你用CSS,則你會(huì)有困惑:我該怎么垂直對(duì)齊容器中的元素?現(xiàn)在,利用CSS3的Transform,...
    kiddings閱讀 3,297評(píng)論 0 11
  • 1.塊級(jí)元素和行內(nèi)元素 塊級(jí)(block-level)元素;行內(nèi)(內(nèi)聯(lián)、inline-level)元素。 塊元素的...
    饑人谷_小侯閱讀 2,200評(píng)論 1 4
  • 你別看月亮高高在上 那其實(shí)只是表象 月亮和我們一樣 生活在地上 白天它拼命吸取陽(yáng)光 也流淚,也揮汗 盡管沒有葉綠素...
    程大泥閱讀 152評(píng)論 0 2
  • 人生之旅 , 如過(guò)山水 。 本想 , 這一程山水 , 不擔(dān)身外事 , 不牽塵世情 。只管 , 把碎念雜想放下 。 ...
    七星二少閱讀 353評(píng)論 0 0

友情鏈接更多精彩內(nèi)容