質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

919閲覧

タブUIを作りたいのですが、表示がうまく行かない

kawasaki4563

総合スコア32

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2021/04/14 08:23

編集2021/04/14 09:02

ユーザー別投稿一覧ページを作っていて、そこに3つのタブUIを設けたいです。しかし挙動がおかしいです。

その様子
具体的には、

・投稿された動画 ・つぶやき(ツイート) ・ブログ

をタブUIでまとめて表示したいです
参考サイトは以下です。
CSS3-Only Tabbed Area

#問題のソースコード

一覧ページのビューファイル

<div class="content-wrapper"> <div class="content-block"> <div class="content"> <div class="user-about"> <div class="image"> <% if @user.image.attached? %> <%= image_tag @user.image %> <% else %> <%= image_tag 'no.user.png' %> <% end %> </div> <div class="profile"> <div class="name-history"> <div class="name"> <%= @user.nickname %> </div> <div class="mania-histry"> <%= "趣味歴:#{@user.mania_histry}年" %> </div> </div> <div class="enjoy-point"> <%= "楽しいポイント#{@user.enjoy_point}"%> </div> </div> </div> <div class="tabbed-area"> <ul class="tabs group"> <li><a href="#box-one">Tab 1</a></li> <li><a href="#box-two">Tab 2</a></li> <li><a href="#box-three">Tab 3</a></li> </ul> <div class="box-wrap"> <div id="box-one"> <% @posts.each do |post| %> <div class="text"> <h2><%= truncate(post.content, length:15) %></h2><%= link_to "コメントor続きをよむ", "/posts/#{post.id}" %> </div> <% if post.images.attached? %> <% post.images.each do |image| %> <div class = 'images'> <%= image_tag image.variant(resize: "1280x720"), class: "content-image" %> </div> <% end %> <% end %> <% end %> </div> <div id="box-two"> <% @movies.each do |movie| %> <div class="text"> <h2><%= truncate(movie.title, length:15) %></h2><%= link_to "コメントor続きをよむ", "/movies/#{movie.id}" %> <h3><%= truncate(movie.introduction, length:15) %></h3> <video src=<%= rails_blob_path(movie.movie) %> ,type='movie/mp4 movie/mov', controls> </div> <% end %> </div> <div id="box-three"> <% @blogs.each do |blog| %> </div> <div class="text"> <div class="title"> <h3>タイトル: <%= blog.title %></h3> </div> <h2><%= truncate(strip_tags(blog.body.to_s),length: 14) %></h2></h2><%= link_to "コメントor続きをよむ", "/blogs/#{blog.id}" %> </div> <% end %> </div> </div> </div> </div> <div class="sidebar"> <%= render 'shared/menu'%> </div> </div> </div> </div> </div>

ビューファイルのCSS

#registrations-new, #sessions-new, #registrations-create,#passwords-new, #registrations-edit{ h2{ text-align: center; } input[type='email'],input[type='password'],input[type='number'], input[type= 'text']{ width: 100%; padding: 5px; border-radius: 5px; border: 1px solid #ccc; appearance: none; -webkit-appearance: none; -moz-appearance: none; } .field{ margin: 10px 0; } .actions{ margin: 15px auto; width: 150px; .button{ display : inline-block; border-radius : 5%; /* 角丸 */ font-size : 18pt; /* 文字サイズ */ text-align : center; /* 文字位置 */ cursor : pointer; /* カーソル */ padding : 12px 12px; /* 余白 */ background : #333; /* 背景色 */ color : #ffffff; /* 文字色 */ line-height : 1em; /* 1行の高さ */ transition : .3s; /* なめらか変化 */ box-shadow : 6px 6px 3px #666666; /* 影の設定 */ border : 2px solid #333; /* 枠の指定 */ } .button:hover { box-shadow : none; /* カーソル時の影消去 */ color : #333; /* 背景色 */ background : #ffffff; /* 文字色 */ } } } #profiles-new,#profiles-create, #profiles-edit{ form{ .fi{ margin: 10px 0; label{ margin-bottom: 5px; display: block; } input[type = 'text'],input[type = 'number']{ width: 100%; padding: 5px; border-radius: 5px; border: 1px solid #ccc; appearance: none; -webkit-appearance: none; -moz-appearance: none; } } .submit-block{ display: flex; align-items: center; justify-content: center; margin: 15px 0; .button { display : inline-block; border-radius : 5%; /* 角丸 */ font-size : 18pt; /* 文字サイズ */ text-align : center; /* 文字位置 */ cursor : pointer; /* カーソル */ padding : 12px 12px; /* 余白 */ background : #333; /* 背景色 */ color : #ffffff; /* 文字色 */ line-height : 1em; /* 1行の高さ */ transition : .3s; /* なめらか変化 */ box-shadow : 6px 6px 3px #666666; /* 影の設定 */ border : 2px solid #333; /* 枠の指定 */ } .button:hover { box-shadow : none; /* カーソル時の影消去 */ color : #333; /* 背景色 */ background : #ffffff; /* 文字色 */ } } } } #users-show{ .content{ border: 2px solid #000; padding: 15px; margin-bottom: 10px; .user-about{ display: flex; .tabs { list-style: none; } .tabs li { display: inline; } .tabs li a { color: black; float: left; display: block; padding: 4px 10px; margin-left: -1px; position: relative; left: 1px; background: white; text-decoration: none; } .tabs li a:hover { background: #ccc; } .group:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; } .box-wrap { position: relative; min-height: 250px; } .tabbed-area div div { background: white; padding: 20px; min-height: 250px; position: absolute; top: -1px; left: 0; width: 100%; } .tabbed-area div div, .tabs li a { border: 1px solid #ccc; } #box-one:target, #box-two:target, #box-three:target { z-index: 1; } .image{ width: 10%; } .profile{ margin-left: 10px; .name-history{ margin-bottom: 3px; display: flex; width: 100%; .name{ font-weight: bold; } .mania-histry{ margin-left: 20px; } } .enjoy-point{ width: 100%; font-size: 13px; } } } } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

自己解決しました
以下のサイトを参考にしてみたらできました。
CSSでタブ切り替えを実装する方法を現役エンジニアが解説【初心者向け】

投稿2021/04/14 13:15

kawasaki4563

総合スコア32

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問