CSS基礎屬性2

屬性名:屬性值
Background-color:red
P{
background-color:red
font-size:24px
}
2.1字體相關屬性
font-family:字體名稱
font-size:字體大小
font-style:字形(斜體等)
font-variaus:字體變化
font-variant:字體變化(如大寫)
font-weight: 100;字體粗細
italic:斜體

<style type="text/css">
    p{
        font-family: 楷體;
        font-size: 36px;
        font-style: italic;
        font-variant: small-caps;
        font-weight: 100;
        font:60px 楷體;
    }
</style>

可以簡寫,書寫循序
font-style: font-variant: font-weight: font-size: font-family:
前面三個不可去缺,使用默認值,font-size:和font-family:必須指定值。

p{
    font:60px 楷體;
}

2.2文本相關屬性
主演包括顏色、對齊方式、修飾效果等。
color設置文本的顏色
text-decoration文本的修飾
none:默認值,沒有修飾效果;
uaderline:加下劃線;
overline:加上劃線;
line-through:加刪除線;
text-shadow:增加陰影。比如text-shadow: 5px 20px blue的含義是定義一個綠色的背景,其水平方向上左移5px,垂直向上上移10px。
Direction:文本的方向:{ltr:自左向右;rtl自右向左}

text-align:文本對其方式:
{left左對齊;
right右對齊;
center居中;
justify兩端對齊;}

vertical-align:文本垂直對其方式:
{top:靠上對齊;
bottom:靠下對齊;
middle:垂直居中}
text-indent:文本縮進
letter-spacing:字符之間的間距
word-spacing:字(單詞)間距
line-height:設置行高,實際上是調整行間距

2.3 背景相關屬性

body{
    background-color: #3aff31;
    background-image: url("圖片/gou.jpg");
    background-repeat: no-repeat;
    background-position: bottom;
}

background-color:背景色;
background-image:設定背景圖片,需要設置圖片的url地址;
background-repeat:圖片的複製選項;
repeat:在水平和垂直兩個方向上進行復制;
no-repeat:不復制;
repeat-x:在水平方向上覆制;
repeat-y:在垂直方向上覆制;
也可以將這一組屬性值封裝到一個屬性background中,書寫書序是:背景色background-color;
背景圖片background-image;
重複方式background-repeat;
位置backgroud-position;
表達更加簡潔

background: green url("../pic/js.jpg") no-repeat right top;

2.4尺寸相關的屬性
height:高度
width寬度

  <style type="text/css">
        div{
            height: 200px;
            background-color: #ff586e;
        }
    </style>
</head>
<body>
<div></div>
</body>

max-width:最大寬度
max-height:最大高度
min-width:最小寬度
min-height:最小高度

2.5顯示相關屬性
隱藏元素的方法
(1)Visibility:hidden:僅僅隱藏內容,該元素所佔位置依然存在;
(2)display:none:(顯示爲空)不僅隱藏內容,還隱藏元素所

div{
height: 300px;
display: none;
}

play可以設置元素的顯示模式
inline;將塊級元素以內聯元素顯示,此刻width和height屬性無效,其空間取決於元素的內容。
inline-block將塊級元素以內聯元素形式顯示,同時兼具塊級元素的某些特徵,比如可以使用width和height設置所佔位置大小。

<style type="text/css">
    li{
        /*display: inline;*/
        display: inline-block;
        width: 200px;
        background-color: blueviolet;
    }
    span{
        display: block;
    }
</style>

也可以將內聯元素以塊級元素形式來顯示,即display:block。

2.6 盒子模型
margin:外邊距
margin-top、margin-right、margin-bottom、margin-left
使用方式
(1)margin:30px;表示上下左右外邊距都未30px;
(2)margin-left:30px;單獨設置上下左右外邊距
(3)margin:10px 20px 30px 40px;分別設置上右下左四個邊距爲10px 20px 30px 40px

padding:內邊距
也有上下左右邊距,和margin類似,不再贅述。

border:邊框
border-width: 邊框寬度;
border-style: 邊框線條類型;
border-color: 邊框的顏色;
word中設置邊框的操作
也可以使用更優化的書寫方式
border:10px dashed blue;

margin: 20px 40px 60px 80px;
 padding: 50px;
border: 5px solid blueviolet;
 outline: 5px dotted red;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章