CSS定位、浮动、选择器

index01

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>定位</title>
    <link href="style.css" type="text/css" rel="stylesheet">
    <style>
        [title]{
            color: forestgreen;
        }
        a[href="http://www.baidu.com"]{
            color: crimson;
            font-size: 30px;
        }
        [style1 ~=sty]{  /* 在确定通过部分属性值来确定时,此处要加一个~,否则无法被加载*/
            color: chartreuse;
            font-size: 25px;
        }
    </style>
</head>
<body>
    <div id="position1"></div>
    <div id="position2"></div>
    <div id="position3"></div>
    <script>
        for(var i =0;i<30;i++){
            document.write(i+"<br/>");
        }
    </script>
    <h3>CSS浮动</h3>
    <div id="container">
    <div id="fd"></div>
    <div id="sd"></div>
    <div id="td"></div>
        <div id="text">Hello HTML!Hello World!</div>
    </div>
    <br/>
<h3>CSS浮动应用</h3>
    <div id="div1">
        <ul>
            <li ><img src="image/1.jpg" width="400px" height="400px"></li>
            <li ><img src="image/2.jpg" width="400px" height="400px"></li>
            <li ><img src="image/3.jpg" width="400px" height="400px"></li>
        </ul>
        <ul>
            <li ><img src="image/4.jpg" width="400px" height="400px"></li>
            <li ><img src="image/5.jpg" width="400px" height="400px"></li>
            <li ><img src="image/6.jpg" width="400px" height="400px"></li>
        </ul>
        <ul>
            <li><img src="image/7.jpg" width="400px" height="400px"></li>
            <li><img src="image/8.jpg" width="400px" height="400px" ></li>
            <li><img src="image/9.jpg" width="400px" height="400px"> </li>
        </ul>
    </div>
    <br/>
    <br/>
<h3>选择器</h3>
<div>
    <div id="did">id只可以使用一次,id选择器不能结合使用,当使用js的时候,需要用到id</div>
    <div class="did">class可以多次使用</div>
    <div class="did">class可以多次使用</div>
    <div class="did">class可以多次使用</div>
</div>
<p title="tt">最简单的属性选择器</p>
<a href="http://www.baidu.com">根据具体的属性值来选择效果</a>
<a href="http://www.bafgfdgsdgfd.com">不匹配的属性值效果不会被加载</a>
<p style1="sty">属性与属性值必须匹配,否则无法显示</p>
    <p style1="ssty">属性与属性值必须匹配,否则无法显示</p>
<p style1="sty hello">根据部分属性值来确定,包含属性值的可以被加载</p>
    <p style1="st hello">不包含属性值的不能被加载</p>
<p>后代选择器<strong>可以指定谁被加载</strong>的效果</p>
<h4>子元素选择器用法为<strong>元素1 > 元素2</strong></h4>
<a href="http://m.blog.csdn.net/u012110719/article/details/41171517">子元素选择器与后代元素选择器区别,详情见网页</a>
<br/>
    <ul>相邻兄弟选择器:必须要有相同的父级元素
    <li>泰国</li>
    <li>新加坡</li>
    <li>印度尼西亚</li>
</ul>
</body>
</html>

style.css
#position1{
    height: 100px;
    width: 100px;
    background-color: lightblue;
    position: absolute;
    top: 40px;
    left: 30px;
    z-index: 3;
}
#position2{
    height: 100px;
    width: 100px;
    background-color: blueviolet;
    position: absolute;
    top: 50px;
    left: 40px;
    z-index: 1;
}
#position3{
    height: 100px;
    width: 100px;
    background-color: palegreen;
    position: absolute;
    top: 60px;
    left: 50px;
    z-index: 2;
}

/*CSS浮动*/
#fd{
    width: 100px;
    height: 150px;
    background-color: chartreuse;
    float: left;
}
#sd{
    width: 150px;
    height: 100px;
    background-color: aqua;
    float: left;
}
#td{
    width: 100px;
    height: 100px;
    background-color: blueviolet;
    float: left;
}
#container{
    width: 300px;
    height: 400px;
    background-color: darkgray;
}
#text{
    clear: left;  /* 文字清除浮动效果*/
}
/*CSS定位-浮动的应用*/
*{
    margin: 0px;
    padding: 0px;
}
li{
    list-style: none;
}
#div1{
    width: 1500px;
    height: auto;
    margin: 20px auto;
}
ul{
    width: 500px;
    float: left;
}
/*选择器*/
#did{
    color: blue;
    font-size: 20px;
}
.did{
    color: crimson;
    font-size: 20px;
}
/*后代选择器*/
p strong{
    color: lightgreen;
    font-size: 30px;
}
/* 子元素选择器*/
h4 > strong{
    color: springgreen;
    font-size: 30px;
}
/*相邻兄弟选择器*/
li+li{
    color: aquamarine;
    font-size: 25px;
}
部分截图

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值