带大家了解下margin

1.margin是:外边距

2.margin:当两个垂直外边距相遇时,它们将形成一个外边距。合并后的外边距的高度等于两个发生合并的外边距的高度中的较大者.margin左右不合并

3.如果margin有三个值,第一个值表示上margin值,第二个值表示左右margin的值

4.何时应当使用margin:需要在border外侧添加空白时。空白处不需要背景(色)时。上下相连的两个盒子之间的空白,需要相互抵消时。如15px + 20px的margin,将得到20px的空白。何时应当时用padding:需要在border内测添加空白时。空白处需要背景(色)时。上下相连的两个盒子之间的空白,

5.谁有margin谁没有margin:行内元素没有margin-top 和 margin-bottom

  • 行内元素的padding-top、padding-bottom、margin-top、margin-bottom属性设置是无效的
  • 行内元素的padding-left、padding-right、margin-left、margin-bottom属性设置是有效的


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的校园官网首页的HTML和CSS示例代码,你可以根据自己的需求和风格进行修改和扩展。 HTML代码: ``` <!DOCTYPE html> <html> <head> <title>校园官网首页</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <header> <h1>校园官网</h1> <nav> <ul> <li><a href="#">首页</a></li> <li><a href="#">新闻</a></li> <li><a href="#">活动</a></li> <li><a href="#">招生</a></li> <li><a href="#">联系我们</a></li> </ul> </nav> </header> <main> <section class="banner"> <h2>欢迎来到我们的校园</h2> <p>这里有最好的师资力量,最先进的教学设施,最优秀的学生。</p> <button>了解更多</button> </section> <section class="news"> <h2>最新新闻</h2> <ul> <li> <img src="news1.png"> <h3>校运会圆满结束</h3> <p>本次校运会取得了很好的成绩,大家都非常努力。</p> </li> <li> <img src="news2.png"> <h3>学校获得国家级荣誉</h3> <p>我校在最新评比中获得了全国三好学校的称号,值得庆贺。</p> </li> <li> <img src="news3.png"> <h3>学生会换届选举</h3> <p>本次学生会换届选举将于下周举行,请各位同学积极参与。</p> </li> </ul> </section> <section class="activities"> <h2>校园活动</h2> <ul> <li> <img src="activity1.png"> <h3>大型文艺晚会</h3> <p>时间:6月15日 下午6点<br> 地点:学生活动中心<br> 欢迎大家前来观看。</p> </li> <li> <img src="activity2.png"> <h3>志愿者招募</h3> <p>我们正在招募志愿者,欢迎各位同学积极参与。</p> </li> <li> <img src="activity3.png"> <h3>科技创新比赛</h3> <p>我们将于下个月举办科技创新比赛,欢迎各位同学参加。</p> </li> </ul> </section> </main> <footer> <p>版权所有 © 校园官网 2021</p> </footer> </body> </html> ``` CSS代码: ``` body { margin: 0; padding: 0; font-family: Arial, sans-serif; } header { background-color: #333; color: #fff; padding: 20px; display: flex; justify-content: space-between; align-items: center; } nav ul { list-style: none; display: flex; } nav li { margin-right: 20px; } nav a { color: #fff; text-decoration: none; font-weight: bold; } main { padding: 20px; } .banner { background-image: url(banner.jpg); background-size: cover; background-position: center; color: #fff; padding: 100px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; } .banner h2 { font-size: 40px; margin-bottom: 20px; } .banner p { font-size: 20px; margin-bottom: 40px; } .banner button { background-color: #fff; color: #333; padding: 10px 20px; font-weight: bold; border: none; border-radius: 5px; cursor: pointer; } .news { margin-top: 50px; } .news h2 { font-size: 30px; margin-bottom: 20px; } .news ul { list-style: none; display: flex; flex-wrap: wrap; justify-content: space-between; } .news li { margin-bottom: 30px; flex-basis: 30%; } .news img { width: 100%; height: auto; margin-bottom: 10px; } .news h3 { font-size: 20px; margin-bottom: 10px; } .news p { font-size: 14px; line-height: 1.5; } .activities { margin-top: 50px; } .activities h2 { font-size: 30px; margin-bottom: 20px; } .activities ul { list-style: none; display: flex; flex-wrap: wrap; justify-content: space-between; } .activities li { margin-bottom: 30px; flex-basis: 30%; } .activities img { width: 100%; height: auto; margin-bottom: 10px; } .activities h3 { font-size: 20px; margin-bottom: 10px; } .activities p { font-size: 14px; line-height: 1.5; } footer { background-color: #333; color: #fff; padding: 20px; text-align: center; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值