簡體   English   中英

無論如何,我的側邊欄都是固定的。 如何使用側邊欄滾動?

[英]My sidebar is fixed no matter what. How do I make scrolling possible with the sidebar?

我的側邊欄有點動態:我發表的文章越多,獲得的內容就越大。 但是,側邊欄也已固定,這使得有時無法看到其底部(當我減小瀏覽器窗口或有很多文章時)。 如何使通過側欄滾動成為可能? 這是我的CSS文件,側邊欄主要由div代表,類為“ container2”

@import "bootstrap-sprockets";
@import "bootstrap";
/* mixins, variables */
 /* universal */
 html {
 overflow-y: scroll;
 }
 body {
 padding-top: 60px;
 position: relative;
 }
 section {
 overflow: auto;
 }
textarea {
resize: vertical;
}
.center {
text-align: center;
h1 {
margin-bottom: 10px;
}
}
/* typography */
h1, h2, h3, h4, h5, h6 {
line-height: 1;
}
h1 {
font-size: 3em;
letter-spacing: -2px;
margin-bottom: 30px;
text-align: center;
}
h2 {
font-size: 1.2em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: center;
font-weight: normal;
color: #3BB9FF;
}
p {
font-size: 1.1em;
line-height: 1.7em;
}
/* 
footer{
background-color: #222;
div ul li{
display:block;
vertical-align: top;
width: 50%;
float: left;
}
}
*/
@mixin box_sizing {
-moz-box-sizing:    border-box;
-webkit-box-sizing: border-box;
box-sizing:         border-box;
}
/* miscellaneous */
.debug_dump {
clear: both;
float: left;
width: 100%;
margin-top: 45px;
@include box_sizing;
}
/* forms */
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;
@include box_sizing;
}
input {
height: auto !important;
}
#error_explanation {
color: red;
ul {
color: red;
margin: 0 0 30px 0;
}
}
.field_with_errors {
@extend .has-error;
.form-control {
color: $state-danger-text;
}
}
/* articles */
.container1 {
opacity: 0.75;
border: 1px solid #000000;
border-radius: 10px;
padding: 30px 75px 75px 100px;
overflow: scroll ;
}
.container1 p img {
float: left;
margin-top: 9px;
margin-right: 15px;
margin-bottom: 15px;
}
.container2 {
position: fixed;
padding: 0px 75px 20px 100px;
clear: both;
background-color: #FFFFFF; /*#F8F8F8;*/
border-radius: 5px;
overflow: scroll;
}
footer{
clear: both ;
padding: 30px 75px 75px 100px;
}
/*Search*/
.search { 
padding:6px 15px 6px 30px;
margin:3px; 
}
.lighter, .light, .dark {
width:95%;
height:50px;
}
.rounded { 
border-radius:15px; 
-moz-border-radius:15px; 
-webkit-border-radius:15px; 
}

我的側邊欄是,這是我的app / views / layouts / application.html.erb,側邊欄由div內的內容表示:

<div class="col-md-2" id ="sidebar">
<div class="container2">

最后:app / views / layouts / application.html.erb:

<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></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 class="container">
<div class="row">
 <div class="col-md-9">
<% flash.each do |message_type, message| %>
    <div class="alert alert-<%= message_type %>"><%= message %></div>
  <% end %>
  <%= yield %>
    </div>
    <div class="col-md-2" id ="sidebar">
    <div class="container2">
 <br>
         <%= form_tag articles_path, :method => :get do   %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil, class: "btn btn-primary" %>
</p>
<% end %>   
         <!-- <form>
            <span><input type="text" class="search rounded" placeholder="Search..."></span>
           </form>
           -->
<hr>
<h3> Archives </h3>
<% if @posts.to_a.empty? %>
<div class="post">
<p>No articles found...</p>
</div>
<% else %>
<% current_month = 0 %>  
<% current_year = 0 %>
<% for article in @posts %> 
<% if (article.created_at.year != current_year)
 current_year = article.created_at.year %>
<h3 class="archiveyear"><%= article.created_at.year%></h3>
<% end %>
<% if (article.created_at.month != current_month || article.created_at.year != current_year) 
current_month = article.created_at.month 
current_year = article.created_at.year %>  
<h4 class="archivemonth"><%= (Date::MONTHNAMES[article.created_at.month]) %></h4>
<% end %>
<div class="archivepost">
<%= link_to article.title, article_path(article) %> posted on <%=     article.created_at.strftime('%A')%> - <%= article.created_at.strftime('%d') + "th"%>
</div>
<% end -%>
<%end %>
<hr>
<h3>Subscribe</h3>
<%= form_for(@subscriber) do |f| %>
  <%= render 'shared/error_messages' %>

  <%= f.label :name %>
  <%= f.text_field :name, class: 'form-control' %>

  <%= f.label :email %>
  <%= f.text_field :email, class: 'form-control' %>

<%= f.submit "Let me subscribe", class: "btn btn-primary" %>
<% end %>
<br>
<hr>
    </div>
    </sidebar>
    </p>
    </div>
    </div>
  <h6>
    <% if logged_in? %>
      <%= "Logged in as #{current_user.email}" %>
      <%= link_to "Log out", logout_path %>
    <% else %>
      <%= link_to "Log in", login_path %> if you are  one of our bloggers
    <% end %>
  </h6>
   </div>
   <%= render 'layouts/footer' %>
  <%= debug(params) if Rails.env.development? %>
   </body>

如何使用側邊欄進行滾動,以便查看其所有內容?

您必須在邊欄上設置一個高度,然后告訴溢出的內容滾動。 這樣的事情應該起作用:

#sidebar {
    height: 600px; /* or whatever height you want */
    overflow: scroll;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM