一些css的特性和‘坑’
2017-02-15 14:13
211 查看
margin对元素的影响
1.首先是嵌套元素: margin-top会合并,而margin-left不会合并
<style> .outer{ width: 200px; height: 200px; background: #CCC; } .inner{ height: 100px; width: 100px; background: orange; margin-top:50px; margin-left: 50px; } </style> <div class="outer"> <div class="inner"></div> </div>
运行结果:
如果解决margin-top合并问题呢?
1.父元素或子元素使用浮动或者绝对定位absolute
2.父元素overflow:hidden;
3.父元素设置padding
4.父元素设置border
2.相邻元素,margin-top和margin-bottom会合并,而且会取较大的值作为他们之前的间距
<style> .rect { height: 100px; width: 100px; background: orange; margin-top: 20px; margin-bottom: 50px; } </style> <div class="rect"></div> <div class="rect"></div>
运行结果:
2.相邻元素,margin-left和margin-right不会合并
<style> .rect { float: left; height: 100px; width: 100px; background: orange; margin-left: 50px; margin-right: 50px; } </style> <div class="rect"></div> <div class="rect"></div>
运行结果:
弄一个满屏的块级元素
比如一个div<style> div { height:100%; width:100%; background:orange; } </style>
然后查看结果:发现什么都没有。
这时需要添加:
<style> html,body { height:100%; } </style>
因为html和body的高度是根据内部元素的高度决定的。如果没有内部元素撑开,需要手动设置html和body高度
display:inline-block之间的空白间距
如下:<style> .span1 { display: inline-block; height: 30px; width: 100px; background: orange; } </style> <span class="span1"></span> <span class="span1"></span> <span class="span1"></span> <span class="span1"></span>
运行结果:
不同浏览器的间距有点不一样,但是一般都是4px,像火狐和谷歌浏览器,但360浏览器是8px。
解决方法:
借鉴张大大的方法:—去除inline-block元素间间距的N种方法
使用css3动画时,如果用到需要浏览器前缀的属性,不仅@keyframes前需要加前缀,内部的转变属性也需要加前缀,才能保证浏览器的兼容性。说得可能不太清楚,下面看例子吧。(注意下面/**/注释)
<style> .ani_div { height:100px; width:100px; background:orange; animation: myAnimate 3s; -moz-animation: myAnimate 3s; -webkit-animation: myAnimate 3s; -o-animation: myAnimate 3s; } @keyframes myAnimate { from {transform:rotate(0deg);} to {transform:rotate(360deg);} } /*不仅keyframes要加前缀,里面的transform也需要加前缀*/ @-moz-keyframes myAnimate/* Firefox */ { from {-moz-transform:rotate(0deg);} to {-moz-transform:rotate(360deg);} } /*不仅keyframes要加前缀,里面的transform也需要加前缀*/ @-webkit-keyframes myAnimate/* Safari and Chrome */ { from {-webkit-transform:rotate(0deg);} to {-webkit-transform:rotate(360deg);} } /*不仅keyframes要加前缀,里面的transform也需要加前缀*/ @-o-keyframes myAnimate/* Opera */ { from {-o-transform:rotate(0deg);} to {-o-transform:rotate(360deg);} } </style> <div class="ani_div"></div>
* 参拜各位大神的资料,结合自己遇到的问题写成笔记记录下来,如有错误,请多多指点,后续一直更新,希望一直进步。*
相关文章推荐
- css一些有效特性
- 总结一些更多的针对webkit的HTML, CSS和Javascript方面的特性.
- 总结一些更多的针对webkit的HTML, CSS和Javascript方面的特性.
- 使用ASP.net 2.0 的一些新特性
- 《Introducing Visual Basic 2005》中看到的一些VB2005的新特性
- (原创)DataGrid和DropDownList的一些配合以及使用css定制DataGrid
- 一些不常用的css
- 通过对php一些服务器端特性的配置加强php的安全
- ASP.NET 2.0 的一些新特性
- asp.net2.0的一些特性(downmoon收集)
- DataGrid和DropDownList的一些配合以及使用css定制DataGrid
- ASP.NET 2.0的一些新特性(仅针对开发人员)
- asp.net2.0的一些特性
- 驾驭“野马”-- 探索Java SE 6的一些新特性
- 在 Oracle JDBC 访问中加入一些 Spring 特性
- 一些CSS
- 用S60操作系统SDK开发NOKIA手机应用程序(4)- 界面层框架及一些特性
- 与MYSQL 搏斗。介绍MYSQL的一些特性和使用工具。
- css学习的一些心得
- SharePointV3,即Office SharePoint Server 2007的一些新特性透露!