CSS常用屬性2

來源:互聯網
上載者:User

標籤:

一、邊框(Border)

  border:複合屬性。設定對象邊框的特性。

  取值:border: line-width | line-style | color

    1)line-width:設定或檢索對象邊框寬度。

    2)line-width:設定或檢索對象邊框樣式。

    3)color:設定或檢索對象邊框顏色。

樣本:

這裡有邊框

<!DOCTYPE html><html>    <head>        <meta charset="UTF-8">        <title></title>        <style type="text/css">            div{                width: 200px;                height: 200px;                border: 5px solid #000000;            }        </style>    </head>    <body>        <div>            <p>這裡有邊框</p>        </div>    </body></html>

 

  1、邊框寬厚(border-width):指定邊框厚度。

    取值:border-width:length | thin | medium | thick

      1)length:用長度值來定義邊框的厚度。不允許負值

      2)medium:定義預設厚度的邊框。計算值為3px

      3)thin:定義比預設厚度細的邊框。計算值為1px

      4)thick:定義比預設厚度粗的邊框。計算值為5px

    border-width-top | border-width-bottom | border-width-left | border-width-right  分別指上、下、左、右 邊框。

 

  2、邊框樣式(border-style):定義邊框的樣式

    取值:border-style:line-style  效果如下:

  • dotted:定義一個點線框
  • dashed:定義一個虛線框
  • solid:定義實線邊界
  • double:定義兩個邊界。 兩個邊界的寬度和border-width的值相同
  • groove: 定義3D溝槽邊界。效果取決於邊界的顏色值
  • ridge: 定義3D脊邊界。效果取決於邊界的顏色值
  • inset:定義一個3D的嵌入邊框。效果取決於邊界的顏色值
  • outset: 定義一個3D突出邊框。 效果取決於邊界的顏色值

  border-top-style | border-bottom-style | border-left-style | border-right-style  分別指上、下、左、右 邊框。

代碼如下:(- -!算了 格式上面有,效果又有。)

 

  3、邊框顏色(border-color):設定邊框的顏色。可以設定的顏色。

    取值:border-color:color(指定顏色)

這個邊框有四種顏色

以上css代碼如下:

div{    width: 70px;    height: 70px;    border-width: 5px;    border-style: solid;    border-top-color: red;    border-right-color: blue;    border-bottom-color: green;    border-left-color: yellow;}

 

  4、利用邊框做出三角箭頭:

 
div{    width: 0;     height: 0;     border-top: 100px solid red;     border-left: 100px solid transparent;     border-right: 100px solid transparent;}

 

 

  4、圓角效果(border-radius):向元素添加圓角邊框

所有角都是用半徑為5px的圓角

 
div{    margin:5px;    width: 50px;     height: 50px;    background: black;     border-radius: 5px;}

四個半徑值分別是左上方、右上方、右下角、左下角,順時針

 
div{    margin: 5px;    width: 50px;     height: 50px;     background: black;     border-radius: 5px 4px 3px 2px;}

也可以分別設定每個角的垂直半徑和水平半徑,用斜杠隔開,第一個參數表示左上方開始順時針的水平半徑,第二個參數左上方開始順時針的垂直半徑

 
div{    margin: 5px;    width: 50px;     height: 50px;     background: black;    border-radius: 5px 10px 15px 20px/3px 5px 10px 15px;}

圓

 
div{    margin: 5px;    width: 50px;     height: 50px;     background: black;    border-radius: 50%;}

半圓

 
div{    margin: 5px;     width: 25px;     height: 50px;     background: black;     border-radius: 50px 0 0 50px;}/*width是height的一半*/

 

 

  5、邊框圖片(border-image):邊框樣式使用映像填充。

    取值:

      border-image-source:設定或檢索對象的邊框是否用映像定義樣式或映像來源路徑。

      border-image-slice:設定或檢索對象的邊框背景圖的分割方式。

      border-image-width:設定或檢索對象的邊框厚度。

      border-image-outset:設定或檢索對象的邊框背景圖的擴充。

      border-image-repea:設定或檢索對象的邊框映像的平鋪方式。

樣本:

.test {    border: 10px solid gray;    border-image: url(test.png) 10/10px;}

使用映像替代 <‘ border-style ‘> 去定義邊框樣式。當 <‘ border-image ‘> 為none或映像不可見時,將會顯示 <‘ border-style ‘> 所定義的邊框樣式效果。

 

二、盒子陰影(box-shadow):向盒子添加陰影。支援添加一個或者多個。

    取值:box-shadow: X軸位移量 Y位移量 [陰影模糊半徑] [陰影擴充半徑] [陰影顏色] [投影方式]

外陰影常規效果

 
div{    margin: 5px;     width: 50px;     height: 50px;     background: red;     box-shadow: 5px 5px rgba(0,0,0,.6);}

