いつもお世話になります。
現在自作のサイトを作成しているところですが、CSSが効かない現象が起きています。
ネット上で解決策を探し、試してみたものの効かない現象がつづいています。
CSS上での記述の仕方が悪いのか、そもそもCSSのファイルが読み込まれていないのかどちらが原因なのか、わかりません。
どなたかご助言をいただけると嬉しいです。
##実現したいこと
以下の投稿一覧の投稿一つ一つを線で区切り、かつ中央に表示したい。(インスタグラムのようなイメージ)
##現在のコードの状態
application.scss
rb
1@import "bootstrap-sprockets"; 2@import "bootstrap"; 3@import "base"; 4@import "posts"; 5@import "comments"; 6 7/* 8 * This is a manifest file that'll be compiled into application.css, which will include all the files 9 * listed below. 10 * 11 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 12 * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. 13 * 14 * You're free to add application-wide styles to this file and they'll appear at the bottom of the 15 * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 16 * files in this directory. Styles in this file should be added after the last require_* statement. 17 * It is generally better to create a new file per style scope. 18 19 * = require font-awesome 20*/
index.html.erb
rb
1<%= stylesheet_link_tag 'index', :media => "all" %> 2 3<div id="recipe_content_wrapper"> 4 <h1>投稿一覧</h1> 5 <div class="ml-auto posts_button"> 6 <%= form_tag posts_path, method: :get, class: 'posts__searchForm' do %> 7 <%= select_tag :tag_id, 8 options_from_collection_for_select(Tag.all, :id, :name, params[:tag_id]), 9 { 10 prompt: 'タグで絞り込み', 11 class: 'form-control posts__select', 12 onchange: 'submit(this.form);' 13 } 14 %> 15 <% end %> 16 <%= link_to '投稿', new_post_path, class: "btn btn-outline-info" %> 17 </div> 18 19 <% if flash[:notice] %> 20 <div class="alert alert-primary"><%= flash[:notice] %></div> 21 <% end %> 22 23 <div id="recipe_list_wrapper"> 24 <div id="recipe_list"> 25 <% @posts.each do |post| %> 26 27 <div class="post.title"><%= post.title %></div> 28 <div class="post.picture"><%= image_tag post.picture.to_s %></div> 29 <p>by</p><div class="post.user"><%= link_to post.user.name, post.user %></div> 30 <div class="post.time"><%= post.created_at.to_s(:datetime_base) %></div> 31 <div class="btn btn-outline-info"><%= link_to "詳細" , post %></div> 32 <div class="btn btn-outline-info"><%= link_to "削除" , post , method: :delete, data: {confirm: "投稿記事を削除しますか?", cancel: "キャンセル", commit: "削除する", title: "削除の確認"} %></div> 33 <% end %> 34 </div> 35 </div> 36 </div> 37</div> 38
index.scss
※ほかにもbase.scssなどのファイルがあるが、indexページのCSSのために新規で作成したscssファイルです。
rb
1.recipe_list{ 2 margin: 0 auto; 3 solid: 1px; 4} 5 6.recipe_list_wrapper{ 7 margin: 0 auto; 8 solid: 1px; 9} 10
assets.rb
rb
1 2(略) 3Rails.application.config.assets.precompile += %w( home.scss ) 4Rails.application.config.assets.precompile += %w( base.scss ) 5Rails.application.config.assets.precompile += %w( index.scss )
##試したこと
・aplication.scssからrequire_tree .とrequire_selfを削除
・assets.rbに個別に読み込みたいscssを定義
・ビュー側に読み込むアセットを設定
##実行環境
AWSのcloud9を使用しています。
rubyのバージョンは 2.4.1p111
railsのバージョンはRails 5.0.7 です。
##参考にしたサイト
【Ruby on Rails】ページごとに、読み込まれるCSSとJavaScriptを変えるには?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/29 03:49