自建电商网站销售商品,响应式网站建设信息,域名是什么,花样云做网站怎样1.使用css画一个三角形
借助 border 实现#xff0c;在 width 和 height 都为 0 时#xff0c;设置 border#xff0c;便会呈现三角形。想要哪个方向的三角形#xff0c;设置其他三边为 透明即可。同时#xff0c;可以通过调整不同边的宽度#xff0c;来调整三角形的高度…1.使用css画一个三角形
借助 border 实现在 width 和 height 都为 0 时设置 border便会呈现三角形。想要哪个方向的三角形设置其他三边为 透明即可。同时可以通过调整不同边的宽度来调整三角形的高度和宽度。
style.box1 {width: 0;height: 0;content: ;border-right: 100px solid black;border-left: 100px solid transparent;border-top: 100px solid transparent;border-bottom: 100px solid transparent;}
/stylebodydiv classbox1/div
/body效果如下
2. 如何使用js来实现鼠标移入时修改元素的样式
法一使用addEventListener
element document.getElementById(box);element.addEventListener(mouseenter,(){element.style.backgroundColor pink;element.style.border 1px solid black;
})
element.addEventListener(mouseleave,(){element.style.backgroundColor ;element.style.border 1px red solid;
})
// 单击事件
element.addEventListener(click, () {alert(元素被单击了);
});法二直接设置 onmouseenter 和 onmouseleave 属性
element document.getElementById(box);element.onmouseenter function () {this.style.backgroundColor lightblue;this.style.color white;
};element.onmouseleave function () {this.style.backgroundColor ;this.style.color ;
};3. 驼峰格式与“-”格式相互转化
3.1 “-”格式转化为驼峰格式
let str hello-world;
function fun(str){let temp str.split(-);for(let i1;itemp.length;i){let s [...temp[i]];s[0] s[0].toUpperCase();temp[i] s.join();}return temp.join();
}
console.log(fun(str)) // helloWorld3.2 驼峰格式转换为“-”格式
let str helloWorld;
function fun(str){let res [];for(let i of str){if(ii.toUpperCase()){res.push(-);res.push(i.toLowerCase());}else{res.push(i)}}return res.join()
}
console.log(fun(str)) // hello-world