css&html的坑

2017-07-26  本文已影响0人  饥人谷_oathy

css盒模型

在CSS中,使用标准盒模型描述这些矩形盒子中的每一个。这个模型描述了元素所占空间的内容。每个盒子有四个边:外边距边, 边框边, 内填充边 与 内容边。

content-box

默认值,标准盒子模型。 width
height
只包括内容的宽和高, 不包括边框(border),内边距(padding),外边距(margin)。

border-box(ie盒模型)

width
height
属性包括内容,内边距和边框,但不包括外边距。这是当文档处于 Quirks模式 时Internet Explorer使用的盒模型

background-box

元素的background范围覆盖了content, padding和border,但不包括margin.


外边距合并(外边距塌陷)

发生margin合并的三种基本情况:

解决方法


关于让一个未知宽高的img在一个div中居中的问题

这是兼容ie8的解决方法

<!-- HTML结构 -->
<div>![](...)<span>here are test words</span></div>
<!-- 样式如下 -->
<style>
  img {
    vertical-align: middle;
  }
  div:before {
    content: "";
    display: inline-block;
    width: 0;
    height: 100%;
    vertical-align: middle;
  }
  span {
    vertical-align: middle;
  }
</style>
如果不用兼容呢
  #container{
      position:relative;
  }
  
  #center{
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
 }
 #container{
     display:flex;
     // display: -webkit-flex; Safari需要使用特定的浏览器前缀
     justify-content:center;
     align-items: center;
 }

 #center{
 }
上一篇 下一篇

猜你喜欢

热点阅读