2013-09-28 326 views
7

trong giờ qua tôi đã cố gắng tìm ra chính xác những gì là sai với chân trang dính của tôi không hoạt động. Tôi có cấu trúc chính xác giống như ví dụ được đưa ra trên trang web getboostrap, nhưng nó dường như không hoạt động. Bất kỳ ý tưởng gì là chính xác sai?Bootstrap 3 và Chân trang Chú ý

Tất cả các tệp css bootstrap được tải chính xác.

<body style=""> 

    <div id="wrap"> 
     <div class="navbar navbar-inverse navbar-fixed-top"> 
      <div class="container"> 
       <div class="navbar-header"> 
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> 
         <span class="icon-bar"></span> 
         <span class="icon-bar"></span> 
         <span class="icon-bar"></span> 
        </button> 
        <a class="navbar-brand" href="/">Application name</a> 
       </div> 
       <div class="collapse navbar-collapse"> 
        <ul class="nav navbar-nav"> 
         <li><a href="/">Home</a></li> 
         <li><a href="/Home/About">About</a></li> 
         <li><a href="/Home/Contact">Contact</a></li> 
        </ul> 
         <ul class="nav navbar-nav navbar-right"> 
     <li><a href="/Account/Register" id="registerLink">Register</a></li> 
     <li><a href="/Account/Login" id="loginLink">Log in</a></li> 
    </ul> 

       </div> 
      </div> 
     </div> 


     <div class="container"> 



<div class="jumbotron"> 
    <h1>ASP.NET</h1> 
    <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p> 
    <p><a href="http://asp.net" class="btn btn-primary btn-large">Learn more »</a></p> 
</div> 
<div class="row"> 
    <div class="col-md-4"> 
     <h2>Getting started</h2> 
     <p> 
      ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that 
      enables a clean separation of concerns and gives you full control over markup 
      for enjoyable, agile development. 
     </p> 
     <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301865">Learn more »</a></p> 
    </div> 
    <div class="col-md-4"> 
     <h2>Get more libraries</h2> 
     <p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p> 
     <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301866">Learn more »</a></p> 
    </div> 
    <div class="col-md-4"> 
     <h2>Web Hosting</h2> 
     <p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p> 
     <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301867">Learn more »</a></p> 
    </div> 
</div> 
     </div> 

    </div> 

    <div id="footer"> 
     <div class="container"> 
      <p class="text-muted credit">Example courtesy <a href="http://martinbean.co.uk">Martin Bean</a> and <a href="http://ryanfait.com/sticky-footer/">Ryan Fait</a>.</p> 
     </div> 
    </div> 


</body> 

Tôi đã tìm ra giải pháp. Tôi nghĩ rằng bao gồm tất cả CSS cũng sẽ có CSS ​​cho footer nhưng dường như nó không. Bạn yêu cầu sau đây để thực hiện một công việc chân dính với bootstrap

html, 
body { 
    height: 100%; 
    /* The html and body elements cannot have any padding or margin. */ 
} 

/* Wrapper for page content to push down footer */ 
#wrap { 
    min-height: 100%; 
    height: auto !important; 
    height: 100%; 
    /* Negative indent footer by its height */ 
    margin: 0 auto -60px; 
    /* Pad bottom by footer height */ 
    padding: 0 0 60px; 
} 

/* Set the fixed height of the footer here */ 
#footer { 
    height: 60px; 
    background-color: #f5f5f5; 
} 
+1

tôi thấy khó để tin rằng đây là giải pháp đơn giản nhất để sửa chữa chân xuống đáy. – JohnAllen

+0

Tôi sẽ giới thiệu cho bạn giải pháp này: https://gist.github.com/martinbean/1855032 – Manza

Trả lời

7

Made một Fiddle nhanh chóng với mã của bạn và một số tinh chỉnh để chân: http://jsfiddle.net/2Zaxt/.

<div id="footer" class="container"> 
    <nav class="navbar navbar-default navbar-fixed-bottom"> 
     <div class="navbar-inner navbar-content-center"> 
      <p class="text-muted credit">Example courtesy <a href="http://martinbean.co.uk">Martin Bean</a> and <a href="http://ryanfait.com/sticky-footer/">Ryan Fait</a>.</p> 
     </div> 
    </nav> 
</div> 
+16

Ví dụ của bạn là chân trang "cố định", không phải là chân trang dính. Đã sửa lỗi luôn hiển thị bất kể chiều dài nội dung dọc. Chú ý "dính vào đáy" và do đó không hiển thị khi có đủ nội dung theo chiều dọc để yêu cầu cuộn xuống, nhưng hiển thị và ở dưới cùng khi có nội dung tối thiểu. –

