老司机Studio 第二章

2017-07-30  本文已影响67人  cenkai88

CSS3的基本特性

<!DOCTYPE html>
<html lang="en">
<head>   
 <meta charset="UTF-8">
    <title>使用CSS3基本选择器</title>
    <style type="text/css"> 
       *{margin:0;  padding: 0;}       
       .clearfix:after,.clearfix:before{display: table;content:""}        
       .clearfix:after{clear: both;overflow: hidden}       
       .demo{width: 250px;border: 1px solid #cccccc;padding: 10px;margin: 20px auto;} 
       li{list-style: none outside none;  float: left;  height: 20px; 
        line-height: 20px;width: 20px;border-radius: 10px; 
        text-align: center;background: #f36;  color: white; margin-right: 5px;}  
     </style>
</head>
<body>
  <ul class="clearfix demo"> 
    <li class="first" id="first">1</li>
    <li class="active">2</li>   
    <li class="important item">2</li>   
    <li class="important">4</li>   
    <li class="item">5</li>  
    <li>6</li>  
    <li>7</li>  
    <li>8</li> 
    <li>9</li> 
    <li class="last" id="last">10</li>
 </ul>
</body>
</html>
通配.png 元素.png id选择器 类选择器 多类名选择器
<!DOCTYPE html>
<html lang="en">
<head>   
<meta charset="UTF-8">  
  <title>使用CSS3层次选择器</title> 
   <style type="text/css">  
     *{margin: 0;padding: 0; }    
    body{width: 300px; margin: 0 auto;}     
    div{margin:5px;padding:5px;border: 1px solid #ccc;}   
 </style>
</head>
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4
      <div>5</div>
       <div>6</div>
</div>
<div>7   
       <div>8  
             <div>10</div>  
       </div>
</div>
</body>
</html>
后代.png 子.png 相邻兄弟.png 通用兄弟.png
.div1 {
    width:200px;
    height:200px;
    border:2px red solid;
    position:absolute;
    left:100px;
    top:50px;
}
<div id="div1"></div>
<div>
  <div style="float: right">test</div>
</div>
<div>test1</div>

作业:仿制百度搜索结果页面

:focus 元素成为焦点(表单)

<div class="demo clearfix">
  <ul class="clearfix">
    <li class="first links odd" id="first"><a href="">1</a></li>
    <li class="links even"><a href="">2</a></li>
    <li class="links odd"><a href="">3</a></li>
    <li class="links even"><a href="">4</a></li>
    <li class="links odd"><a href="">5</a></li>
    <li class="links even"><a href="">6</a></li>
    <li class="links odd"><a href="">7</a></li>
    <li class="links even"><a href="">8</a></li>
    <li class="links odd"><a href="">9</a></li>
    <li class="links even last" id="last"><a href="">10</a></li>
  </ul>
</div>

.demo { 
width: 300px;
border: 1px solid #ccc; 
padding: 10px; 
}
.demo li { 
border: 1px solid #ccc; 
padding: 2px; 
float: left; 
margin-right:4px; 
} 
.demo a { 
float: left; 
display: block; 
height: 20px; 
line-height: 20px; 
width: 20px; 
border-radius: 10px; 
text-align: center; 
background: #f36; 
color: green; 
text-decoration: none; 
}
选择器

:first-child选择某个元素的第一个子元素;
:last-child选择某个元素的最后一个子元素;
:nth-child()选择某个元素的一个或多个特定的子元素;
:nth-last-child() 从后选择元素某个元素

<p class="box">Other content.</p>

p.box {
  width: 300px;
  border: solid 1px white;
  padding: 20px;
}
 
p.box:before {
  content: "#";
  border: solid 1px white;
  padding: 2px;
  margin: 0 10px 0 0;
}
上一篇 下一篇

猜你喜欢

热点阅读