通过 css 将 div 固定在底部 - css

html-css014

通过 css 将 div 固定在底部 - css,第1张

对将要固定至底部的 div 设置如下 class 样式即可:

设置基础宽高后并添加绝对位置定位 position 为 fixed 和 bottom 为 0;

以上便是此次分享的全部内容,希望能对大家有所帮助!

1、首先新建一个html页面,然后在这个html代码页面创建一个<div>标签,同时给这个<div>添加一个class类为footer。

2、然后设置footer类,把div固定在底部。创建<style>标签,在该标签内设置通过position:fixedbottom:0设置footer类样式,把div固定在底部。

css样式代码:

.footer{

height:100px

width:100%

background-color:#ddd

position:fixed

bottom:0

}

3、保存html代码,然后使用浏览器打开即可看到不管如何放大缩小浏览器div都是固定在底部的。