CSS

CSS三种书写方式

外部样式
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>外部样式</title>
    <!--外部样式书写
    <link href="css/xxx.css" rel="stylesheet">

    css的书写:
    标签{
        xx:xx;
        xx:xx;
    }
    外部样式的原理,就是根据配置傻瓜式配置
    -->
    <link href="css/index.css" rel="stylesheet">
</head>
<body>
<div>这是一个容器标签</div>
<p>这是一个段落标签</p>
</body>
</html>
行内样式
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>行内样式</title>
</head>
<body>
<!--注意书写格式
 style = "xx:xx;xx:xx;"
-->
<div style="font-size: 30px ; color: black ; background-color: cadetblue;">这是一个容器标签</div>
<br/>
<p style="font-size: 20px;color: blue;background-color: gray">这是一个段落标签</p>
</body>
</html>
页内样式
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>页内样式</title>
    <!--页内样式的书写
    <style>
        标签{xx:xx;
            xx:xx;}
    <style>
    注意:font-size: 30px  要加px!!!

    遵守原则:就近原则;叠加原则;
    -->
    <style>
        div{
            color: black;
            background-color: gray;
        }
        div{
            color: white;
            background-color: blue;
            font-size: 30px;
        }
        p{
            color: blue;
            background-color: saddlebrown;
            font-size: 20px;
        }
    </style>
    <!--<link href="css/index.css" rel="stylesheet">-->
</head>
<body>
<div>这是容器标签</div>
<div>这是容器标签</div>
<div>这是容器标签</div>

<p>这是段落标签</p>
<p>这是段落标签</p>
<p>这是段落标签</p>
</body>
</html>

CSS选择器

前三个选择器比较常用

        1、标签选择器
        div{
            font-size: 30px;
            background-color: saddlebrown;
        }

        2、类选择器 
        .test{
            font-size: 25px;
            background-color: gray;
        }

        3、id选择器 只有一处能用,当有多处使用的时候就报错
        #myid{
            font-size: 20px;
            background-color: darkslategray;
        }

        4、并列选择器 逻辑或:满足一个条件就使用样式
        div,.test{
            font-size: 10px;
            background-color:darkred;
        }

        5、复合选择器 逻辑与:同时满足条件才可以
        div.test{
            font-size: 10px;
            background-color:darkred;
        }

        6、后代选择器 
        div p{
            background-color: darkred;
        }

        7、直接后台选择器
        div > p{
            background-color: green;
        }

        8、相邻兄弟选择器 
        div + p{
            background-color: gray;
        }

        9、属性选择器 
        div[name]{
            background-color: green;
        }

        10、、伪类选择器 当鼠标移动到上面的时候
        #myid:hover{
            background-color: gray;
        }

        11、伪元素选择器 
        div:first-letter{
            background-color: gray;
        }

CSS属性

        div{
            color: white;
            background:url("images/1.jpeg");
            /* no-repeat 设置不平铺
               cover:把背景图像扩展至足够大,以使背景图像完全覆盖背景区域。
                     背景图像的某些部分也许无法显示在背景定位区域中。*/
            background-size: cover;
            width: 200px;
            height: 200px;
            /*
              visibility 会隐藏内容,不会隐藏尺寸
              display 既隐藏内容,又隐藏尺寸
              */
            /*visibility: hidden;*/
            /*display: none;*/
            background-color: green;
            /*字体 */
            font-family: '宋体';
            /*字体加粗 */
            font-weight: bold;
            /*设置光标类型 */
            cursor: crosshair;
            /*加下划线 underline  none*/
            text-decoration: underline;
            /*text-decoration-color: red;*/
            /*首行缩进30%*/
            text-indent: 30%;

        }
        ul{
            /*指示点是方形*/
            list-style: square;
        }

        p{
            /*一定要注意:写数字就要加 px!!! */
            width: 100px;
            height: 50px;
            /*超出标签部分内容隐藏  auto */
            overflow: auto;
        }
可继承属性
    <!--可以继承的属性

    这个属性,所有标签可继承
    visibility、cursor

    这些属性,只有内联标签可继承
    letter-spacing、word-spacing、white-space、line-height、color、font、font-family、font-size、font-style、font-variant、font-weight、text-decoration、text-transform、direction

    这些属性,只有块级标签可继承
    text-indent、text-align

    这些属性,只有列表标签可继承
    list-style、list-style-type、list-style-position、list-style-image
不可继承属性
    display、margin、border、padding、background
    height、min-height、max-height、width、min-width、max-width
    overflow、position、left、right、top、bottom、z-index
    float、clear
    table-layout、vertical-align
    page-break-after、page-bread-before
    unicode-bidi
CSS3新增属性
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,845评论 1 92
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    wzhiq896阅读 1,821评论 0 2
  • 选择qi:是表达式 标签选择器 类选择器 属性选择器 继承属性: color,font,text-align,li...
    love2013阅读 2,350评论 0 11
  • 本文主要是起笔记的作用,内容来自慕课网. 认识CSS样式 CSS全称为“层叠样式表 (Cascading Styl...
    0o冻僵的企鹅o0阅读 2,676评论 0 30
  • 及笄之年 “逸哥哥,我要吃糖葫芦。” “女孩子不能吃太多。” “逸哥哥,我要嫁给你” “女孩子要矜持。” “逸哥哥...
    d5370a43f536阅读 252评论 0 0