zoukankan      html  css  js  c++  java
  • Some css position box description

    1. padding:

    What would happen if you used either ems or percentages for the padding values?
    The two units have slightly different effects: the em unit scales the padding according
    to the size of the font of the content, while the percentage unit scales
    the padding (and margin) according to the width or height of the block that contains the element.

    <!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">
    <head>
        <title>Box Model Demo</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css">
            body
            {
                background-color: #808080;
                color: black;
            }
            h1, h4
            {
                background-color: #c0c0c0;
                color: black;
                padding: 10%;
            }
            
            .main-div 
            {
                 600px;
                height: 300px;
            }
        </style>
    </head>
    <body>
        <div class="main-div">
        
        <h1>
            MMMMMM</h1>
        <h4>
            MMMMMM</h4>
        </div>
    </body>
    </html>
    

    the above html fragment shows H1 and H4 has 10% padding, their parent container DIV's width is 600px so their padding will be 60px.

    If change the H1 H4 css style to  use em like

    h1, h4
            {
                background-color: #c0c0c0;
                color: black;
                padding: 1em;
            }
    

    then in IE browse the H1 padding will be 32px and h4 padding will be 16px.

    2. absolute

    The absolute position will calc by it's parent:

    <!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">
    <head>
        <title>Box Model Demo</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css">
            .big
            {
                font-family: Helvetica, Arial, sans-serif;
                font-size: 2em;
                font-weight: bold;
            }
        </style>
    </head>
    <body>
        <div style="position: absolute; left: 125px; top: 75px;" class="big">
            This is the first line of text being positioned.
            <div style="position: absolute; left: 25px; top: 30px;" class="big">
                This is a second line.
            </div>
        </div>
    </body>
    </html>
    

      

    3. relative

    Relative positioning is always based on the positioned element’s original position on the page.

    In other words, the positioning context of an element that uses relative positioning is provided by its default position.

    <!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">
    <head>
        <title>Box Model Demo</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css">
            .big
            {
                font-family: Helvetica, Arial, sans-serif;
                font-size: large;
                font-weight: bold;
            }
        </style>
    </head>
    <body>
        <div style="position: absolute; left: 125px; top: 75px;" class="big">
            This is the first line of text being positioned.
            <div style="position: absolute; left: 25px; top: 30px;">
                This is <span style="position: relative; left: 10px; top: 30px;">an example of</span>
                a second line.
            </div>
        </div>
    </body>
    </html>
    

      

  • 相关阅读:
    [扩展推荐] Laravel 中利用 GeoIP 获取用户地理位置信息
    10 个优质的 Laravel 扩展推荐
    5 个非常有用的 Laravel Blade 指令,你用过哪些?
    PHP 7.3 我们将迎来灵活的 heredoc 和 nowdoc 句法结构
    使用 Swoole 来加速你的 Laravel 应用
    一个成功的 Git 分支模型(适用于商业应用开发)
    github搜索语法
    python协程爬虫-aiohttp+aiomultiprocess使用
    python-协程、多线程、多进程性能比较
    functools模块-为函数预设args/kwargs参数
  • 原文地址:https://www.cnblogs.com/dragonstreak_1/p/2603014.html
Copyright © 2011-2022 走看看