我试图将进度条锁定到页面顶部(类:outerDiv_S),因此如果用户向下滚动,他们将始终可以看到他们的进度。
我已经尝试过这篇文章提出的各种解决方案但没有成功:How do you create non scrolling div at the top of an HTML page without two sets of scroll bars
/*basic reset*/
* {margin: 0; padding: 0;}
.html_S {
height: 100%;
}
.toast {
opacity: 1 !important;
}
.body_S {
min-height: 100%;
margin: 0;
background-repeat: no-repeat;
background-attachment: fixed;
font-family: montserrat, arial, verdana;
background-color: black !important;
}
.reqSpan_S {
top: -15px;
position:relative;
}
.reqFieldText_S {
color: red;
padding: 0;
margin: 0;
}
.reqFieldStar_S {
font-weight: bold;
}
.k-button {
color: red;
}
.buttonCentre_S {
clear: left;
text-align: center;
}
.outerDiv_S {
width: 85%;
margin: 50px auto;
text-align: center;
position: fixed;
}
#surveyForm {
top: 135px;
position:relative;
width: 85%;
margin: 50px auto;
text-align: left;
}
#surveyForm fieldset {
background: white;
border: 0 none;
border-radius: 3px;
box-shadow: 0 0 15px 1px rgba(0, 0, 0, 0.4);
padding: 20px 30px;
box-sizing: border-box;
width: 80%;
margin: 0 10%;
}
/*inputs*/
#surveyForm input, #surveyForm textarea {
padding: 15px;
border: 1px solid #ccc;
border-radius: 3px;
margin-bottom: 10px;
width: 100%;
box-sizing: border-box;
font-family: montserrat;
color: #2C3E50;
font-size: 13px;
}
/*buttons*/
#surveyForm .action-button {
text-align: center;
width: 100px;
background: #27AE60;
font-weight: bold;
color: white;
border: 0 none;
border-radius: 1px;
cursor: pointer;
padding: 10px 5px;
margin: 10px 5px;
}
#surveyForm .action-button:hover, #surveyForm .action-button:focus {
box-shadow: 0 0 0 2px white, 0 0 0 3px #27AE60;
}
#surveyForm .action-button-submit {
width: 100px;
background: #3498db;
font-weight: bold;
color: white;
border: 0 none;
border-radius: 1px;
cursor: pointer;
padding: 10px 5px;
margin: 10px 5px;
}
/*For Toast not part of surveyForm...*/
.action-button-ok {
width: 100px;
background: rgba(255, 255, 255, 0.3);
font-weight: bold;
color: white;
border: 0 none;
border-radius: 1px;
cursor: pointer;
padding: 10px 5px;
margin: 10px 5px;
}
#surveyForm .action-button-submit:hover, #surveyForm .action-button-submit:focus {
box-shadow: 0 0 0 2px white, 0 0 0 3px #3498db;
}
/*headings*/
.fs-title {
font-size: 15px;
text-transform: uppercase;
color: #2C3E50;
margin-bottom: 10px;
}
.fs-subtitle {
font-weight: normal;
font-size: 13px;
color: #666;
margin-bottom: 20px;
}
/*progressbar*/
#progressbar {
margin-bottom: 30px;
overflow: hidden;
/*CSS counters to number the steps*/
counter-reset: step;
}
#progressbar li {
list-style-type: none;
color: white;
text-transform: uppercase;
font-size: 9px;
/* width should be 100 divided by the number of steps */
/* this is set in the code dynamically in javascript */
width: 12.5%;
float: left;
position: relative;
}
#progressbar li:before {
content: counter(step);
counter-increment: step;
width: 20px;
line-height: 20px;
display: block;
font-size: 10px;
color: #333;
background: white;
border-radius: 3px;
margin: 0 auto 5px auto;
}
/*progressbar connectors*/
#progressbar li:after {
content: '';
width: 100%;
height: 2px;
background: white;
position: absolute;
left: -50%;
top: 9px;
z-index: -1; /*put it behind the numbers*/
}
#progressbar li:first-child:after {
/*connector not needed before the first step*/
content: none;
}
/*marking active/completed steps green*/
/*The number of the step and the connector before it = green*/
#progressbar li.active:before, #progressbar li.active:after{
background: #27AE60;
color: white;
}
.k-dropdown {
width: 100%;
}
.k-state-selected.k-state-focused {
background-color: #27AE60;
border: 0;
}
#surveyForm hr {
border: 0;
height: 0;
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-bottom: 1px solid rgba(255, 255, 255, 0.3);
margin-bottom: 10px;
}
/* https://stackoverflow.com/a/17541916/1550052 */
.rad,
.ckb{
cursor: pointer;
user-select: none;
-webkit-user-select: none;
-webkit-touch-callout: none;
padding: 10px;
/*float: left;*/
}
label {
display:block;
}
.rad > input,
.ckb > input{ /* HIDE ORG RADIO & CHECKBOX */
visibility: hidden;
position: absolute;
}
/* RADIO & CHECKBOX STYLES */
.rad > i,
.ckb > i{ /* DEFAULT <i> STYLE */
display: inline-block;
vertical-align: middle;
width: 16px;
height: 16px;
border-radius: 50%;
transition: 0.2s;
box-shadow: inset 0 0 0 8px #fff;
border: 1px solid #d3d3d3;
background: #666;
margin-right: 4px;
}
/* CHECKBOX OVERWRITE STYLES */
.ckb > i {
width: 25px;
border-radius: 3px;
}
.rad:hover > i{ /* HOVER <i> STYLE */
box-shadow: inset 0 0 0 3px #fff;
background: #666;
}
.rad > input:checked + i{ /* (RADIO CHECKED) <i> STYLE */
box-shadow: inset 0 0 0 3px #fff;
background: #27AE60;
}
/* CHECKBOX */
.ckb > input + i:after{
content: "";
display: block;
height: 12px;
width: 12px;
margin: 2px;
border-radius: inherit;
transition: inherit;
background: #d3d3d3;
}
.ckb > input:checked + i:after{ /* (RADIO CHECKED) <i> STYLE */
margin-left: 11px;
background: #27AE60;
}
&#13;
<body class='body_S'>
<div class='outerDiv_S'>
<!-- progressbar -->
<ul id='progressbar'>
<li>First</li><li>Second</li><li>Third</li><li>Fourth</li><li>Fifth</li><li>Sixth</li><li>Seventh</li><li>Eighth</li>
</ul>
<span class='reqFieldText_S reqSpan_S'><span class='reqFieldStar'>*</span> indicates required field</span>
</div>
<form id='surveyForm'>
<!-- fieldsets -->
<fieldset >
<h2 class="fs-title">
Title
<br /><br /><br /><br /><br /><br /><br /><br />
</h2>
<h2 class="fs-subtitle">
Subheading
</h2>
<br /><br />
<h2 class="fs-subtitle">
1
</h2>
<label>Type of Business
</label>
<br />
<label class="ckb" for="cb-638-0">
<input type="checkbox" name="cb-638" id="cb-638-0" value="3223" />
<i></i>Accommodations
</label>
<br /><br />
<label class="ckb" for="cb-638-1">
<input type="checkbox" name="cb-638" id="cb-638-1" value="3224" />
<i></i>Activities
</label>
<label class="ckb" for="cb-638-2">
<input type="checkbox" name="cb-638" id="cb-638-2" value="3225" />
<i></i>Association
</label>
<label class="ckb" for="cb-638-3">
<input type="checkbox" name="cb-638" id="cb-638-3" value="3226" />
<i></i>Convention
</label>
<label class="ckb" for="cb-638-4">
<input type="checkbox" name="cb-638" id="cb-638-4" value="3227" />
<i></i>Convention Centre
</label>
<label class="ckb" for="cb-638-5">
<input type="checkbox" name="cb-638" id="cb-638-5" value="3228" />
<i></i>Cruise Line
</label>
<label class="ckb" for="cb-638-6">
<input type="checkbox" name="cb-638" id="cb-638-6" value="3229" />
<i></i>Destination
</label>
<label class="ckb" for="cb-638-7">
<input type="checkbox" name="cb-638" id="cb-638-7" value="3230" />
<i></i>Destination
</label>
<label class="ckb" for="cb-638-8">
<input type="checkbox" name="cb-638" id="cb-638-8" value="3231" />
<i></i>Event
</label>
<label class="ckb" for="cb-638-9">
<input type="checkbox" name="cb-638" id="cb-638-9" value="3232" />
<i></i>Technology
</label>
<label class="ckb" for="cb-638-10">
<input type="checkbox" name="cb-638" id="cb-638-10" value="3233" />
<i></i>Transportation
</label>
<label class="ckb" for="cb-638-11">
<input type="checkbox" name="cb-638" id="cb-638-11" value="3234" />
<i></i>Tourism
</label>
<label class="ckb" for="cb-638-12">
<input type="checkbox" name="cb-638" id="cb-638-12" value="3235" />
<i></i>Venues
</label>
</fieldset>
</form>
</body>
</html>
&#13;
答案 0 :(得分:3)
尝试添加
位置:固定;到outerDiv_S
.outerDiv_S {
position: fixed;
}
它的作用是将div保护到一个位置,当用户向下滚动页面时它不会移动。
你需要做一些样式来修复div和其他内容的定位。
你需要做的样式将是这样的
.outerDiv_S {
width: 85%;
margin: 0px auto;
text-align: center;
position: fixed;
left: 0;
right: 0;
top: 0;
z-index: 9999;
padding-top: 80px;
box-sizing: border-box;
background-color: #000;
}
这是一个你要求的实例
答案 1 :(得分:0)
使用首字母缩写;在某些对象上最有可能表现更好: 就像以某种方式,您拥有一个移动网站,并且希望您的框保留在页面顶部。这样一来,它可以更平稳地移动,并且不会跟随页面。
您可能还想使用display:block;可以将菜单设置为禁止放置。有时,除非尝试第二种方法,否则它可能适用于某些主题。
.containter {
display: block;
position: initial;
}
与其他方法不同,有时您可能需要将某些块的所有对象都设置为顶部,也可以使用第一边距功能-28px将其设置为向上28px。如果您的程序块处于绝对值高于所有位置的功能。您可以相应地更改px值和正值。
您的代码块可能位于所有对象之上,但是该对象也没有空间。
您将必须手动找到最高的对象标头并设置:“ padding-top:20px;”相应地,如果块菜单设置为50px,则您希望块设置多少开放空间,然后设置50px。为顶部菜单留出空间。绝对的覆盖条件下的所有其他对象。
.h {
padding-top: 50px;
}
.containcer {
display: block;
margin: -28px 0 0 0px;
position: absolute;
{