在HTML中,除了color和font-size外还有很多其他css属性可以应用。
在 HTML 和 CSS 中,除了 color 和 font-size 之外,还有许多其他的 CSS 属性可以用来控制网页元素的样式。以下是一些常见的 CSS 属性及其用途:
1. 背景属性
background-color: 设置元素的背景颜色。例如,background-color: lightblue;background-image: 设置元素的背景图片。例如,background-image: url('image.jpg');background-repeat: 控制背景图片是否重复。例如,background-repeat: no-repeat;background-position: 设置背景图片的位置。例如,background-position: center;
2. 边框属性
border: 设置元素的边框。例如,border: 1px solid black;border-width: 设置边框的宽度。例如,border-width: 2px;border-style: 设置边框的样式。例如,border-style: dashed;border-color: 设置边框的颜色。例如,border-color: red;
3. 间距和对齐
margin: 设置元素的外边距。例如,margin: 10px;padding: 设置元素的内边距。例如,padding: 5px;text-align: 设置文本的对齐方式。例如,text-align: center;vertical-align: 设置文本或行内元素的垂直对齐。例如,vertical-align: middle;
4. 字体属性
font-family: 设置文本的字体。例如,font-family: Arial, sans-serif;font-weight: 设置字体的粗细。例如,font-weight: bold;font-style: 设置字体的样式,例如,font-style: italic;
5. 尺寸和布局
width: 设置元素的宽度。例如,width: 100px;height: 设置元素的高度。例如,height: 50px;display: 控制元素的显示行为。例如,display: block;position: 设置元素的位置类型。例如,position: relative;top,right,bottom,left: 控制元素的位置。例如,top: 10px;
6. 文本效果
text-decoration: 设置文本的装饰效果。例如,text-decoration: underline;text-transform: 设置文本的转换效果。例如,text-transform: uppercase;
示例
<p style="color: yellowgreen; font-size: 16px; background-color: lightblue; border: 2px solid black; margin: 10px; padding: 5px; text-align: center;" title="demo">
yellowgreen color test
</p>在这个示例中,段落不仅设置了文字颜色和字体大小,还设置了背景颜色、边框、外边距、内边距以及文本对齐方式。
这些 CSS 属性可以组合使用,以达到各种不同的样式效果。