いつもお世話になります。
現在自作のサイトを作成しているところですが、CSSが効かない現象が起きています。
ネット上で解決策を探し、試してみたものの効かない現象がつづいています。
CSS上での記述の仕方が悪いのか、そもそもCSSのファイルが読み込まれていないのかどちらが原因なのか、わかりません。
どなたかご助言をいただけると嬉しいです。
実現したいこと
以下の投稿一覧の投稿一つ一つを線で区切り、かつ中央に表示したい。(インスタグラムのようなイメージ)
現在のコードの状態
application.scss
@import "bootstrap-sprockets";
@import "bootstrap";
@import "base";
@import "posts";
@import "comments";
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
* = require font-awesome
*/
index.html.erb
<%= stylesheet_link_tag 'index', :media => "all" %>
<div id="recipe_content_wrapper">
<h1>投稿一覧</h1>
<div class="ml-auto posts_button">
<%= form_tag posts_path, method: :get, class: 'posts__searchForm' do %>
<%= select_tag :tag_id,
options_from_collection_for_select(Tag.all, :id, :name, params[:tag_id]),
{
prompt: 'タグで絞り込み',
class: 'form-control posts__select',
onchange: 'submit(this.form);'
}
%>
<% end %>
<%= link_to '投稿', new_post_path, class: "btn btn-outline-info" %>
</div>
<% if flash[:notice] %>
<div class="alert alert-primary"><%= flash[:notice] %></div>
<% end %>
<div id="recipe_list_wrapper">
<div id="recipe_list">
<% @posts.each do |post| %>
<div class="post.title"><%= post.title %></div>
<div class="post.picture"><%= image_tag post.picture.to_s %></div>
<p>by</p><div class="post.user"><%= link_to post.user.name, post.user %></div>
<div class="post.time"><%= post.created_at.to_s(:datetime_base) %></div>
<div class="btn btn-outline-info"><%= link_to "詳細" , post %></div>
<div class="btn btn-outline-info"><%= link_to "削除" , post , method: :delete, data: {confirm: "投稿記事を削除しますか?", cancel: "キャンセル", commit: "削除する", title: "削除の確認"} %></div>
<% end %>
</div>
</div>
</div>
</div>
index.scss
※ほかにもbase.scssなどのファイルがあるが、indexページのCSSのために新規で作成したscssファイルです。
.recipe_list{
margin: 0 auto;
solid: 1px;
}
.recipe_list_wrapper{
margin: 0 auto;
solid: 1px;
}
assets.rb
(略)
Rails.application.config.assets.precompile += %w( home.scss )
Rails.application.config.assets.precompile += %w( base.scss )
Rails.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 です。
参考にしたサイト
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 過去に投稿した質問と同じ内容の質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 88.32%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
2018/11/29 12:49
いつもありがとうございます。基本的なところを押さえられていませんでした。助かりました。ありがとうございます。