zoukankan      html  css  js  c++  java
  • css定位

    文档流

    所谓的文档流,指的是元素排版布局过程中,元素会自动从左往右,从上往下的流式排列。并最终窗体自上而下分成一行行, 并在每行中按从左至右的顺序排放元素。脱离文档流即是元素打乱了这个排列,或是从排版中拿走。

    当前所知的脱离文档流的方式有两种:浮动和定位。

    css定位机制

    普通流、浮动、绝对定位

    css position属性

    static:position默认值,保持文档流。

    relative:相对本身的原始位置发生位移且保持文档流,占空间。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
    <head>
    <title>相对定位</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="ouym" />
    </head>
        <body>
            <div style=" 100px; height: 100px; background-color:#00ff00;"> div1</div>
            <div style=" 100px; height: 100px; background-color:#00ffff;position:relative;left:20px;top:-20px;"> div2</div>
            <div style=" 100px; height: 100px; background-color:#ffff00;"> div3</div>
    
        </body>
    </html>

    效果如下:

    absolute:脱离文档流,不占空间且相对于其包含块来定位(相对最近的非static块定位)。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
    <head>
    <title>新建网页</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="ouym" />
    </head>
        <body>
            <div style=" 100px; height: 100px; background-color:#00ff00;"> div1</div>
            <div style=" 100px; height: 100px; background-color:#00ffff;position:absolute;left:20px;top:20px;"> div2</div>
            <div style=" 100px; height: 100px; background-color:#ffff00;"> div3</div>
    
        </body>
    </html>

    效果如下:

    fixed:总是以body为定位时的对象,总是根据浏览器的窗口来进行元素的定位,一般页面上飘来飘去的,或者浮动在顶部或右下角的小模块都是用的fixed,脱离文档流。

    浮动float

    脱离文档流,不占空间。虽然普通块元素可以忽视浮动块,但是块元素中的文本不会,文本会围绕浮动块。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
    <head>
    <title>浮动</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="ouym" />
    </head>
        <body>
            <div style=" 100px; height: 100px; background-color:#00ff00;"> div1</div>
            <div style=" 100px; height: 100px; background-color:#00ffff;float:left;"> div2</div>
            <div style=" 100px; height: 110px; background-color:#ffff00;"> div3</div>
    
        </body>
    </html>

    运行效果:

    div2覆盖了div3的部分,但是把div3的文本挤下来了。clear可以清除浮动

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
    <head>
    <title>清除浮动</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="ouym" />
    </head>
        <body>
            <div style=" 100px; height: 100px; background-color:#00ff00;"> div1</div>
            <div style=" 100px; height: 100px; background-color:#00ffff;float:left;"> div2</div>
            <div style=" 100px; height: 110px; background-color:#ffff00;clear:both;"> div3</div>
    
        </body>
    </html>

  • 相关阅读:
    Selenium3+python3自动化(三十九)--python3.7上SendKeys报错用PyUserInput取代
    Selenium3+python3自动化(三十八)--异常后截图(screnshot)、只截某个元素的图
    python学习6--python读取excel数据
    Selenium3+python3自动化(三十七)--捕获异常(NoSuchElementException)、try...except
    Selenium3+python3自动化(三十六)--expected_conditions模块 判断文本(text_to_be_present_in_element)
    Selenium3+python3自动化(三十五)--登录方法(参数化)
    Selenium3+python3自动化(三十四)--expected_conditions模块 判断弹出框存在(alert_is_present)
    Selenium3+python3自动化(三十三)--万能的js解决click()、clear()失效问题
    Selenium3+python3自动化(三十二)--4类32种定位方法(find_element_by_xx, find_elements_by_xx, find_element)
    Selenium3+python3自动化(三十一)--元素定位参数化(find_element)
  • 原文地址:https://www.cnblogs.com/ouym/p/6250636.html
Copyright © 2011-2022 走看看