篇文章主要講述了CSS樣式更改中的背景Background,這篇文章我們來談談字體設置Font&邊框Border的基礎用法。
<div style='font-family: sans-serif normal'></div>
可用字體:
Serif
Sans-serif
Monospace
Cursive
Fantasy
Times
Courier
<div style='font-style:normal'></div>
文本傾斜:
normal 文本正常顯示
italic 文本斜體顯示
oblique 文本傾斜顯示
<div style='font-variant:small-caps'></div>
normal 顯示標準字體。
small-caps 顯示小型大寫字母的字體。
<div style='font-weight:normal'></div>
normal 標準的字符
bold 粗體字符
bolder 更粗的字符
lighter 更細的字符
也可以使用數字表示,范圍為100~900
<div style='font-size:60px'></div>
smaller 變小
larger 變大
length 固定值
而且還支持百分比
首先說一下邊框風格,它的風格比較多,常用的一般是實線為主:
<div style='border-style:none'></div>
hidden 隱藏邊框
dotted 點狀邊框
dashed 虛線邊框
solid 實線邊框
double 雙線邊框
groove 3D凹槽邊框
ridge 3D壟狀邊框
inset 3D inset邊框
outset 3D outset邊框
邊框也有四面,所以也會有上下左右
所以有時候為了更精確定位并修改樣式可以使用:
border-top-style 上邊框樣式
border-right-style 右邊框樣式
border-bottom-style 下邊框樣式
border-left-style 左邊框樣式
先定義邊框的寬度 風格和顏色,然后定義邊框的其它屬性。
<div style='border-radius:25px;'></div>
2).邊框陰影
<div style='box-shadow:1px 2px 2px 2px red'></div>
參數含義:
邊框各個方向的大小和顏色
3).邊框圖片
<div style='border-image:url(1.png) 30 30 10 round'></div>
參數含義:
邊框圖片的路徑
圖片邊框向內偏移
圖片邊框的寬度
邊框圖像區域超出邊框的量
圖像邊框是否應平鋪(repeated)、鋪滿(rounded)或拉伸(stretched)。
這篇文章主要介紹了CSS樣式更改篇中的字體設置Font&邊框Border設置,希望讓大家對CSS選擇器有個簡單的認識和了解。
****看完本文有收獲?請轉發分享給更多的人****
IT共享之家
想要學習更多,請前往Python爬蟲與數據挖掘專用網站:http://pdcfighting.com/
言
頁面總少不了字體吧,字體還有家族font-family,那好吧
字體格式
TTF (TrueType Font) 字體格式是由蘋果和微軟為 PostScript 而開發的字體格式。在 Mac 和 Windows 操作系統上,TTF 一直是最常見的格式,所有主流瀏覽器都支持它。然而,IE8 不支持 TTF;且 IE9 上只有被設置成 "installable" 才能支持(譯注:別想了,轉別的格式吧)。
TTF 允許嵌入最基本的數字版權管理標志————內置標志可以告訴我們字體作者是否允許改字體在 PDF 或者網站等處使用,所以可能會有版權問題。另一個缺點是,TTF 和 OTF 字體是沒壓縮的,因此他們文件更大。
OTF (OpenType Font) 由 TTF 演化而來,是 Adobe 和微軟共同努力的結果。OTF 字體包含一部分屏幕和打印機字體數據。OTF 有幾個獨家功能,包括支持多平臺和擴展字符集。OTF 字體可以在 Macintosh 和 Windows 系統上使用。
OTF 也允許多達 65000 個字符的存儲。這個額外的空間讓設計師可以自由地添加附加元素,比如小帽子、老式數字體、代替的字符和其他一些以前必須作為獨立字體分發的附加材料。
實踐
1、CSS引入TTF或OTF文件
@font-face {
font-family: HansKendrick-Regular;
src:url('../fonts/HansKendrick-Regular.otf');
}
備注:
otf文件由設計同學提供或自行下載。
url使用的是相對路徑。絕對路徑測不管是放在public還是src下均沒有測試成功。
2、CSS樣式的使用
font-family: 'HansKendrick-Regular';
font-style: normal;
font-weight: 400;
font-size: 14px;
line-height: 17px;
text-align: center;
color: rgba(255, 255, 255, 0.8);
備注:以上是樣例,根據實際情況配置即可。
資料來源:
午說了CSS字體的顏色屬性,下午來說下字體的文本對齊text-align和文本裝飾text-decoration
text-align屬性用于設置元素內文本內容的水平對齊方式。語法規則如下:
div {
text-align:center;
}
除了有center屬性外,還有另外兩個屬性:
left 左對齊(默認值)
right 右對齊
先看下居中效果:
對應代碼為:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
text-align: center;
}
</style>
</head>
<body>
<div>人保好,還是平安好呢?一個是央企,一個是巨頭</div>
</body>
</html>
然后是文案左對齊,看下效果:
對應代碼為:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
text-align: left;
}
</style>
</head>
<body>
<div>人保好,還是平安好呢?一個是央企,一個是巨頭</div>
</body>
</html>
最后是右對齊,看下效果:
對應的代碼為:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
text-align: right;
}
</style>
</head>
<body>
<div>人保好,還是平安好呢?一個是央企,一個是巨頭</div>
</body>
</html>
如果不寫文字對齊的屬性,看下默認應該都是左對齊,效果如下:
對應代碼為:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* div {
text-align: right;
} */
</style>
</head>
<body>
<div>人保好,還是平安好呢?一個是央企,一個是巨頭</div>
</body>
</html>
可以看到已經將text-align代碼注釋掉了,默認展示就是左對齊
今天先到這里,大家學習工作辛苦了~
*請認真填寫需求信息,我們會在24小時內與您取得聯系。