我正在网站上工作,无论如何,每当我加载网站或点击链接时,它都会跳到最底层。
当我从application.html.erb文件中删除页脚时,该站点没有滚动到底部。 但我想保持页脚。 有谁知道问题是什么或我如何防止它?
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>NightJobs</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div id="content"></div>
<div id="container">
<%= yield %>
</div>
<%= render 'layouts/footer' %>
</body>
</html>
Layouts _footer.html.erb
<nav class="footer">
<div class="footer-link-container">
<ul>
<li><%= link_to "Home", root_path,class: "link-new" %></li>
<li><%= link_to "Help", help_path,class: "link-new" %></li>
<li><%= link_to "Contact", contact_path,class: "link-new" %></li>
<li><%= link_to "About", about_path,class: "link-new" %></li>
</ul>
</div>
<div class="subscribe-container">
<section class="subscribe">
<div class="subscribe-pitch subscribe-pitch-new">
<%= image_tag("envelope.png", alt: "envelope icon", :class => "envelope")%>
<p>Sign up for<br> daily updates<p>
</div>
<form action="index.html" method="post" class="subscribe-form">
<input type="email" name="email" class="subscribe-input" id="subscribe-spacing" placeholder="Email" autofocus>
<form action="index.html" method="post" class="subscribe-form">
<input type="email" name="email" class="subscribe-input" id="subscribe-spacing" placeholder="Zip Code" autofocus>
<button type="submit" class="tfbutton tfubutton-subscribe">Sign Up</button>
</form>
</section>
</div>
_footer.html.erb类的CSS和id&#39;
/* footer */
.footer {
text-align: center;
height: 170px;
clear: both;
position: relative;
z-index: 10;
margin-top: -3em;
background-color: #090909;
}
.footer-link-container{
width: 300px;
margin-left: 100px;
}
.footer li{
position: relative;
float: left;
margin-top: 100px;
display: inline-block;
margin-top: 35px;
}
.link-new{
position: relative;
padding: 20px;
color: $grayLight;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
font-weight: normal;
line-height: 20px;
text-decoration: none solid rgb(51,51,51);
word-spacing: 0px;
}
.link-new:hover{
color: white;
text-decoration: none;
}
/* Newsletter */
.subscribe-container {
height: 120px;
width: 300px;
position: relative;
float: right;
margin-right: 100px;
padding: 20px 20px 0px 20px;
margin-top: -40px;
border: solid 2px white;
background-color: #b5d77c;
}
.subscribe-form{
position: relative;
margin-top: -5px;
margin-left: 120px;
}
.subscribe-input{
width: 140px;
height: 15px !important;
margin-bottom: 70px;
top-padding: 100px;
line-height: 5px;
font-size: 5px;
}
#subscribe-spacing{
margin-bottom: 13px !important;
}
.subscribe-pitch{
margin-top: -5px;
margin-left: 10px;
bottom-padding: 50px;
width: 90px;
float: left;
color: #090909;
}
.envelope{
height: 60px;
width: 60px;
}
.tfubutton-subscribe {
margin-bottom: 10px !important;
margin-right: 60px !important;
width: 100px !important;
height: 30px !important;
padding: 5px 25px;
font-family: Arial, Helvetica, sans-serif;
font-size:14px;
outline: none;
text-align: center;
text-decoration: none;
color: #ffffff;
border: solid 1px #0076a3; border-right:0px;
background: #0095cd;
background: -webkit-gradient(linear, left top, left bottom, from(#00adee), to(#0078a5));
background: -moz-linear-gradient(top, #00adee, #0078a5);
border-top-right-radius: 5px 5px;
border-bottom-right-radius: 5px 5px;
}
.tfbutton:hover {
text-decoration: none;
background: #007ead;
background: -webkit-gradient(linear, left top, left bottom, from(#0095cc), to(#00678e));
background: -moz-linear-gradient(top, #0095cc, #00678e);
}
/* Fixes submit button height problem in Firefox */
.tfbutton::-moz-focus-inner {
border: 0;
}
如果您需要更多信息,请告诉我
更新
似乎页脚中的订阅部分是问题所在。 我暂时删除了订阅框,这解决了问题。 它与我认为的HTML有关,因为当我删除CSS时,页面仍然跳到底部。
答案 0 :(得分:4)
从页脚中的字段中删除autofocus
或在页面上方移动订阅表单。
<form action="index.html" method="post" class="subscribe-form">
<input type="email" name="email" class="subscribe-input"
id="subscribe-spacing" placeholder="Email" XXXautofocusXXX>
<form action="index.html" method="post" class="subscribe-form">
<input type="email" name="email" class="subscribe-input"
id="subscribe-spacing" placeholder="Zip Code" XXXautofocusXXX>
<button type="submit" class="tfbutton tfubutton-subscribe">Sign Up</button>
</form>