css如何让元素块根据自身向下,向右同时移动50px?

html-css013

css如何让元素块根据自身向下,向右同时移动50px?,第1张

① 可以使用“相对定位”,position:relative;

② 注意坐标轴的移动方向:

向左移动:当然是正数->left:50px

向下移动:当然是正数->top:50px;

(这样记:既然要向下移动,当然是要远离top顶部了,自然top的属性值要正数

既然要向右移动,就是远离左边了,left属性值自然要为正数!!!)

方案一:

div{margin:50pc 0 0 50pc}

方案二:

div{

position: relative

top: 50pc

left: 50pc

}

方案三:

div{

transform: translate(50pc,50pc)

}

1 方法:

①设置div1的margin-top的值为 (div的height-div1的height)/2

②设置div1的display值为 inline-block

2 代码

<html>

<head>

    <title></title>

    <style type="text/css">

        div {

            width: 700px

            height: 100px

            background-color: #93C

        }

        #div1 {

            width: 700px

            height: 40px

            background-color: #06F

            margin-top: 30px

            display: inline-block

        }

    </style>

</head>

<body>

    <div>

        <div id="div1">div1</div>

    </div>

</body>

</html>

3 显示效果如下