简体   繁体   中英

How to stop a position: fixed element in the right place in css and html?

I have page Job and element with logo and button apply . I added to this element position: fixed and when I scroll page I have this element STICKY and when I scroll to footer the logo and button overlaps with the footer. Can I change it somehow to make this element (logo and button) turn off position: fixed at the footer or other div below? I want use position:fixed only next to content - card-text (which is on the left side my element).

element {
     margin: 0 auto;
     margin-top: 0px;
     display: block;
     margin-top: 15px;
}
 img#companylogo {
     position: fixed;
}
 img#companylogo {
     position: fixed;
}
 img {
     vertical-align: middle;
     border-style: none;
}
<div class="row" >
<div class="col-xl-8">
   <div class="card shadow p-3 mb-5 bg-white rounded" style="max-width: 50rem;margin-left: auto; margin-right: auto;">
      <div class="card-body">
         <b>agreement</b>
         <p class="card-text"><%= @job.job_type %></p>
         <b>description</b>
         <p class="card-text"><%=raw @job.description %></p>
         <b>skills</b>
         <p class="card-text"> <%=raw @job.requirements %></p>
         <b>expiration date offer</b>
         <p> <%= @job.data %> <%= @job.hour %></p>
         :
      </div>
   </div>
</div>
<div class="col-xl-4">
   <%  unless @job.avatar_url.nil? %><%= image_tag  @job.avatar_url(:display), style: "margin: 0 auto; display: block;  margin-top: 15px", id: "companylogo" %><% end %>
   <%= link_to @job.url do %>
   <% end %>
   <%=  link_to 'Apply', @job.url, class: "btn btn-lg btn-block pb_btn-pill  btn-shadow-blue .margin_desktop", style: "max-width: 200px ; background:  linear-gradient(to right, #1488cc, #2b32b2); color: white !important;  border: 0px;margin: 0 auto; display: block; margin-top: 15px;  margin-bottom: 15px"%>
</div>
</body>

辅助绘图

You can use position:sticky.. And browser support is great. Check this link link Example: This Link

like thislink you can do it with this jquery code

var windw = this;

$.fn.followTo = function ( pos ) {
var $this = this,
    $window = $(windw);

$window.scroll(function(e){
    if ($window.scrollTop() > pos) {
        $this.css({
            position: 'absolute',
            top: pos
        });
    } else {
        $this.css({
            position: 'fixed',
            top: 0
        });
    }
  });
};

$('#your div ID contain logo and btn').followTo(200/*WHERE YOU WANT TO STOP SCROLING*/);

I hope it solved your problem but If you can put your code on jsfiddle I can help you better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM