zoukankan      html  css  js  c++  java
  • 【CSS属性#1】

    "


    目录

    一、宽和高

    二、字体属性

    1. 文字字体 font-famlly

    2. 字体大小 font-size

    3. 字重(粗细) font-weight

    4. 文本颜色 color

    三、字符属性

    1. 文字对齐 text-align

    2. 文字装饰 text-decoration

    3. 首行缩进 text-indent

    四、背景

    五、边框

    六、圆形 border-radius

    七、display 属性

     


    一、宽和高

    • width:设置属性宽度,宽度向右填充空格,块级标签才可设置宽度,内联标签的宽度度由内容来决定.
    • heigth:设置属性高度,高度向下填充空白.
    1. <!DOCTYPE html>
    2. <html lang="zh-CN">
    3. <head>
    4. <meta http-equiv="content-Type" charset="UTF-8">
    5. <meta http-equiv="x-ua-compatible" content="IE=edge">
    6. <meta http-equiv="refresh" content="60; URL=https://blog.csdn.net/qq_41964425">
    7. <title>CSS</title>
    8. <style>
    9. #tag {
    10. width: 20%;
    11. height: 10px;
    12. }
    13. p {
    14. width: 31px;
    15. }
    16. </style>
    17. </head>
    18. <body>
    19. <div>
    20. <p id="tag">劫过九重城关</p>
    21. <p>我座下马正酣</p>
    22. </div>
    23. </body>
    24. </html>

    二、字体属性

    1. 文字字体 font-famlly

    可以把多个字体名称作为一个“回退”系统来保存,如果浏览器不支持第一个字体,则会尝试下一个,浏览器会使用它可识别的第一个值.

    1. <!DOCTYPE html>
    2. <html lang="zh-CN">
    3. <head>
    4. <meta http-equiv="content-Type" charset="UTF-8">
    5. <meta http-equiv="x-ua-compatible" content="IE=edge">
    6. <meta http-equiv="refresh" content="60; URL=https://blog.csdn.net/qq_41964425">
    7. <title>CSS</title>
    8. <style>
    9. body {
    10. /*font-family*/
    11. font-family: "Mircrosoft Yahei", "微软雅黑", "Arial", "sans-serif";
    12. color: yellowgreen;
    13. }
    14. </style>
    15. </head>
    16. <body>
    17. <div>
    18. <p>看那轻飘飘的衣摆</p>
    19. <p>趁擦肩把裙掀</p>
    20. </div>
    21. </body>
    22. </html>

    2. 字体大小 font-size

    大小有px、%之分,16px与100%为默认字体大小.
    如果值为 inherit  则继承父元素的字体大小.

    1. <!DOCTYPE html>
    2. <html lang="zh-CN">
    3. <head>
    4. <meta http-equiv="content-Type" charset="UTF-8">
    5. <meta http-equiv="x-ua-compatible" content="IE=edge">
    6. <meta http-equiv="refresh" content="60; URL=https://blog.csdn.net/qq_41964425">
    7. <title>CSS</title>
    8. <style>
    9. div {
    10. font-size: 16px; /*font-size*/
    11. color: darkcyan;
    12. }
    13. </style>
    14. </head>
    15. <body>
    16. <div>
    17. <p>踏遍三江六岸</p>
    18. <p>借刀光做船帆</p>
    19. </div>
    20. </body>
    21. </html>

    3. 字重(粗细) font-weight

    描述
    normal 默认值,标准粗细
    bold 粗体
    bolder 更粗
    lighter 更细
    100~900 设置具体粗细,400为normal,700为bold
    inherit 继承父元素字体的粗细值
    1. <!DOCTYPE html>
    2. <html lang="zh-CN">
    3. <head>
    4. <meta http-equiv="content-Type" charset="UTF-8">
    5. <meta http-equiv="x-ua-compatible" content="IE=edge">
    6. <meta http-equiv="refresh" content="60; URL=https://blog.csdn.net/qq_41964425">
    7. <title>CSS</title>
    8. <style>
    9. /*font-weight*/
    10. p {
    11. font-weight: lighter;
    12. }
    13. #tag {
    14. font-weight: 700;
    15. }
    16. </style>
    17. </head>
    18. <body>
    19. <div>
    20. <p>任露水浸透了短衫</p>
    21. <p id="tag">大盗睥睨四野</p>
    22. </div>
    23. </body>
    24. </html>

    4. 文本颜色 color

    color属性用来设置字符的颜色,是CSS最常用的属性.

    • 十六进制值(如:#FFFFFF,可简写为FFF)
    • RGB值(如:rgb(255,0,0))
    • 颜色名称(如:blue)
    • 还有rgba(255,0,0,0.5),第四个值为alpha,用于指定色彩的透明/不透明度,范围在0.0-1.0之间
    1. <!DOCTYPE html>
    2. <html lang="zh-CN">
    3. <head>
    4. <meta http-equiv="content-Type" charset="UTF-8">
    5. <meta http-equiv="x-ua-compatible" content="IE=edge">
    6. <meta http-equiv="refresh" content="60; URL=https://blog.csdn.net/qq_41964425">
    7. <title>CSS</title>
    8. <style>
    9. #tag1 {color: #A9A9A9;} /*十六进制值,可简写*/
    10. #tag2 {color: rgb(150,100,0);} /*RGB值*/
    11. #tag3 {color: darkgrey;} /*颜色名称*/
    12. #tag4 {color: rgba(150,100,0,0.5);} /*rgba*/
    13. </style>
    14. </head>
    15. <body>
    16. <div>
    17. <p id="tag1">枕风宿雪多年</p>
    18. <p id="tag2">我与虎谋早餐</p>
    19. <p id="tag3">拎着钓叟的鱼弦</p>
    20. <p id="tag4">问卧龙几两钱</p>
    21. </div>
    22. </body>
    23. </html>

    三、文字属性

    1. 文字对齐 text-align

    描述
    left 左对齐,默认值
    right 右对齐
    center 居中对齐
    justify 两端对齐
    1. <!DOCTYPE html>
    2. <html lang="zh-CN">
    3. <head>
    4. <meta http-equiv="content-Type" charset="UTF-8">
    5. <meta http-equiv="x-ua-compatible" content="IE=edge">
    6. <meta http-equiv="refresh" content="60; URL=https://blog.csdn.net/qq_41964425">
    7. <title>CSS</title>
    8. <style>
    9. #tag1 {text-align: left;} /*左对齐*/
    10. #tag2 {text-align: right;} /*右对齐*/
    11. #tag3 {text-align: center;} /*居中对齐*/
    12. #tag4 {text-align: justify;} /*两端对齐*/
    13. </style>
    14. </head>
    15. <body>
    16. <div>
    17. <p id="tag1">蜀中大雨连绵</p>
    18. <p id="tag2">关外横尸遍野</p>
    19. <p id="tag3">你的笑像一条恶犬</p>
    20. <p id="tag4">撞乱了我心弦</p>
    21. </div>
    22. </body>
    23. </html>

    2. 文字装饰 text-decoration

    描述
    none 标准文本,默认值
    常用于去掉a标签默认的下划线
    underline 定义文本下的一条线
    overline 定义文本上的一条线
    line-through 定义穿过文本的一条线
    inherit

    继承父元素

    1. <!DOCTYPE html>
    2. <html lang="zh-CN">
    3. <head>
    4. <meta http-equiv="content-Type" charset="UTF-8">
    5. <meta http-equiv="x-ua-compatible" content="IE=edge">
    6. <meta http-equiv="refresh" content="60; URL=https://blog.csdn.net/qq_41964425">
    7. <title>CSS</title>
    8. <style>
    9. #tag1 {text-decoration: none;} /*标准文本*/
    10. #tag2 {text-decoration: underline;} /*下划线*/
    11. #tag3 {text-decoration: overline;} /*上划线*/
    12. #tag4 {text-decoration: line-through;} /*删除线*/
    13. a {text-decoration: none;} /*去掉a标签默认的下划线*/
    14. </style>
    15. </head>
    16. <body>
    17. <div>
    18. <p id="tag1">谈花饮月赋闲</p>
    19. <p id="tag2">这春宵艳阳天</p>
    20. <p id="tag3">待到梦醒时分睁眼</p>
    21. <p id="tag4">铁甲寒意凛冽</p>
    22. <a href="https://blog.csdn.net/qq_41964425" target="_blank">CSDN</a>
    23. </div>
    24. </body>
    25. </html>

    3. 首行缩进 text-indent

    常用的有像素(px)、百分比(%),默认缩进值都为零.

    1. <!DOCTYPE html>
    2. <html lang="zh-CN">
    3. <head>
    4. <meta http-equiv="content-Type" charset="UTF-8">
    5. <meta http-equiv="x-ua-compatible" content="IE=edge">
    6. <meta http-equiv="refresh" content="60; URL=https://blog.csdn.net/qq_41964425">
    7. <title>CSS</title>
    8. <style>
    9. #tag1 {text-indent: 32px;} /*将段落的第一行缩进32像素*/
    10. #tag2 {text-indent: 32%;} /*将段落的第一行缩进32百分比*/
    11. </style>
    12. </head>
    13. <body>
    14. <div>
    15. <P id="tag1">夙愿只隔一箭</P>
    16. <p id="tag2">故乡近似天边</p>
    17. </div>
    18. </body>
    19. </html>

    四、背景

    操作 解释
    background-color: red; 将背景颜色设为红色
    bsckground-image: url("test.jpg"); 将test.jpg图片设为网页背景
    background-position: right top; 图片位置:右 上
    还可写成像素百分比等
    background-position

    背景重复,值如下:
    repeat:平铺整个网页,默认值
    repeat-x:水平方向平铺

    		<p>repeat-y:垂直方向平铺<br>
    		no-repeat:背景图片不平铺</p>
    		</td>
    	</tr></tbody></table></div><p><strong>简写:</strong><span style="color:#86ca5e;">background: green&nbsp;url("test.jpg") no-repeat </span><span style="color:#86ca5e;">center center;</span></p>
    

    很多网站会把一些小图标放在一张图片上,然后根据位置去显示图片,从而减少频繁的图片请求.

    一个有趣的例子:鼠标滚动背景不动:

    1. <!DOCTYPE html>
    2. <html lang="zh-CN">
    3. <head>
    4. <meta http-equiv="content-Type" charset="UTF-8">
    5. <meta http-equiv="x-ua-compatible" content="IE=edge">
    6. <meta http-equiv="refresh" content="60; URL=https://blog.csdn.net/qq_41964425">
    7. <title>鼠标滚动背景不动</title>
    8. <style>
    9. * {
    10. margin: 0;
    11. }
    12. .tag1 {
    13. width: 3%;
    14. height: 200px;
    15. background-color: antiquewhite;
    16. }
    17. .tag2 {
    18. color: white;
    19. width: 100%;
    20. height: 300px;
    21. background:
    22. url("http://img3.imgtn.bdimg.com/it/u=1167730288,2455334783&fm=26&gp=0.jpg")
    23. no-repeat center center;
    24. background-attachment: fixed; /*鼠标滚动背景不动*/
    25. }
    26. .tag3 {
    27. height: 200px;
    28. text-align: right;
    29. background-color: aquamarine;
    30. }
    31. .tag4 {
    32. height: 200px;
    33. text-align: right;
    34. background-color: steelblue;
    35. }
    36. </style>
    37. </head>
    38. <body>
    39. <div class="tag1">不知何人浅唱弄弦</div>
    40. <div class="tag2">我彷徨不可前</div>
    41. <div class="tag3">枕风宿雪多年</div>
    42. <div class="tag4">我与虎谋早餐</div>
    43. </body>
    44. </html>

    五、边框

    在这里插入图片描述

    简写:border: 2px dashed blue;

    还可以单独为某一个边框设置样式:

    在这里插入图片描述

    简写:border-left: 2px dotted green;

    1. <!DOCTYPE html>
    2. <html lang="zh-CN">
    3. <head>
    4. <meta http-equiv="content-Type" charset="UTF-8">
    5. <meta http-equiv="x-ua-compatible" content="IE=edge">
    6. <meta http-equiv="refresh" content="60; URL=https://blog.csdn.net/qq_41964425">
    7. <title>边框</title>
    8. <style>
    9. #tag1 {
    10. border-width: 3px; /*边框宽度*/
    11. border-style: dotted; /*边框类型*/
    12. border-color: cornflowerblue; /*边框颜色*/
    13. }
    14. #tag2 {
    15. border: 2px dashed mediumspringgreen; /*简写*/
    16. }
    17. /*单独为某个边框设置样式*/
    18. #tag3 {
    19. border-top-width: 2px;
    20. border-top-style: dotted;
    21. border-top-color: cornflowerblue;
    22. border-bottom-width: 2px;
    23. border-bottom-style: dashed;
    24. border-bottom-color: cornflowerblue;
    25. }
    26. /*单独为某个边框设置样式. 简写*/
    27. #tag4 {
    28. border-left: 2px dotted lightseagreen;
    29. border-right: 2px dotted lightseagreen;
    30. border-bottom: 2px solid mediumaquamarine;
    31. }
    32. </style>
    33. </head>
    34. <body>
    35. <div>
    36. <p id="tag1">拎着钓叟的鱼弦</p>
    37. <p id="tag2">问卧龙几两钱</p>
    38. <p id="tag3">蜀中大雨连绵</p>
    39. <p id="tag4">关外横尸遍野</p>
    40. </div>
    41. </body>
    42. </html>

    六、圆形 border-radius

    将其值设置为宽或高的一半即可得到一个圆形:

    1. <!DOCTYPE html>
    2. <html lang="zh-CN">
    3. <head>
    4. <meta http-equiv="content-Type" charset="UTF-8">
    5. <meta http-equiv="x-ua-compatible" content="IE=edge">
    6. <meta http-equiv="refresh" content="60; URL=https://blog.csdn.net/qq_41964425">
    7. <title>圆形</title>
    8. <style>
    9. #tag1 {
    10. text-align: center;
    11. width: 200px;
    12. border: 3px dotted darkviolet;
    13. border-radius: 50%; /*设置为宽或高的一半*/
    14. }
    15. #tag2 {
    16. text-align: center;
    17. width: 30px;
    18. height: 110px;
    19. border: 2px dashed hotpink;
    20. border-radius: 50%; /*设置为宽或高的一半*/
    21. }
    22. div {
    23. width: 150px;
    24. height: 150px;
    25. border: 2px solid lawngreen;
    26. border-radius: 50%; /*设置为宽或高的一半*/
    27. }
    28. </style>
    29. </head>
    30. <body>
    31. <div>
    32. <p id="tag1">你的笑像一条恶犬</p>
    33. <p id="tag2">撞乱我心弦</p>
    34. </div>
    35. </body>
    36. </html>

    七、display 属性

    描述
    display: none; 使元素在网页中不显示,一般用于配合JavaScript代码使用
    display: block; 默认占满整个页面宽度,如果指定了宽度,则会用margin填充剩下的部分
    display: inline; 按行内元素显示,此时再设置元素的width、height、margin-top、margin-bottom、float属性都不会有什么影响
    display: inline-block; 使元素同时具有行内元素和块级元素的特点
    1. <!DOCTYPE html>
    2. <html lang="zh-CN">
    3. <head>
    4. <meta http-equiv="content-Type" charset="UTF-8">
    5. <meta http-equiv="x-ua-compatible" content="IE=edge">
    6. <meta http-equiv="refresh" content="60; URL=https://blog.csdn.net/qq_41964425">
    7. <title>display属性</title>
    8. <style>
    9. #tag1 {
    10. display: block; /*占满整个页面宽度*/
    11. }
    12. #tag2 {
    13. display: inline; /*按行内元素显示*/
    14. height: 100px; /*此时无效*/
    15. }
    16. #tag3 {
    17. visibility: hidden; /*替换成空白*/
    18. }
    19. #tag4 {
    20. display: none; /*不显示*/
    21. }
    22. </style>
    23. </head>
    24. <body>
    25. <div>
    26. <span id="tag1">烽烟万里如衔</span>
    27. <span>掷群雄下酒宴</span> <!--此时换行-->
    28. <p id="tag2">谢绝策勋十二转</p> <!--此时不换行-->
    29. <p id="tag3">想为你窃玉簪</p> <!--此时不显示(替换成空白)-->
    30. <p>入巷间吃汤面</p>
    31. <p id="tag4">笑看窗边飞雪</p> <!--此时不显示-->
    32. </div>
    33. </body>
    34. </html>

    display: none;与visibility: hidden;的区别:

    visibity: hidden; :可以隐藏某个元素,但隐藏的元素仍会占用隐藏之前的空间。也就是说,虽然该元素被隐藏的,但是仍然会影响布局。

    display:none; :隐藏某个元素,且隐藏的元素不会占用任何空间。也就是说,该元素不但被隐藏了,而且该元素原本占用的空间也会从页面布局中消失。



    苦 才是生活
    累 才是工作
    变 才是命运
    忍 才是历练
    容 才是智慧
    静 才是修养
    舍 才会得到
    做 才会拥有

    "
  • 相关阅读:
    AcWing 157. 树形地铁系统 (hash判断树同构)打卡
    AcWing 156. 矩阵 (哈希二维转一维查询)打卡
    AcWing 144. 最长异或值路径 01字典树打卡
    AcWing 143. 最大异或对 01字典树打卡
    AcWing 142. 前缀统计 字典树打卡
    AcWing 139. 回文子串的最大长度 hash打卡
    AcWing 138. 兔子与兔子 hash打卡
    常用C库函数功能及用法
    编程实现C库函数
    C语言面试题5
  • 原文地址:https://www.cnblogs.com/zyk01/p/11375967.html
  • Copyright © 2011-2022 走看看