天講了怎么使用css中font-family來設置字體,如微軟雅黑、宋體、Arial等。繼續講下使用font-size屬性來定義字體大小。
語法如下:
p {
font-size:20px;
}
px(像素)大小是我們網頁的最常用的單位。谷歌瀏覽器默認的字體大小為16px 不同瀏覽器可能默認顯示的字體字號大小不一致,盡量給一個明確值大小,不要默認大小??梢越o<body>指定整個頁面文字的大小。
來看下效果:
對應的代碼為:
<!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>CSS字體屬性之字體系列</title>
<!--對h2修改下字體-->
<style>
body {
font-size: 16px;
}
</style>
</head>
<body>
<h2>明月幾時有</h2>
<p>明月幾時有,把酒問青天</p>
<p>不知天上宮闕,今夕是何年</p>
<p>我欲乘風歸去,又恐瓊樓玉宇</p>
<p>高處不勝寒,起舞弄清影,何似在人間。</p>
</body>
</html>
有沒有發現除了標題標簽,其余的字的字體都是16px了?那么這里需要注意一點: 標題標簽比較特殊,需要單獨指定文字大小。
如下的效果:
可以看到標題字體變小了,具體的代碼為:
<!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>CSS字體屬性之字體系列</title>
<!--對h2修改下字體-->
<style>
body {
font-size: 16px;
}
h2 {
font-size: 16px;
}
</style>
</head>
<body>
<h2>明月幾時有</h2>
<p>明月幾時有,把酒問青天</p>
<p>不知天上宮闕,今夕是何年</p>
<p>我欲乘風歸去,又恐瓊樓玉宇</p>
<p>高處不勝寒,起舞弄清影,何似在人間。</p>
</body>
</html>
可以看到對h2單獨進行了字體設置
h2 {
font-size: 16px;
}
注意點:
不要忘記加上px
標題有特殊性,需要單獨設置文字大小。
好的,今天就到這里了。晚安~
頁中添加滾動字幕效果
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>滾動字體的設置</title>
</head>
<body>
<canvas id="canvas1" width="600" height="600" style="border:1px solid #000000"></canvas>
<script type="text/javascript">
var canvas1 = document.querySelector("#canvas1") // 1.找到畫布對象
var ctx = canvas1.getContext("2d") // 2.上下文對象(畫筆)
ctx.shadowBlur = 10; // 陰影距離
ctx.shadowColor = "red" // 陰影顏色
ctx.shadowOffsetX = 30 // 陰影偏移
ctx.shadowOffsetY = 30 // 陰影偏移
ctx.font = "150px 楷體"
ctx.fillText("你好!", 20,150)
ctx.fillText("你好!", 20,350)
ctx.strokeText('你好!',23, 153)
ctx.strokeText('你好',23, 553)
canvas繪制文字
var x = 600
setInterval(function(){
if(x > -350){
//清空畫布
ctx.clearRect(0,0,600,600)
ctx.strokeText('你好!',x, 153)
ctx.fillText("你好!", x,350)
ctx.font = "50px 宋體"
ctx.strokeText('每天學習一點點',x, 553)
x -= 3
}else{x=590}
}, 16)
</script>
</body>
</html>
*請認真填寫需求信息,我們會在24小時內與您取得聯系。