css3(1)

之前的css属性选择器包括:类选择器,id选择器,标签选择器,关联选择器,组合选择器,伪类选择器等

css3属性选择器


        /*1、有class属性的input属性*/
        input[class] {
            background-color: red;
        }
        
        /*2、class属性是first的元素*/
        input[class=first] {
            background-color: blue;
        }
        
        /*3、class=first的元素*/
        [class=first] {
            background-color: green;
        }
        
        /*4、input的name属性值以first开头,^=是以什么开头*/
        input[name^=first] {
            background-color: yellow;
        }
        
        /*5、input的name属性值以name结尾,$=是以什么结尾*/
        input[name$=name] {
            background-color: lightgrey;
        }
        
        /*6、input的name属性值包含stna字符串的元素,*=是包含什么*/
        input[name*=stna] {
            background-color: pink;
        }

需要注意的就是:元素与后面[ ]之间,不要有空格,否则会失效

css3伪类选择器


css2中:
:hover, :link, :active, :visited

E:fisrt-child  E的父元素的第一个子元素
E:last-child  E的父元素的最后一个子元素
:root 
E:nth-child(n) E的父元素的第n个子元素
E:nth-last-child(n) E的父元素的倒数第n个子元素
E:empty 不包含任何内容的元素
E:enabled 匹配可用的元素
E:disabled 匹配不可用的元素
E:check 匹配选中的元素

css3伪对象选择器


:before:在盒子内部的前面插入一个行显示的盒子
:after:在盒子内部的后面插入一个行显示的黑子

以上2个都是inline类型,设置宽高生效的话,需要display:block;

       #shi {
            border: 1px solid red;
        }

        #shi:before {
            content: '锄禾日当午,';
            width: 150px;
            background-color: #f00;
            display: inline-block;
        }

        #shi:after {
            content: '谁知盘中餐,';
            width: 200px;
            background-color: #036;
            display: inline-block;
        }

注意:这个选择器必须和content一起使用,即使没有内容插入。

demo


Paste_Image.png
<!DOCTYPE html>
<html>
<head>
    <title>Bootstrap</title>
    <meta charset="utf-8">
    <mata http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <!-- <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"> -->
    <!--[if lt IE 9]>
      <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        #con {
            width: 300px;
            height: 30px;
            line-height: 30px;
            font-size: 12px;
            margin: auto;
            border: 1px solid lightgrey;
        }
        
        #con input {
            margin: 0px;
            padding: 0px;
            width: 210px;
            height: 30px;
            border: none;
        }

        #con:before {
            content: '';
            width: 24px;
            height: 24px;
            background: url(src/images/cone_24px_1185590_easyicon.net.png) no-repeat;
            display: inline-block;
            vertical-align: middle;
            margin: -2px 15px 0px 5px; 
        }

        #con:after {
            content: '';
            width: 24px;
            height: 24px;
            background: url(src/images/address_book_alt_21.013333333333px_1185558_easyicon.net.png) no-repeat;
            vertical-align: middle;
            display: inline-block;
            margin: -2px 5px 0 0;
        }
    </style>
</head>
<body style="padding:50px;background-color:#ccc">
  <div class="container" style="padding:30px;background-color:#fff;">
    <div id="con">
        <input type="text" value="搜索我的礼物">
    </div>
  </div>
</body>
</html>
<!-- <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script> -->
<script src="bootstrap/js/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、属性选择器:id选择器 # 通过id 来选择类名选择器 . 通过类名来选择属性选择器 ...
    Yuann阅读 5,570评论 0 7
  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 14,687评论 1 92
  • 之前学过的选择器 属性选择器 伪类选择器 结构选择器 结构伪类选择器 结构为类的的问题 empty target伪...
    Yuann阅读 3,199评论 0 0
  • 最近在看html基础,好吧,写点笔记,比较low见谅,反正我自己看懂就行了 CSS基础 1、css简介 casca...
    小龙是只猫阅读 3,682评论 0 1
  • 最近有一款席卷全国的游戏被网络和媒体舆论推到风口浪尖,它就是腾讯旗下的游戏产品王者荣耀。王者荣耀自上线一年以来,拥...
    cici爱读书阅读 9,941评论 0 1