ITPub博客

首页 > IT职业 > IT职场 > css浮动产生的负作用

css浮动产生的负作用

IT职场 作者:daqianmen 时间:2021-09-11 09:46:17 0 删除 编辑

1、背景不能显示(overflow:hidden)。

由于浮动产生,如果对父级设置了(css background背景)CSS背景颜色或CSS背景图片,而父级不能被撑开,所以导致CSS背景不能显示。

2、边框不能撑开,如果父级设置了CSS边框属性,子级里使用了float属性产生浮动,父级不能被撑开。

3、margin padding设置值不能正确显示。

由于浮动导致父级子级之间设置css padding,css margin 属性的值不能正确表达,特别是上下边的padding和margin不能正确显示。

实例

<head>
<style type="text/css">
*{ margin:0; padding:0;}   //取消设置 如 li 留下的那个实点
ul{ width:900px; border:3px dotted red; list-style:none; overflow: hidden;}//overflow:hidden :让行高自适应
.left{ width:300px; height:300px; background:#FF0; float:left;}   //float:left设置浮动全部向左排
.chent{ width:300px; height:300px; background:#000; float:left}
.right{ width:300px; height:300px; background:red; float:left}
</style>
</head>
<body>
<ul>
<li></li>
         <li></li>
         <li></li>
</ul>
</body>

以上就是css浮动产生的负作用,希望对大家有所帮助。更多css学习指路:css教程

本文转载于掘金,如有侵犯联系作者修改。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1727/viewspace-2828035/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-07-31

  • 博文量
    108
  • 访问量
    34266