css样式设置底部固定
有时候我们的页面会希望底部有一个固定的栏,不管页面的其他内容有多少,这个栏总是固定在页面的底部。这时候我们可以使用CSS来设置底部固定,接下来我会介绍一下具体步骤:
/* 首先我们要设置body和html的高度为100% */ html,body{ height:100%; margin:0; padding:0; } /* 这里我们要创建一个类名为wrapper的div,用来包含页面的主要内容 */ .wrapper{ min-height:100%; /* 接下来我们需要让.wrapper的padding-bottom等于我们需要固定在底部的栏的高度 */ padding-bottom:50px; } /* 这里我们需要创建一个类名为footer的div,来设置我们需要固定的栏的样式 */ .footer{ position:fixed; left:0; bottom:0; width:100%; height:50px; background-color:#333; color:#fff; text-align:center; line-height:50px; }
接下来我们在HTML中就可以使用以上的class名来设置页面的样式,具体方法为:
<body> <div class="wrapper"> 主要内容 </div> <div class="footer"> 底部栏 </div> </body>
这样就可以实现一个固定在底部的栏了,希望本篇文章对您有所帮助!