html + css Quick Start Tutorial (5)

Exercise:

1. 2. Draw a box painting box 1 2 3 4 Jingdong Jingdong shopping features found good stuff 5. Jingdong play 3c

7.3 Positioning

By using the position property, we can choose between 3 different types of targeting, which affects the way the element box generated.

relative

The relative positioning of the reference position of its original, block element offset a certain distance. Element shape before their remains unlocated, the space it had occupied remains.

<html>
<head>
<style type="text/css">
h2.pos_left{
    position:relative;
    left:-20px
}
h2.pos_right{
    position:relative;
    left:20px
}
</style>
</head>

<body>
<h2>这是位于正常位置的标题</h2>
<h2 class="pos_left">这个标题相对于其正常位置向左移动</h2>
<h2 class="pos_right">这个标题相对于其正常位置向右移动</h2>
<p>相对定位会按照元素的原始位置对该元素进行移动。</p>
<p>样式 "left:-20px" 从元素的原始左侧位置减去 20 像素。</p>
<p>样式 "left:20px" 向元素的原始左侧位置增加 20 像素。</p>
</body>

</html>

absolute

Absolute positioning reference is positioning properties for the parent element, layer by layer to find out the positioning of reference until the body

<html>
<head>
<style type="text/css">
h2.pos_abs{
    position:absolute;
    left:100px;
    top:150px
}
</style>
</head>

<body>
<h2 class="pos_abs">这是带有绝对定位的标题</h2>
<p>通过绝对定位,元素可以放置到页面上的任何位置。
下面的标题距离页面左侧 100px,距离页面顶部 150px。</p>
</body>

</html>

fixed

Reference is fixedly positioned browser viewable area

<html>
<head>
<style type="text/css">
p.one{
    position:fixed;
    left:5px;
    top:5px;
}
p.two{
    position:fixed;
    top:30px;
    right:5px;
}
</style>
</head>
<body>

<p class="one">一些文本。</p>
<p class="two">更多的文本。</p>

</body>
</html>

Exercise:

1, fixedly positioned Jingdong 2, column 3 netease Europe multicast FIG Lun

8 other selectors

8.1 adjacent selector

