私はレールにドロップダウンメニューを構築しています。私は、application.html.erbファイルにメニューを持っています。そのすぐ下に、自分のコンテンツがどこにあるのか私の<%= yield%>タグがあります。私のドロップダウンメニューは、ヘッダーセクションの外に出てセクションエリアに行くと途切れてしまいます。私はオーバーフローをチェックしており、誰もそれを "隠す"ように設定していません。私は何が起こっているのか分からない。それが問題ならば、親は浮かんでいます。 誰かを助けることができますか?ここでドロップダウンメニューが終了する
は、問題の写真です:ここで
はCSSです。ここで
<!DOCTYPE html>
<html>
<head>
<title>BookApp</title>
<%= csrf_meta_tags %>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<header>
<h1>Book Reviews</h1>
<nav>
<div class="dropdown">
<img onclick="myFunction()" class="menu_icon" src="/assets/menu_icon.png">
<div id="myDropdown" class="dropdown-content">
<a class="hide_when_large" href="#home">Home</a>
<a class="hide_when_large" href="#about">Logout</a>
<a class="hide_when_large" href="#contact">Add Book</a>
</div>
</div>
<!--<%= image_tag 'menu_icon', :class => "menu_icon" %>-->
<% if user_signed_in? then %>
<%= link_to "Home", books_path, :class => "hide" %>
<% end %>
<% if user_signed_in? then %>
<%= link_to "Logout", destroy_user_session_path, method: :delete, :class => "hide" %>
<% else %>
<%= link_to "Login", new_user_session_path, :class => "hide" %>
<% end %>
<% if user_signed_in? then %>
<%= link_to "Add Book", new_book_path, :class => "hide" %>
<% end %>
</nav>
</header>
<%= yield %>
</body>
<script>
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.menu_icon')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
</script>
</html>
は私show.html.erbです:メディアはここ
@media only screen and (max-device-width: 546px) {
$darker-grey: #3e3e3e;
$dark-grey: #282828;
$gold: #ffd43e;
$light-grey: #b7b7b7;
a {
color: $light-grey;
font-family: arial;
}
body {
background-color: $dark-grey;
}
p {
color: white;
font-family: arial;
}
h1, h2, h3, h4, h5, h6 {
color: white;
font-family: arial;
}
label {
color: white;
font-family: arial;
display:inline;
font-style: italic;
}
header {
width: calc(100% - 70px);
padding: 35px;
background-color: black;
h1 {
font-size: 28px;
color: $gold;
float: left;
}
}
.alert {
color: red;
}
.book {
box-shadow: 0px 0px 20px black;
display: inline;
margin-left: auto;
margin-right: auto;
width: 230px;
height: 350px;
}
.book_show {
box-shadow: 0px 0px 20px black;
margin-right: 0px;
margin-bottom: 30px;
margin-left: auto;
margin-right: auto;
width: 300px;
display: inline;
}
.btn {
border: 2px solid $gold;
border-radius: 5px;
background-color: none;
padding-top: 10px;
padding-bottom: 10px;
width: 80px;
color: $gold;
text-align: center;
text-decoration: none;
display: inline-block;
margin-top: 20px;
margin-bottom: 20px;
font-family: arial;
}
.btn_left {
border: 2px solid $gold;
border-radius: 5px 0px 0px 5px;
background-color: none;
padding-top: 10px;
padding-bottom: 10px;
width: 80px;
color: $gold;
text-decoration: none;
display: inline-block;
margin-top: 20px;
margin-right: 0px;
font-family: arial;
}
.btn_right {
border: 2px solid $gold;
border-radius: 0px 5px 5px 0px;
background-color: none;
padding-top: 10px;
padding-bottom: 10px;
width: 80px;
color: $gold;
text-decoration: none;
display: inline-block;
margin-top: 20px;
margin-left: 0px;
font-family: arial;
}
.btn_center {
border: 2px solid $gold;
border-radius: 0px;
background-color: none;
padding-top: 10px;
padding-bottom: 10px;
width: 80px;
color: $gold;
text-decoration: none;
display: inline-block;
margin-top: 20px;
margin-left: 0px;
font-family: arial;
}
.btn_submit {
border-radius: 5px;
width: 150px;
margin-top: 20px;
padding-top: 13px;
padding-bottom: 13px;
background-color: $gold;
color: white;
border: 0px;
text-align: center;
text-decoration: none;
font-family: arial;
font-size: 16px;
display: inline-block;
}
.btn_submit:hover {
background-color: none;
margin-left: 0px;
}
.buttons {
text-align: center;
background-color: none;
padding-top:30px;
padding-bottom: 60px;
clear: left;
width: 323px;
}
.container_books_index {
margin-left: auto;
margin-right: auto;
width: 85%;
margin-bottom: 50px;
text-align:center;
background-color: none;
display: inline-block;
display: block;
}
.container_books_show {
width: 80%;
background-color: none;
text-align: center;
padding: 0px;
display: inline-block;
h4 {
margin-bottom: 20px;
padding-right: 20px;
}
h2 {
margin-bottom: 10px;
padding-right: 20px;
}
hr {
margin-right: 30px;
}
p {
margin-bottom: 10px;
padding-right: 20px;
}
.inner_left {
width: 323px;
background-color: none;
display: inline-block;
text-align: center;
margin-left: 0px;
margin-right: 0px;
}
}
.hide {
display: none;
}
.form_upload {
color: white;
}
.remember {
position: relative;
top: -48px;
left: 32px;
margin-bottom: 0px;
}
remember_label {
text-align: left;
width: 5px;
}
.field_with_errors {
color: red;
margin-bottom: 10px;
font-family: arial;
}
.form {
margin-top: 50px;
width: 50%;
margin-left: auto;
margin-right: auto;
h2 {
margin-bottom: 40px;
text-align: center;
}
p {
margin-bottom: 10px;
}
input {
margin-bottom: 30px;
width: 100%;
height: 20px;
border-radius: 5px;
padding: 5px;
}
textarea {
margin-bottom: 20px;
width: 100%;
height: 120px;
border-radius: 5px;
padding: 10px;
}
.submit {
width: 150px;
height: 40px;
margin-top: 20px;
background-color: $gold;
color: white;
border: 0px;
text-align: center;
font-size: 16px;
margin-left: 0px;
}
.submit:hover {
background-color: none;
margin-left: 0px;
}
span {
font-size: 13px;
font-style: italic;
}
}
.menu_icon {
background-color: none;
padding: 0px;
border: none;
cursor: pointer;
width: 30px;
float: right;
margin-top: 0px;
position: relative;
top: -10px;
}
.dropbtn:hover, .dropbtn:focus {
background-color: none;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
overflow: auto;
right: 0;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown a:hover {background-color: #f1f1f1}
.show {display:block;}
nav {
background-color: none;
padding-top: 13px;
float: right;
a {
color: $gold;
text-decoration: none;
font-family: arial;
margin-left: 30px;
}
}
.notice {
color: green;
}
section {
overflow: inherit;
width: 100%;
padding-top: 50px;
text-align: center;
background-color: none;
display: inline-block; /* Necessary to trigger "hasLayout" in IE */
display: block; /* Sets element back to block */
}
}
に照会し、私のapplication.html.erbファイルであると私はSASSを使用しています。それはすべてのビューで発生しますのでご注意ください、問題がapplication.html.erb
<section>
<div class="container_books_show">
<div class="inner_left">
<%= image_tag @book.book_img.url, :class => "book_show" %>
<div class="buttons">
<% if user_signed_in? then %>
<% if current_user.id = @book.user_id %>
<%= link_to "Edit", edit_book_path, :class => "btn_left" %>
<%= link_to "Delete", book_path(@book), method: :delete, :class => "btn_right", data: {confirm: "Are you sure?"} %>
<% end %>
<% end %>
<br />
<%= link_to "Back", root_path, :class => "btn" %>
<br />
<%= link_to "Add Review", new_book_review_path(@book) , :class => "btn_submit" %>
</div>
</div>
<h2 class="title"><%= @book.title %></h2>
<h4><%= @book.author %></h4>
<div class="average-review-rating" data-score=<%= @average_review %>></div>
<label>Average Rating</label>
<br />
<br />
<p><%= @book.description %></p>
<br />
<% if @book.reviews.count >= 1 %>
<h4>Reviews</h4>
<% end %>
<%= render @book.reviews %>
</div>
</section>
<script>
$('.review-rating').raty({
readOnly: true,
score: function() {
return $(this).attr('data-number');
},
path: '/assets/'
});
</script>
<script>
$('.average-review-rating').raty({
readOnly: true,
path: '/assets/',
score: function() {
return $(this).attr('data-score')
}
});
</script>
私はそれを試しても機能しませんでした。私はこれで完全に困惑しています。 –