问题
I have tried using position fixed but I just cannot seem to find out how to do it, I want my sidebar to stay fixed along the screen as the user scrolls, my sidebar element id is #displayside
can someone please help me out and explain what I must do to have this fixed.
Please excuse me if this question is too obvious but I am just starting to code and I need help.
Thanks!
#displayside {
width: 15%;
/* margin-left: 25px; */
float:right;
text-align:center;
padding:5px;
margin:3px;
background-image:url('/resources/images/htmlbg.jpeg');
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px; /* future proofing */
-khtml-border-radius: 10px; /* for old Konqueror browsers */
position: fixed;
回答1:
Use position:fixed
#displayside
{
position:fixed;
}
and set top and left according to your requirement
as
#displayside
{
position:fixed;
left:10px;
top:10px;
}
来源:https://stackoverflow.com/questions/11395201/css-and-js-make-div-follows-scroll