HTML CSS 層疊樣式表 四

來源:互聯網
上載者:User

標籤:頁面   padding   分享   適合   containe   定位   響應   技術   固定   

一、頁面配置:div+css布局

1.<style >

  *{

    margin:0px;

    padding:0px;

  }

  #ad{

    width:100px;

    height:100px;

    background-color:red;

    position:fixed;       定位:固定定位,需要設定距離邊框的距離;相對於瀏覽器視窗位置固定

    right:0px;

    top:100px;

  }

  .class{

    float:left;     流式布局:從左往右。right從右往左。如果有序號,也會從右往左排。

    position:relative;    定位:相對定位,相對於周邊其他元素的定位;預設,一般不寫,需要設定z-index分層時必須寫。

  }

  .class2{

    min-width:500px;  給流式布局設定一個外框寬度設定成百分比,然後給這個外框一個最小寬度,可以防止流式布局的元素髮生換行。一般用於響應式布局,以適合不同的瀏覽器和裝置。

  }

  .class3{

    position:absolute;     定位:絕對位置;需要制定靠著誰,如果外層元素未定位會相對於瀏覽器定位。

    right:0px;

    bottom:0px;

    z-index:-1;    z軸定位,需要跟隨定位

  }

</style>

<div>

  <div style="clear:both;"></div>

</div>

  利用清除浮動屬性將上層div撐開,有多高的元素上層div就多高;

二、課上練習

<style>        * {            margin:0px;  /*去掉所有元素的內外邊框*/            padding:0px;        }        #ad {            width:100px;                    height:100px;            background-color:red;               position:fixed;    /*絕對位置  以瀏覽器視窗作為基準*/            right:0px;                /*離右側0*/            top:100px;              /*離上側100*/        }        .item {            width:100px;            height:100px;            margin-right:10px;            color:blueviolet;            border:2px solid red;  /*邊框 2像素寬 實線 紅色*/            float:right;  /*流式布局 letf從左往右  right為從右往左*/            position:relative;  /*相對定位 相對於周邊其他元素*/        }        .container {            width:50%;            min-width:456px;            /*height:500px;*/            border:3px solid black;            position:relative;            z-index:10;  /*Z軸定位 用於確定上下層關係 可以有負數 建議值10 20 30 方便後期改動*/         }        .sup {            width:100px;            height:100px;            border:2px solid blue;            position:absolute;            right:0px;            top:0px;            background-color:darkcyan;            z-index:-1;        }    </style>
<body>    <div id="ad"></div>    <div class="container">            <div class="item">1</div>        <div class="item">2</div>        <div class="item">3</div>        <div class="item">4</div>        <div class="sup"></div>        <div style="clear:both"></div>  <!--外部DIV不需要設定寬度,有多少內容就放多大-->    </div>    <p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p>    <p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p>    <p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p>    <p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p>    <p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p><p>甲乙丙</p>    </body>

 

三、網頁

 

HTML CSS 層疊樣式表 四

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.