Fe-6 CSS

Fe-6-1

  • 三种引入CSS
  1. 内联(inline style attribute)
<h1 style='background:red;'>内联(inline style attribute)</h1>
  1. <head> 标签内的 <style> 标签
    <style>
            h1 {
                background: blue !important;
            }

        </style>
  1. <link> 标签中的外联
<link rel="stylesheet" href="fe6.css">

样式优先级(从高到低)
!important
内联样式
<style> 中的样式
link 中的样式

  • 三种选择器
  1. ID
  2. 元素
.green {
                background: green;
                /*color: white;*/
            }
            h1 {
                background: yellow !important;
                color: red;
            }
            #id-button-test {
                background: lightblue;
            }

选择器优先级(从高到低)
!important
内联样式
id 选择器
class 选择器
元素选择器


display 属性

  • block
    默认 block 的标签有
    div p ul ol li h1 h2 h3 h4 h5 h6

  • inline
    inline 只占 content 的尺寸

  • inline-block
    inline-block 是 inline 布局 block 模式
    inline-block 对外表现为 inline,所以可以和别的 inline 放在一行
    对内表现为 block,所以可以设置自身的宽高

  • 盒模型, inline 元素没有盒模型
    内容
    padding 盒子里距离
    border 盒子
    margin 盒子外


Fe-6-2
  • position 属性用于元素定位
    static
    relative
    absolute
    fixed

非 static 元素可以用 top left bottom right 属性来设置坐标
非 static 元素可以用 z-index 属性来设置显示层次

  • relative 是相对定位 只改变自己的位置,对页面没用影响
微信截图_20180106112720.png
  • absolute 完全绝对定位, 忽略其他所有东西
    往上浮动到 非 static 的元素
    就是什么子绝父绝,子绝父相

这里给了class选择器这个盒子相对定位,否则X会上浮到 非static的元素右上角


微信截图_20180106113254.png
  • fixed 基于 window 的绝对定位, 不随页面滚动改变
    一些浮动小广告

  • 后写的会盖住先写的内容
    可以设置谁厚度z-index:100 显示在上面,默认是0

  • overflow属性
    visible 默认
    auto 需要的时候加滚动条
    hidden 隐藏多余元素
    scroll 就算用不着也会强制加滚动条

微信截图_20180106114024.png
  1. 如果设置overflow;hidden;溢出的部分就会隐藏
微信截图_20180106114130.png
  1. auto是加滚动条

盒模型相关的 CSS

border
border-width
border-style
border-color
3 个属性可以简写为一句
border: 3px red solid;

微信截图_20180106114632.png
border-top
    border-top-width
    border-top-style
    border-top-color

border-right
    border-right-width
    border-right-style
    border-right-color

border-bottom
    border-bottom-width
    border-bottom-style
    border-bottom-color

border-left
    border-left-width
    border-left-style
    border-left-color
margin
    margin-top
    margin-right
    margin-bottom
    margin-left

padding
    padding-top
    padding-right
    padding-bottom
    padding-left

三种缩写, 分别对应有 4 2 3 个值的时候的解释, padding 同理
margin: top right bottom left
margin: (top/bottom) (right/left)
margin: top (right/left) bottom

  • border-radius 是用来设置圆角度数的
    px是半径
    它也拥有三种缩写, 对应的含义如下
    左上角为 top, 右下角为 bottom

background 相关属性和缩写
background-color: #233;
background-image: url(bg.png);
background-repeat: no-repeat;
background-attachment: fixed; /* 背景图片随滚动轴的移动方式 */
简写如下
background: #233 url(bg.png) no-repeat;

查询属性兼容网站
Caniuse

https://caniuse.com/

居中写法

  • 上下0,左右auto
    block 元素居中
margin: 0 auto;

inline inline-block 元素居中

text-align: center;
  • text-decoration:
    underline
    overline
    line-through
    blink(这个值已经废弃了)

链接下划线就是这个属性的underline


微信截图_20180106121048.png
margin 合并 特例
  • 上下margin
微信截图_20180106121613.png
outline
  • 基本和border一样,可是不改变盒子大小。可以设置这个属性看盒子大小。
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,796评论 1 92
  • 学会使用CSS选择器熟记CSS样式和外观属性熟练掌握CSS各种选择器熟练掌握CSS各种选择器熟练掌握CSS三种显示...
    七彩小鹿阅读 6,334评论 2 66
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 27,670评论 1 45
  • 不知不觉,来简书三个月了。 最初只是把简书当成学习的地方,偶尔写字画画的时候打个卡。 开始的时候,写上一个标题,帖...
    梦归秦淮_马乔阅读 1,292评论 113 57
  • 被狂风凌虐过的落叶散落一地,毫无生机,死气沉沉。它们如一片乱葬岗上无处安放的尸体,我踩在上面,负罪感深重。我生自凡...
    杯酒言欢欢欢阅读 326评论 0 0