+0

Tôi có thể thấy nơi danh pháp không phải lúc nào cũng rõ ràng nhưng điều này chắc chắn đã cho tôi kết quả tôi muốn. Cảm ơn. – Rig

+0

hoàn hảo một ..... –

6
html, 
body { 
    height: 100%; 
    /* The html and body elements cannot have any padding or margin. */ 
} 

/* Wrapper for page content to push down footer */ 
#wrap { 
    min-height: 100%; 
    height: auto !important; 
    height: 100%; 
    /* Negative indent footer by its height */ 
    margin: 0 auto -60px; 
    /* Pad bottom by footer height */ 
    padding: 0 0 60px; 
} 

/* Set the fixed height of the footer here */ 
#footer { 
    height: 60px; 
    background-color: #f5f5f5; 
} 
1

Đây là cách nó làm việc cho tôi.

tôi đã thêm các giá trị Footer ID và phong cách tùy chỉnh để ID đó, và cho cái nhìn tương tự và cảm nhận thêm "navbar-default"

HTML

<div id="footer" class="navbar-default"> 
    <div class="container"> 
    <p>Your Footer Content Here</p>   
    </div> 
</div> 

CSS

#footer { 
    background-color: #F5F5F5; 
    bottom: 0; 
    height: 60px; 
    position: relative; 
    width: 100%; 
} 
11

Tại sao bạn không sử dụng:

.navbar-fixed-bottom 

Điều này sẽ giải quyết vấn đề điều hướng cố định dưới cùng của bạn và bạn có thể đặt bất kỳ thứ gì vào đó.

+0

đó là trong câu trả lời của George Durzi – Jordan

+1

tháng 9 năm 2013, nhưng có câu trả lời của bạn có được quyền .. – Jordan

+1

Đây không phải là chân trang dính, chân trang dính ở dưới cùng chỉ hiển thị khi bạn cuộn trang xuống. – Manza

1

Bạn có thể tìm thấy một ví dụ cho một 'chân dính với một thanh điều hướng cố định' (cố định để phía trên cùng của trang) trong tài liệu bootstrap: http://getbootstrap.com/examples/sticky-footer-navbar/

CSS:

/* Sticky footer styles */ 
html { 
    position: relative; 
    min-height: 100%; 
} 
body { 
    /* Margin bottom by footer height */ 
    margin-bottom: 60px; 
} 
#footer { 
    position: absolute; 
    bottom: 0; 
    width: 100%; 
    /* Set the fixed height of the footer here */ 
    height: 60px; 
    background-color: #f5f5f5; 
} 

/* Fixed navbar styles */ 
body > .container { 
    padding-top: 60px; 
} 
1

giải pháp đơn giản độc đáo cho Baes chân dính trên @ teh0wner, tôi đã thêm một số CSS JS

html { 
    position: relative; 
    min-height: 100%; 
} 
footer { 
    position: absolute; 
    bottom: 0; 
    width: 100%; 
} 

JS

$(document).ready(function() { 
    var height = $('footer').height(); 
    $('body').css({ 
     "margin-bottom": height 
    }); 
}); 
0

Trong bootstrap 3, lớp container và footer, bằng cách nào đó ghi đè quy tắc css của bạn. Tôi đã cố thay đổi màu nền của chân. Tôi đã thử nhiều thứ mà tôi đã tìm thấy dưới dạng giải pháp trên web và không thể thực hiện thành công. Sau khi sử dụng lớp clearfix cho footer trang đã trở thành những gì tôi thực sự muốn xem.

.myFooter { 
 
    background-color: #c4a9f1; 
 
    width: 100%; 
 
} 
 
.hi-icon a { 
 
    display: block; 
 
    width: 100%; 
 
    height: 100%; 
 
    position: absolute; 
 
    top: 0px; 
 
    z-index: 100; 
 
}
<footer class="footer clearfix"> 
 
    <div class="container myFooter"> 
 
    <div class=" "> 
 
     <div class="col-sm-3"> 
 
     <h3 class="page-header">Part 1 </h3> 
 
     <ul> 
 
      <li>Link1</li> 
 
      <li>Link2</li> 
 
      <li>Link3</li> 
 
      <li>Link4</li> 
 
     </ul> 
 
     </div> 
 
     <div class="col-sm-3"> 
 
     <h3 class="page-header">Part 2</h3> 
 
     <ul> 
 
      <li>Link1</li> 
 
      <li>Link2</li> 
 
      <li>Link3</li> 
 
      <li>Link4</li> 
 
     </ul> 
 
     </div> 
 

 

 
    </div> 
 
    </div> 
 
    </div> 
 
</footer>