CSS基础复习(续)

旧城等待, 2022-09-25 15:15 387阅读 0赞

border 与box 边线,盒子模型


border属性:用来设置元素的边框

(块级元素有边线)

四边设置

border:width值 style值 color值;

单边设置

border-left:width

p,段落也是块级

四边设置 border

p{ border:1px solid #CCC;}

border 加冒号多粗,然后空格 虚线还是实线 实线是 solid ,然后空格颜色。

单边设置border

有些时候标题会加上边框,左边是一个比较宽的边,然后下面是一个比较窄的边框。。

h1{

border-left:15px solid #999;

border-bottom:2px solid #999;

}

就在标题的左面加了一个框框,因为很粗是5px的,所以像一个实心的块块,在左面

然后下面是一个2px厚的线。

也就是说,不是直接进行四边设置,而是单独的对某一边进行设置。

RGB 调颜色,每一个都是从0-255的

rgb(10,20,30 ) 就代表一个颜色 用10进制表示

rgb( 20%,30%,50% ) 用百分比表示

每一位用16进制表示 十六进制表示

以#号开头,前两位 红色,中间两位绿色,后两位蓝色

背景色

background-color

背景图片

background-image:url(‘ ’);

#qwe{color:#F00;background-image:url(1.png);}

默认情况下,背景图片在水平和垂直方向上重复出现,创建一种 墙纸的效果。

background-repeat 属性可以控制背景图片的平铺效果

取值:

repeat: 在垂直方向和水平方向重复,为重复值

repeat-x : 仅在水平方向重复

repeat-y:仅在垂直方向重复

no-repeat: 仅显示一次

background-position 属性用于改变背景图片在元素中的位置。

background-position:center; 图片居中

默认情况下,背景图片会随着页面的滚动而移动。

可以通过background-aattachment属性改变此特征

默认值是scroll :背景会随着文档滚动。

可取值为fixed :背景图像固定,并不会随着页面的其余部分滚动,长用于实现水印的图像。

例如:

body{ background-attachment:fixed; }

这个背景图片就不会随着滚动条滚动了。

这个是让背景图片铺满整个屏幕。

background-size:100%;

文本格式化

指定字体:

font-family:value1,value2;

body{font-family:’微软雅黑’,’文泉驿正黑’,’黑体’;

}

字体大小:

font-size:value;

font-sizze:50px

字体加粗:

font-weight

font-weight:bold

控制文本格式:

文本颜色

color:value;

文本排列

text-aligin left/right/center;

文本修饰

text-decoration:none/underline;

行高

line-height:value(1.6em);

首行文本缩进

text-indent:value(2em);

例子:

text-align:center; 居中。

text-decoration:underline; 效果等同 也是有个下划线。

text-indent:2em; 首行缩进2个文本。

line-height:1.6em; 设置行高为1.6.

默认文字在段落居中,设置文本的行高与p一样高。

设置了段落的height为50px;那么设置行高等于段落的高就会让段落中的文字垂直居中。

p{

height:50px;

line-height:50px;

}

例子:设置一个超链接,点击和没点击都是白色的

666的python,华山杯,写writeup

p a:link{color:#fff;}

p a:visited{color:#fff;}

去掉下划线:

text-decoration:none;

使文本居右

text-align:right;

设置内边距

padding-right:40px;

外边距:

margin-right:40px;

在div中居中,设置行高等于div的高。

去掉外边距:


margin:0;

表格样式

表格同样可以使用box模型,可以设置边框,内边距,宽高,以及文本格式属性。

合并相邻的边框

如果设置了单元格的边框,相邻单元格的边框会单独显示,类似双线边框。

Center

border-collapse属性:合并相邻的边框

设置是否将表格边框合并为单一边框。

border-collapse:separate/collapse;

Center 1

实例:

代码:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>表格样式</title>
  6. <style type="text/css">
  7. #t1{
  8. width:200px;
  9. border:1px solid #F00;
  10. padding:10px;
  11. margin:30px auto;
  12. }
  13. #t1 td{
  14. border:1px solid #000;
  15. padding:10px;
  16. text-align:center;
  17. }
  18. #t2{
  19. width:910px;
  20. border:1px solid #0;
  21. border-collapse:collapse;
  22. }
  23. #t2 thead th{
  24. border:1px solid #ccc;
  25. height:40px;
  26. text-height:40px;
  27. background-color:#fbedce;
  28. }
  29. #t2 tbody td{
  30. border:1px solid #ccc;
  31. width:32px;
  32. text-height:32px;
  33. text-align:center;
  34. }
  35. #t2 tbody tr:hover{
  36. background-color:#f7f9fd;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <table id="t2">
  42. <tr>
  43. <td>aa</td>
  44. <td>bb</td>
  45. </tr>
  46. <tr>
  47. <td>cc</td>
  48. <td>dd</td>
  49. </tr>
  50. </table>
  51. <div>
  52. <table id="t2">
  53. <thead>
  54. <tr>
  55. <th><input type="checkbox" id="all"/><label for="all">全选</label></th>
  56. <th>序号</th>
  57. <th>角色</th>
  58. <th>职业</th>
  59. <th>
  60. 操作
  61. </th>
  62. </tr>
  63. </thead>
  64. <tbody>
  65. <tr>
  66. <td><input type="checkbox"/></td>
  67. <td>1</td>
  68. <td>唐僧</td>
  69. <td>法师</td>
  70. <td>
  71. <input type="button" value="删除" class="shanchu"/>
  72. <input type="button" value="修改" class="xiugai"/>
  73. </td>
  74. </tr>
  75. <tr>
  76. <td><input type="checkbox"/></td>
  77. <td>2</td>
  78. <td>猪八戒</td>
  79. <td>战士</td>
  80. <td>
  81. <input type="button" value="删除" class="shanchu"/>
  82. <input type="button" value="修改" class="xiugai"/>
  83. </td>
  84. </tr>
  85. <tr>
  86. <td><input type="checkbox"/></td>
  87. <td>3</td>
  88. <td>孙悟空</td>
  89. <td>战士</td>
  90. <td>
  91. <input type="button" value="删除" class="shanchu"/>
  92. <input type="button" value="修改" class="xiugai"/>
  93. </td>
  94. </tr>
  95. <tr>
  96. <td><input type="checkbox"/></td>
  97. <td>3</td>
  98. <td>沙僧</td>
  99. <td>NPC</td>
  100. <td>
  101. <input type="button" value="删除" class="shanchu"/>
  102. <input type="button" value="修改" class="xiugai"/>
  103. </td>
  104. </tr>
  105. </tbody>
  106. </table>
  107. </div>
  108. </body>
  109. </html>

Center 2

发表评论

表情:
评论列表 (有 0 条评论,387人围观)

还没有评论,来说两句吧...

相关阅读

    相关 css复习

    3.10选择器总结 除了内联样式(用style属性描写的),对于样式的描述格式有     样式的描述包括两部分:即选择器和样式内容 样式内容:是键值对的形式描述样式的