<p>HTML设置文本阴影,主要通过CSS的text-shadow
text-shadow
text-shadow: horizontal-offset vertical-offset blur-radius color;
horizontal-offset
vertical-offset
blur-radius
color
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-shadow: 2px 2px 5px red; /* 红色阴影,水平偏移2px,垂直偏移2px,模糊半径5px */
}
p {
text-shadow: -2px -2px 3px blue; /* 蓝色阴影,水平偏移-2px,垂直偏移-2px,模糊半径3px */
}
.multiple-shadows {
text-shadow: 1px 1px 2px black, 0 0 1em blue, 0 0 0.2em blue; /* 多个阴影效果 */
}
</style>
</head>
<body>
<h1>带有红色阴影的标题</h1>
<p>带有蓝色阴影的段落。</p>
<p class="multiple-shadows">多个阴影效果的文字。</p>
</body>
</html><h1>
<p>
.multiple-shadows
rgba(255, 0, 0, 0.5)
h1 {
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5); /* 半透明黑色阴影 */
}text-shadow
text-shadow
text-shadow
text-shadow
text-shadow
text-shadow
text-shadow
text-shadow
text-shadow
style
<!DOCTYPE html>
<html>
<head>
<style>
.shadow-text {
text-shadow: 2px 2px 5px #888888; /* 初始阴影 */
}
</style>
</head>
<body>
<h1 id="myHeading" class="shadow-text">动态改变阴影的标题</h1>
<script>
const heading = document.getElementById('myHeading');
heading.addEventListener('mouseover', function() {
this.style.textShadow = '4px 4px 8px #000000'; // 鼠标悬停时改变阴影
});
heading.addEventListener('mouseout', function() {
this.style.textShadow = '2px 2px 5px #888888'; // 鼠标移开时恢复初始阴影
});
</script>
</body>
</html><h1>
text-shadow
以上就是HTML如何设置文本阴影?text-shadow属性的用法是什么?的详细内容,更多请关注php中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号