Boa*_*rdy 3 html javascript css css3 tether
我正在开发一个新的网站,我希望在容器div的底部包含一个页脚.
我发现了一个名为Tether的javascript库(http://github.hubspot.com/tether/),但我遇到了实施问题.
下面是我的HTML代码
<html>
<head>
<title>Bug Reporting</title>
<link href="StyleSheet.css" type="text/css" rel="stylesheet" />
<script src="includes/jquery.js"></script>
<script src="includes/tether/tether.js"></script>
<script>
$(document).ready(function()
{
new Tether({
element: '.footer',
target: '.container',
attachment: 'top left',
targetAttachment: 'bottom left'
});
});
</script>
</head>
<body>
<div class="container">
<header>
This is the body
</header>
<div id="content">
This is the content<br />
</div>
<div class="footer1">
This is the footer
</div>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
下面是我的StyleSheet
html, body
{
font-family: arial;
margin: 0;
padding: 0;
}
header
{
background-color: red;
width: 100%;
height: 80px;
}
.container
{
background-color: yellow;
height: calc(100% - 80px);
width: 100%;
}
#content
{
background-color: blue;
width: 1024px;
margin-left: auto;
margin-right: auto;
height: auto;
}
.footer1
{
position: absolute;
background-color: green;
width: 100%;
height: 80px;
}
Run Code Online (Sandbox Code Playgroud)
问题是当我加载页面时,我在系绳库中得到一个例外
未捕获的TypeError:无法读取null的属性'classList'
感谢您的任何帮助,您可以提供.
Tether的选项定义element和target作为DOM或jQuery 元素(在相当松散的意义上),而不是字符串.
你需要将一个jQuery对象传递给Tether,如下所示:
$(document).ready(function() {
new Tether({
element: $('.footer'),
target: $('.container'),
attachment: 'top left',
targetAttachment: 'bottom left'
});
});
Run Code Online (Sandbox Code Playgroud)
初始化Tether实例时,还要确保元素在页面上.