向上传递案例:
<style>
.box {
height: 400px;
width: 800px;
background-color: red;
}
.box .item {
height: 200px;
width: 300px;
background-color: green;
margin-top: 100px;
}
style>
<body>
<div class="box">
<div class="item">
<p>123p>
div>
div>
body>
向下传递案例:
<style>
.box1 {
width: 300px;
/*
height: 300px;
高度不设置的,默认为auto
*/
background-color: #00f;
}
.item1 {
width: 200px;
height: 250px;
background-color: #0ff;
margin-bottom: 200px;
}
style>
<body>
<div class="box1">
<div class="item1">div>
div>
<div>testdiv>
body>
{
margin: 0 auto;
}
是图片中线一直居中
{
transform: translate(-50%);
/* 使图片左移一半
现在中线在屏幕最左边
*/
margin-left: 50%;
/* 使中线根据父元素的宽度向右移动一半,达到居中 */
}
案例:
父元素1190px
子元素1120px
不使用width
利用margin改变子元素的宽度
利用第一次的公式
设置margin-left: -10px;
width就变成了1120px