外陰影模糊外延陰影製作效果

 
div{    margin: 5px;     width: 50px;     height: 50px;     background: red;     box-shadow: 5px 5px 5px 5px rgba(0,0,0,.6);}

內陰影製作效果

 
div{    margin: 5px;     width: 50px;     height: 50px;     background: red;     box-shadow: 2px 2px 5px 1px rgba(0,0,0,.6) inset;}

雙內陰影製作效果(兩個陰影用逗號分開)

 
div{    margin: 5px;     width: 50px;     height: 50px;     background: red;     box-shadow: 2px 2px 5px 1px rgba(0,0,0,.6) inset,-2px -2px 5px 1px rgba(0,0,0,.6) inset;}

 

三、段落

  1、行高(line-height):控制段落內每行高度。

    取值:line-height: normal | length

代碼如下:

p{line-height:15px}p{line-height:150%}

 

  2、段落縮排(text-indent):控制段落的首行縮排。

    取值:text-indent:lenght

代碼如下:

p{text-indent:2em}

  4、段落對齊(text-align):控制段落對齊,不但是文本,對象中的其他inline或inline-block元素也能夠被text-align進行對齊設定。

    取值:text-align: left | right | center | justify(左右對齊)

代碼如下:

p{text-align:right}p{text-align:center}

 

  5、文字間距(letter-spacing):控制段落文字間的間距。

    取值:letter-spacing:normal | length

代碼如下:

p{letter-spacing:5px;}

 

  6、文字溢出(text-overflow): 控制文字內溢出部分的樣式。

    取值:text-overflow:clip | ellipsis

      1)clip:當內聯內容溢出塊容器時,將溢出部分裁切掉。

      2)ellipsis:當內聯內容溢出塊容器時,將溢出部分替換為(...)

  但是text-overflow只是用來解說文字溢出時用什麼方式顯示,要實現溢出時產生省略符號的效果,還必須定義強制文本在一行內顯示(white-space:nowrap)及溢出內容為隱藏(overflow:hidden),
只有這樣才能實現顯示溢出文本顯示省略符號的效果。

代碼如下:

原效果

以二三四五六七八九十

ellipsis效果

以二三四五六七八九十
p{    overflow:hidden;    white-space:nowrap;    text-overflow:ellipsis;}

   7、段落換行(word-wrap):控制內容超過容器的邊界時是否斷行。

    取值:word-wrap: normal | break-word

      1)normal:允許內容頂開或者溢出指定的容器邊界。

      2)break-word:內容將在邊界內換行。如果需要,單詞內部允許斷行。

 

四、背景樣式

  background:複合屬性。設定或檢索對象的背景特性。元素的背景是元素的總大小,包括填充和邊界(但不包括邊距)

  1、背景顏色(background-color):設定一個元素的背景顏色。

    取值:background-color:color(顏色)

如下:

 

div{    width:50px;    height:50px;    background-color:green;}

 

  1.1、漸層色彩(linear-gradient):CSS3 Gradient 分為線性漸層(linear)和放射狀漸層(radial)。

  - 第一個參數省略時,預設為”180deg“,等同於”to bottom“。
  - 第二個和第三個參數,表示顏色的起始點和結束點,可以有多個顏色值。(顏色值後面可以追加百分比,表示這個顏色要佔總背景顏色的面積百分比)

 
div{    width: 100px;     height: 100px;     border: 1px solid black;     background-image: linear-gradient(to left,red 30%,blue);}

 

  2、背景圖(background-image):設定一個元素的背景映像。

    取值:background-image: none | url(url)

  3、背景平鋪方式(background-repeat):設定如何平鋪對象的 background-image 屬性。預設情況下,重複background-image的垂直和水平方向。

    取值:background-repeat: repeat | no-repeat | repeat-x | repeat-y |

值 說明
repeat 背景映像將向垂直和水平方向重複。這是預設
repeat-x 只有水平位置會重複背景映像
repeat-y 只有垂直位置會重複背景映像
no-repeat background-image不會重複
inherit 指定background-repea屬性設定應該從父元素繼承

  4、背景定位(background-position):設定背景映像的起始位置。

    取值:background-position: 靠左對齊方式 上對齊

 

 

值 描述
left top
left center
left bottom
right top
right center
right bottom
center top
center center
center bottom
如果僅指定一個關鍵字,其他值將會是"center"
x% y% 第一個值是水平位置,第二個值是垂直。左上方是0%0%。右下角是100%100%。如果僅指定了一個值,其他值將是50%。 。預設值為:0%0%
xpos ypos 第一個值是水平位置,第二個值是垂直。左上方是0。單位可以是像素(0px0px)或任何其他 CSS單位。如果僅指定了一個值,其他值將是50%。你可以混合使用%和positions
inherit 指定background-position屬性設定應該從父元素繼承

(- -!媽蛋!今天就寫到這裡了...困死了!- -!把感冒靈沖劑當成飲料喝了!)

CSS常用屬性2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.