実現したい事
現在、ejsを使用しながらHPを作成しております。
似たようなコンテンツが多いのでforEachを使ってまとめて書きたいと考えました。
しかし、上手く行かずハマっているので、是非ご教授頂きたいです。
ちなみに完成形のイメージとしてはこちらです。↓
発生している問題・エラーメッセージ
現状はこんな感じになっています。↓
一つのboxで各画像を12回繰り返している感じになっています。
該当のソースコード
index.ejs
1<% var title= "TOP"; var description = "トップのdescription"; %> 2<% var mainName = ['01','04','06','08','10','12','14','14','14','14','14','14']; %> 3<% var mainIcon = ['46','48','50','52','54','56','58','60','62','63','65','66']; %> 4<% var mainTitle = ['16','19','21','23','26','28','31','33','35','37','40','43']; %> 5 6<% include src/ejs/template/_head %> 7 <div class="l-main"> 8 <% include src/ejs/template/_sidebar %> 9 <div class="l-main__menu"> 10 <% for (var i = 0; i < 12; i++) { %> 11 <div class="p-menuBox"> 12 <% mainName.forEach(function (value) { %> 13 <div class="p-menuBox__name"><img src="../assets/images/mainmenu/menu/spr_top01_<%= value %>.png"></div> 14 <% }); %> 15 <div class="p-menuBox__inner"> 16 <% mainIcon.forEach(function (value) { %> 17 <div class="p-menuBox__icon"><img src="../assets/images/mainmenu/icon/spr_top01_<%= value %>.png"></div> 18 <% }); %> 19 <% mainTitle.forEach(function (value) { %> 20 <div class="p-menuBox__title"><img src="../assets/images/mainmenu/menu2/spr_top01_<%= value %>.png"></div> 21 <% }); %> 22 <div class="p-menuBox__text"> 23 <p>グッピーズは、人材採用をITで革新し続ける企業です。</p> 24 </div> 25 </div> 26 </div><% } %> 27 28 </div> 29 30 31 32<% include src/ejs/template/_footer %> 33
_menuBox.scss
1.p-menuBox { 2 display: flex; 3 flex-wrap: wrap; 4 justify-content: center; 5 align-items: flex-start; 6 height: 230px; 7 width: 230px; 8 border: solid 1px #cc9933; 9 10 &:nth-of-type(n + 4) { 11 margin-top: 10px; 12 } 13 14 &:hover { 15 background-color: #bbb; 16 } 17 18 #{&}__name { 19 display: inline-block; 20 width: 100%; 21 height: 15px; 22 margin-top: 10px; 23 } 24 25 #{&}__inner { 26 display: flex; 27 flex-wrap: wrap; 28 justify-content: center; 29 width: 200px; 30 } 31 32 #{&}__icon { 33 width: 80px; 34 height: 80px; 35 } 36 37 #{&}__title { 38 margin-top: 10px; 39 width: 100%; 40 height: 20px; 41 } 42 43 #{&}__text { 44 margin-top: 10px; 45 font-size: 5px; 46 font-size: 0.5rem; 47 } 48} 49
なぜこうなっているのか現在原因を究明している所です。
詳しい方ございましたら、アドバイスまた参考サイトをご教授頂けますと幸いです。
補足情報(FW/ツールのバージョンなど)
・npm -v 6.9.0
・node -v 12.6.0
・webpack -v 5.65.0
・ yarn -v 1.22.17

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。