Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

负margin的使用 #8

Open
yurensmile opened this issue Apr 17, 2019 · 1 comment
Open

负margin的使用 #8

yurensmile opened this issue Apr 17, 2019 · 1 comment

Comments

@yurensmile
Copy link
Owner

yurensmile commented Apr 17, 2019

结论: 当margin值为负的时候,top\left使自身元素移动,bottom\right使其下\右的元素移动,
看一个例子吧:

<div class="wrap">
  <div class="num1">我的right有-10px</div>
  <div class="num2">我的bottom有-10px</div>
  <div class="num3">我的top有-10px</div>  
  <div class="num4">我的left有-10px</div>
</div>
*{
  margin:0; 
  padding:0;
}
.wrap{
  width:440px; 
  border:10px solid #000;
  display: flex;
  flex-wrap: wrap;
}
.wrap > div {
  box-sizing: border-box;
  width: 200px;
  height: 100px;
  line-height: 90px;
  text-align: center;
}
.num1{
  border: 5px solid red;
  margin-right: -10px;
}
.num2 {
  border: 5px solid green;
  margin-bottom: -10px;
}
.num3{
  border: 5px solid blue;
  margin-top: -10px;
}
.num4{
  border: 5px solid yellow;
  margin-left: -10px;
}

结果:
image

num2的负值margin-bottom为什么不起作用呢,这是一个需要注意的问题。
参考文章:我知道你不知道的负Margin

@yurensmile
Copy link
Owner Author

组件化:模板+数据结构

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant