Layout: margin between different sections (which wraps <h> and <p>).

see comment in css

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<link rel="stylesheet" href="style.css">
</head>
<body>
	<header>
	  <div>
	    <p>This is a paragraph.</p>
	  </div>
	</header>
	<section>
	  <div>
	    <p>This is a another paragraph.</p>
	  </div>
	 </section>
	<a href="1">Link 1</a>
	<a href="2">Link 2</a>
</body>
</html>

 

/* removing the default spacing */
/*body,  header, section, div {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}
body {
  line-height: 1;
}*/

/*  */
header {
  background-color: grey;
  /*border: 1px blue solid;*/
}
section {
  background-color: yellow;
}
div {
   /*Parent-child collapse: 
   if there is no padding betweeen p and div (p and div adjoining), p and div's margin will collapse 
   (combine to form a single margin). In this case, the collapsed margin of p and div will be 20px.
   Horizontal collapse:
   Moreover, the margin between p top and p bottom will collapse to a single margin of 20px.
  Inspect(chrome) shows that div's content is as large as p within border */
  /* With padding added to div:
  Div and p are no longer adjoining due to padding and the margin will not collapse. Inspect shows that
  div's content is as large as p with margin (INCLUDING MARGIN). Outside of div's content, padding will 
  be added. 
  So the spacings between header .education .work (content-wrapper) footer come both from the default 
  margin around p and h and from padding of content-wrapper(div)s.*/

   padding: 50px; 
}
p {
  border: 1px red solid;
  padding: 25px;
  /*margin: 0px;*/
   margin: 20px 0px; 
}
a {
  border: 1px red solid;
}

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值