css很簡單,但是離靈活應用還是有一定距離的,今天先查漏補缺放個小總結
1. padding(內邊距)的設置
Padding-top、right、bottom、left
內邊距都爲5px時,padding:5px
2. Border-width(邊框)
border-top-width、right、bottom、left
邊框都爲5px時,padding:Border-width:px
3. (margin)外邊距
Margin-top、right、bottom、left
外邊距都爲5px時,margin:5px
4. css主要有三種使用方式:
1)內部樣式:比較少用,相當於把外部樣式嵌入到了HTML的<head></head>之間去了
在html文檔的<style>標籤中中寫css樣式,格式:
<type>
//css代碼
body{background-color:red;}
</type>
2)外部樣式:較爲常用,最方便。就是把css單獨作爲一個文件,便於管理,並且可以將多個HTML文檔關聯到一個css上,使得批量管理更爲方便。
在html文檔中用<link>標籤,引用外部css文件,格式:
<link rel="icon"href="./assets/default/img/title.ico" />
<link rel="stylesheet"type="text/css" href="./css/bootstrap.min.css">
(<linkhref="./css/bootstrap.min.css">)
3)行內樣式:適用於css文檔比較小時
在標籤中使用,使用style屬性控制當前標籤的顯示效果
<div style="color:red;"></div>
5. css的jQuery使用
1)設置樣式
$("#delRoot").css('display',"none");
2)Jquery css函數用法(判斷標籤是否擁有某屬性)
判斷一個層是否隱藏: |
$("#id").css("display")=="none" ; |
在所有匹配的元素中,設置一個樣式屬性的值: |
$("p").css("color","red"); |
把一個“名/值對”對象設置爲所有匹配元素的樣式屬性。 這是一種在所有匹配的元素上設置大量樣式屬性的最佳方式 |
$("p").css({ color: "#ff0011", background: "blue" }); |
如果屬性名包含 "-"的話,必須使用引號: |
$("p").css({ "margin-left": "10px", "background-color": "blue" }); |