• <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>

    用css怎樣使div相對整個頁面居中

    新建一個html文件,定名為test.html,用于講解用css如何使div相對整個頁面居中。

  • 2

    在test.html文件中,建立一個div,并設置其class屬性為dcenter,本家兒要用于下面進行css樣式設置。

  • 3

    在test.html文件中,初始化頁面所有元素的css樣式 ,設置表里邊距都為0px。

  • 4

    在css樣式中,對類名為dcenter的div進行樣式設置。設置div的寬高為200px,布景顏色為紅色。

  • 5

    設置div的位置屬性為絕對定位(position: absolute),距離頁面左邊緣為50%,距離頁面上邊緣為50%。

  • 6

    經由過程上面的css樣式設置,只是實現了div左上角的點在頁面居中,若想整個div居中,還需要經由過程transform設置div的程度和垂直位置的偏移量為-50%。

  • 7

    在瀏覽器打開test.html文件,查看div在整個頁面居中的結果。

    • 發表于 2019-09-19 17:00
    • 閱讀 ( 1833 )
    • 分類:其他類型

    你可能感興趣的文章

    相關問題

    0 條評論

    請先 登錄 后評論
    admin
    admin

    0 篇文章

    作家榜 ?

    1. xiaonan123 189 文章
    2. 湯依妹兒 97 文章
    3. luogf229 46 文章
    4. jy02406749 45 文章
    5. 小凡 34 文章
    6. Daisy萌 32 文章
    7. 我的QQ3117863681 24 文章
    8. 華志健 23 文章

    聯系我們:uytrv@hotmail.com 問答工具
  • <noscript id="ecgc0"><kbd id="ecgc0"></kbd></noscript>
    <menu id="ecgc0"></menu>
  • <tt id="ecgc0"></tt>
    久久久久精品国产麻豆