Chapter7 CSS入门

ex:
p{background-color:red; #backgorund color border:1px solid gray;} # boder
This code can modify all the P elements.


《CSS Pocket Reference 》


add <style type=text/css>&</style> in <head>

p{color:maroon;} # font-color


h1{font-family:sans-serif;color:gray;}+
h2{font-family:sans-serif;color:gray;}
=h1,h2{ #selector font-family:sans-serif; #font package color:gray; }


修改整个网站的CSS

  1. 提取A.html文件的规则,保存为A.css
  2. 从A.html创建到达这个文件的链接
  3. 在其他文件重复步骤2
  4. 测试所有文件

PS:

  1. 步骤1中不要复制<style>标记
  2. revise A.html.
    delete <style>,add<link>
    <link rel="stylesheet" type="text/css" href="../lounge.css">
    type:defalt(no need in HTML5)
    rel:define the relation between the files
    href:link to the CSS file

tips:

  • style will effect all the son-elements
  • style in son-element will cover father-element's style

annotation in CSS
/*this is a annotation*/


class

  1. add attribute class to the elements that belong to a group.ex:<p class=green>
  2. add a class selector as p.green{}
  3. if class contain several elements ,and you want modify all the class's style,then can write as .green{}
  4. one element can have several classes
    write as<p class="green red yellow"

应用样式的规则

  • 若无选择器选择元素时,查找父元素。
  • 若父元素依然无,则使用浏览器默认值。
  • 若多个选择器选择同一元素,比较哪个选择器更特定。
    父元素<子元素<.green<p.green
  • 当p.green与p.red冲突时,选择CSS文件靠后的规则

可以在这个W3C的官方网站验证CSS文件


属性

color:颜色
font-weight:文本粗细
left:制定元素最左边所在的位置
top:控制元素最顶端的位置
line-height:文本的行间距
text-align:设置文本的对齐方式(左对齐、右对齐、居中)
letter-spacing:设置字母间的间距
background-color:控制元素的背景色
font-style:设置斜体字
border:元素周围的边框
list-style:改变列表项的外观
padding:控制元素边缘及其边框的空间(内边框)
font-size:字体大小
background-image:在某元素后放置图像


warning!

void元素<img> <a>无继承性

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • FreeCodeCamp - HTML5 and CSS 发现原来在另外一台电脑学 FreeCodeCamp 的时...
    付林恒阅读 9,453评论 2 17
  • 学习CSS的最佳网站没有之一 http://www.w3school.com.cn/tags/index.asp ...
    Amyyy_阅读 1,100评论 0 1
  • 本文为阅读《Head First HTML 与 CSS》的css部分的读书笔记,方便回顾书上的知识,另一篇为Hea...
    兼续阅读 1,863评论 0 17
  • 童话的结局往往都是,王子和公主从此过上了幸福地生活。 似乎王子和公主经历了前半生的奋斗与艰辛,便可以幸福一生。 但...
    妈妈向上UP阅读 193评论 0 1
  • 清晨的雾伏在玻璃窗上 煎蛋泣血 流出酸楚的黄
    大野川阅读 147评论 0 0