現在投稿後に、トップページに表示させる実装をしているのですが、1投稿目のレイアウトが2投稿目の子要素として表示されてしまいます。
すべての投稿が縦にズレることなく表示させるにはどのようにレイアウトを修正すればよろしいでしょうか。
■■な機能を実装中に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
具体的には、下記の画像のようになります。
https://gyazo.com/2990e199fde01906518a7ad501eb5fc3
**<div class="content-page">に投稿されたものが表示されるようにしているのですが、1枚目の投稿が2枚目に投稿された<div class="content-page">**の子要素として表示されているためにレイアウトにズレが起きてしまっております。
erb
1<div class="content-page"> 2 <div class="upload-contents-wrapper">..</div> 3 <div class="content-page">...</div> 4</div>
該当のソースコード
app/views/uploads/index.html.erb
erb
1<%= render "shared/header" %> 2 3 <div id class="main-page"> 4 <div class="search-content"> 5 <form method="get" action="#" class="search_container"> 6 <input type="text" size="75" placeholder=" タグや地名で検索"> 7 <input type="submit" value=""> 8 </form> 9 </div> 10 <div class="title-content"> 11 <h1 class="main-title">新規カフェ情報一覧</h1> 12 </div> 13 <div class="main-content"> 14 <div class="main-content__category"> 15 <!-- 後から実装--> 16 </div> 17 <div id="content-table"> 18 <% @uploads.each do |upload| %> 19 <div class="content-page"> 20 <%= link_to upload_path(upload.id), class: "upload-link", method: :get do %> 21 <div class="upload-contents-wrapper"> 22 <div class="upload-img-contents"> 23 <%= image_tag upload.image, class: "upload-img" if upload.image.attached? %> 24 </div> 25 <div class="upload-contents-detail"> 26 <div class="upload-name"><%= upload.title %></div> 27 <% upload.tags.each do |tag| %> 28 <div class="upload-tags">#<%= tag.name %></div> 29 <% end %> 30 </div> 31 <div class="upload-contents-explain"> 32 <div class="upload-explain"><%= upload.text %></div> 33 </div> 34 <p class="upload-user"> 35 <a class="user-name__image" href="#"> 36 <img src="assets/image-4.jpg" width="40" height="40" alt=""> 37 </a> 38 <%= link_to upload.user.name, "#", class: "upload-user__name" %> 39 </p> 40 </div> 41 <% end %> 42 <% end %> 43 </div> 44 </div> 45 </div> 46 </div> 47 <%= link_to('uploads/new', class: 'uploads-btn') do %> 48 <%= image_tag 'post.png', size: '70x70', class: "uploads-btn-icon" %> 49 <% end %> 50</div>
app/assets/styesheets/uploads/index.scss
css
1////// Place all the styles related to the uploads controller here. 2////// They will automatically be included in application.scss. 3////// You can use Sass (SCSS) here: https://sass-lang.com/ 4$white: white; 5$black: black; 6 7//スライドページ 8 9*:focus { 10 outline: none; 11} 12 13#top-container { 14 height: 450px; 15 padding: 10px 0; 16 overflow: hidden; 17 background: #BBBBBB; 18 position: relative; 19} 20 21.top-wrapper { 22 width: 100%; 23 height: 100%; 24 overflow: hidden; 25 display: flex; 26} 27 28.top-slide { 29 width: 630px; 30 height: 100%; 31 float: left; 32 background: $white; 33 margin: 0 4px; 34 z-index: 1; 35} 36 37.top-image { 38 height: 260px; 39 overflow: hidden; 40 background-color: $white; 41 42 & > img { 43 height: 100%; 44 width: 100%; 45 } 46} 47 48.projects-detail { 49 padding: 18px 20px 20px; 50 background-color: $white; 51 position: relative; 52} 53 54.icon-name { 55 text-align: center; 56 width: 100%; 57 font-weight: 600; 58 padding-left: 20px; 59 display: flex; 60 justify-content: space-between; 61 62 &__style { 63 font-size: 25px; 64 color: black; 65 font-weight: bold; 66 background-image: linear-gradient(to right, rgba(0, 0, 0, 0) 50%, white 50%); 67 background-position: 0 0; 68 background-size: 200% auto; 69 transition: 0.5s; 70 text-decoration: none; 71 72 &:hover { 73 background-position: -100% 0; 74 color: cadetblue; 75 } 76 } 77 78 &__tag { 79 border: 2px solid; 80 color: grey; 81 border-radius: 40%; 82 padding: 10px 10px; 83 } 84} 85 86.user-name { 87 padding-left: 40px; 88 font-weight: 300; 89 bottom: 20px; 90 line-height: 10px; 91 display: flex; 92 93 &__detail { 94 margin-left: 10px; 95 font-size: 18px; 96 font-weight: bold; 97 color: $black; 98 display: inline-block; 99 position: relative; 100 line-height: 40px; 101 text-decoration: none; 102 background-image: linear-gradient(to right, rgba(0, 0, 0, 0) 50%, white 50%); 103 background-position: 0 0; 104 background-size: 200% auto; 105 transition: 0.5s; 106 107 &:hover { 108 background-position: -100% 0; 109 color: cadetblue; 110 } 111 112 &::after { 113 position: absolute; 114 bottom: -4px; 115 left: 0; 116 content: ''; 117 width: 100%; 118 height: 2px; 119 background: #333; 120 transform: scale(0, 1); 121 transform-origin: left top; 122 transition: transform .3s; 123 } 124 125 &:hover::after { 126 transform: scale(1, 1); 127 } 128 } 129 130 &__image { 131 132 & > img { 133 border-radius: 50%; 134 text-decoration: none; 135 } 136 } 137} 138 139//検索フォーム 140 141.search-content { 142 padding: 48px 40px; 143 align-items: center; 144 display: flex; 145} 146 147.search_container { 148 margin: 0 auto; 149 position: relative; 150 box-sizing: border-box; 151 display: block; 152 padding: 3px 10px; 153 border-radius: 20px; 154 height: 2.2em; 155 width: 400px; 156 overflow: hidden; 157 background: #3879D9; 158} 159 160.search_container input[type="text"] { 161 border: none; 162 height: 2.0em; 163 background: #3879D9; 164} 165 166.search_container input[type="text"]:focus { 167 outline: 0; 168} 169 170.search_container input[type="submit"] { 171 cursor: pointer; 172 font-family: FontAwesome; 173 font-size: 1.3em; 174 border: none; 175 background: none; 176 color: #fff; 177 position: absolute; 178 height: 2.5em; 179 right: 8px; 180 top: -10px; 181 outline: none; 182} 183 184.search_container ::-webkit-input-placeholder { 185 color: #fff; 186} 187 188//メイン投稿一覧 189 190.title-content { 191 display: flex; 192} 193 194.main-title { 195 display: block; 196 margin: 0 auto; 197} 198 199.main-content { 200 display: flex; 201 width: 850px; 202 margin: 0 auto; 203 204 &__category { 205 padding-right: 30px; 206 background-color: beige; 207 width: calc(900px - 650px); 208 } 209} 210 211.content-page { 212 width: calc(900px - 250px); 213 padding: 20px 20px; 214 background-color: bisque; 215 height: 480px; 216} 217 218.upload-link { 219 text-decoration: none; 220 color: black; 221} 222 223.upload-contents-wrapper { 224 width: 100%; 225 height: 100%; 226 background-color: white; 227 filter: drop-shadow(0px 0px 10px black); 228} 229 230.upload-img-contents { 231 height: 250px; 232} 233 234.upload-img { 235 object-fit: cover; 236 width: 100%; 237 height: 100%; 238} 239 240.upload-contents-detail { 241 padding: 15px 12px; 242 display: flex; 243 justify-content: space-between; 244} 245 246.upload-name { 247 font-size: 25px; 248 font-weight: bold; 249 margin-left: 20px; 250} 251 252.upload-tags { 253 border: 1px solid gray; 254 border-radius: 10%; 255 padding: 8px 8px; 256 background: lightgoldenrodyellow; 257 color: gray; 258 font-weight: bold; 259 font-size: 15px; 260} 261 262.upload-contents-explain { 263 padding: 15px 12px; 264} 265 266.upload-explain { 267 margin-left: 20px; 268 color: gray; 269 font-size: 15px; 270} 271 272.upload-user { 273 margin: 15px 25px 5px; 274 275 &__name { 276 text-decoration: none; 277 font-weight: bold; 278 margin-left: 5px; 279 color: black; 280 } 281} 282//投稿ボタン 283 284.uploads-btn { 285 width: 100px; 286 background: #F7F7F7; 287 text-align: center; 288 border-radius: 5%; 289 bottom: 32px; 290 right: 32px; 291 position: fixed; 292 padding: 15px; 293} 294 295 296
試したこと
・** <% @uploads.each do |upload| %>の内部に<div class="content-page">**を置いてブラウズで確認してみたが、ズレの修正には至らなかった。
補足情報(FW/ツールのバージョンなど)
開発環境
・rubymine
・ruby(3.0.1)
・Ruby on rails (6.1.3.1)
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/05/13 09:24