
批改狀態(tài):合格
老師批語:這個案例目前有點(diǎn)超前了, 大家先有點(diǎn)感覺吧
在style中用
position
屬性來實(shí)現(xiàn)元素定位
—position的值:
值 | 解釋 |
---|---|
absolute |
絕對定位,相對于 static 定位以外的第一個父元素進(jìn)行定位 |
relative |
相對定位,相對于該元素的正常位置按設(shè)置的屬性值進(jìn)行偏移 |
fixed |
絕對定位,相對于瀏覽器窗口進(jìn)行定位 |
static |
無定位,系統(tǒng)默認(rèn),根據(jù)文檔流中出現(xiàn)的位置顯示,并且大小根據(jù)原生大小顯示 |
px
絕對像素單位 vh
相對對象單位(可以理解相對百分比)
<a href="https://php.cn" target="_self">php.cn</a>
<!-- 預(yù)覽style.css -->
<a href="style.css" target="_blank">css文件</a>
<!--下載demo1.zip -->
<a href="demo1.zip" target="_blank">zip文件</a>
<a href="mailto:12345678@qq.com" target="_blank">發(fā)郵件</a>
<a href="tel:13888888888" target="_blank">13888888888</a>
<a href="#hello">跳轉(zhuǎn)到hello</a>
<h1 id="hello" style="margin-top: 1000px;">Hello world</h1>
<a href="#">跳轉(zhuǎn)到首頁</a>
<h1 id="#">回到首頁</h1>
對象常用的三種事件添加方法
<!-- this代表當(dāng)前對象 -->
<button onclick="console.log(this.innertext)">按鈕1</button>
script
中添加
<!-- this代表當(dāng)前對象 -->
<button >按鈕2</button>
<button >按鈕3</button>
<script>
// <!-- 對象屬性方式添加事件 只有最后一次有效的,同名事件彼此覆蓋-->
document.querySelectorAll('button')[1].onclick=function(){
console.log("第一次點(diǎn)擊");
};
document.querySelectorAll('button')[1].onclick=function(){
console.log("第二次點(diǎn)擊");
}
</script>
script
中使用addEventListener
const btn3=document.querySelectorAll('button')[2];
// btn3.addEventListener(事件類型,事件方法),可以給一個元素多次添加 同一個事件,并且可以自定義事件的觸發(fā)階段
btn3.addEventListener('click',function(){
console.log("第一次點(diǎn)擊");
});
btn3.addEventListener('click',function(){
console.log("第一次點(diǎn)擊");
}
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號