This is an explanation of the video content.
 用技术延续对ACG的热爱
475

 |   | 

HTML样式

定义

HTML的style属性用于向元素添加样式,如颜色、字体、大小等。

<!DOCTYPE html>
<html>
<body>

<p>I am normal</p>
<p style="color:red;">I am red</p>
<p style="color:blue;">I am blue</p>
<p style="font-size:50px;">I am big</p>

<h1 style="background-color:powderblue;">This is a heading</h1>
<p style="background-color:tomato;">This is a paragraph.</p>
<h1 style="text-align:center;">Centered Heading</h1>

</body>
</html>

常见样式名

使用style属性设置HTML元素的样式。

属性名 意义
background-color 设置背景颜色。
color 设置文本颜色。
font-family 设置文本字体。
font-size 设置文本大小。
text-align 设置文本对齐方式。
border 设置元素的边框样式,包括边框颜色、边框宽度和边框样式(实线、虚线等)。
margin 设置元素的外边距,控制元素与相邻元素之间的距离。
padding 设置元素的内边距,控制元素内容与边框之间的距离。
width 设置元素的宽度。
height 设置元素的高度。
display 设置元素的显示方式,如 block(块级元素)、inline(行内元素)等。
position 设置元素的定位方式,如 relative(相对定位)、absolute(绝对定位)等。
float 设置元素的浮动方式,使元素向左或向右浮动。
text-decoration 设置文本装饰效果,如 underline(下划线)、line-through(删除线)等。
text-transform 设置文本转换效果,如 capitalize(首字母大写)、uppercase(全大写)等。
text-overflow 控制文本溢出时的显示方式,如省略号显示。
box-shadow 设置元素的阴影效果。
cursor 设置鼠标指针在元素上的样式,如 pointer(手型光标)、default(默认指针)等。
opacity 设置元素的透明度。
transition 控制元素的过渡效果,如平滑的渐变过渡。
border-radius 设置元素的边框圆角效果。

style="?" 可以设置元素样式,?替换为要定义的样式

475 🖺前端 ↦ HTML __ 75 字
 HTML #8