Adjacent selector may select immediately following neighbors, Note: + Number Used to select adjacent connector

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <style>
           h1+div{
                width:100px;
                height:100px;
                background:blue;
        </style>
    </head>
    <body>
        <h1>css 样式测试</h1>
        <div id="div1"></div>
        <div id="box"></div>
    </body>
</html>

More than 8.2 element selector

When there are several elements common attributes, you can use multi-element selector Note: select multiple elements at the right time, separated by commas

<style>
    h1,h2,h3,h4,h5,h6,ol,ul,dl,dd,textarea,
form,input,select,body{margin:0;padding:0}
</style>

8.3 Descendant selectors

Descendant selectors acting on the parent element of all of the following sub-elements

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <style>
           #div1 p{
           /*
           把id为div1的下面的所有p元素的字体设置为红色,这里包括id为box的子元素p
           
           */
                color:red;
                
        </style>
    </head>
    <body>
        <h1>css 样式测试</h1>
        <div id="div1">
            <p>一江春水向东流</p>
            <p>飞流直下三千尺</p>
            <div id="box">
                  <p>床前明月光</p>
            </div>
        </div>
    </body>
</html>

8.4 subelements selector

Child element selected parent element acting on a child element, the selector and the selector progeny difference that the sub-element may act on selected descendant descendant elements, sub-elements and selectors can only act on its children

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <style>
           #div1>p{
           /*把id为div1的子元素p的字体设置为红色
           这里只包含子元素,不包含id为box下面的子元素
           */
                color:red;
                
        </style>
    </head>
    <body>
        <h1>css 样式测试</h1>
        <div id="div1">
            <p>一江春水向东流</p>
            <p>飞流直下三千尺</p>
            <div id="box">
                  <p>床前明月光</p>
            </div>
        </div>
    </body>
</html>

8.5 attribute selector

E [attr] att match all attributes having E elements, regardless of its value, for example: input [name], as long as the name attribute input element will be selected

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <style>
           input[name]{
              /*把带有name属性的input元素加上红色边框*/
              border:red solid 1px;
           }
        </style>
    </head>
    <body>
       <form>
            <input type="text" name="ipt1"/>
            <input type="text" name="ipt1"/>
            <input type="submit" value="提交" /> 
       </form>
    </body>
</html>

E [attr = val] is equal to match all attributes attr val E element input [id = ipt2] Usually attribute value without quotes

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <style>
           input[id=ipt2]{
              /*把id值为ipt2的input元素的边框设置成蓝色*/
              border:blue solid 1px;
           }
        </style>
    </head>
    <body>
       <form>
            <input type="text" name="ipt1" id='ipt1'/>
            <input type="text" name="ipt1" id='ipt2'/>
            <input type="submit" value="提交" /> 
       </form>
    </body>
</html>

E [attr ~ = val], "~" means comprise, as long as the property value includes the val E element will be selected

<!DOCTYPE html>
<html>
<head>
<style>
[title~=flower]{
    border:5px solid yellow;
}
</style>
</head>
<body>

<p>title 属性中包含单词 "flower" 的图片会获得黄色边框。</p>

<img src="/i/eg_tulip.jpg" title="tulip flower" />
<br />
<img src="/i/shanghai_lupu_bridge.jpg" title="lupu bridge" />

<p><b>注释:</b>对于 IE8 及更早版本的浏览器中的 [attribute~=value],
必须声明 <!DOCTYPE>。</p>

</body>
</html>

E [attr = ^ val], "^" at the beginning of a certain value, but as the property value will be selected to E element val at the beginning of

<!DOCTYPE html>
<html>
<head>
<style> 
div[class^="test"]{
    /*第三个div元素的背景会被设置成红色*/
    ckground:red;
}
</style>
</head>
<body>

<div class="first_test">第一个 div 元素。</div>
<div class="second">第二个 div 元素。</div>
<div class="test_three">第三个 div 元素。</div>
<p class="test">这是段落中的文本。</p>

</body>
</html>

E [attr = $ val], "$" at the end of some value, but as the property value will be selected to E element val at the beginning of

<!DOCTYPE html>
<html>
<head>
<style> 
div[class$="test"]{
    /*第一个div的背景会被设置成蓝色*/
    background:blue;
}
</style>
</head>
<body>

<div class="first_test">第一个 div 元素。</div>
<div class="second">第二个 div 元素。</div>
<div class="test_three">第三个 div 元素。</div>
<p class="test">这是段落中的文本。</p>

</body>
</html>

8.6 Pseudo-classes and pseudo elements

8.6.1 :after和:before

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            a:before{
                content: "点我";
            }
            a:after{
                content: "!!!";
            }
        </style>
    </head>
    <body>
        <a href="http://www.baidu.com">百度</a>
        <p>百度一下你就知道了!</p>
        <a href="http://nativejs.org">原生js社区</a>
    </body>
</html>

8.6.2 a state of four different tag

Unvisited links (link), put the mouse status (hover), visited links (visited), the currently active link (active).

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            a:link{
                color: red;
            }
            a:visited{
                color: blue;
            }
            a:hover{
                color: yellow;
            }
            a:active{
                color: green;
            }
        </style>
    </head>
    <body>
        <a href="http://nativejs.org">原生js</a>
         
    </body>
</html>

The above code, the elements of a use: before and: after pseudo selectors, selectors for use of such time, by setting the content to specify the content property value Yao inserted. This property is rather special, can only be used in conjunction with the pseudo-selectors. represents a prior inserted after the element content, before showing a inserted after the element content

Screw classroom video lessons Address: http://edu.nodeing.com

Guess you like

Origin www.cnblogs.com/dadifeihong/p/12023989.html