質問編集履歴
3
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,142 +1,1 @@
|
|
1
|
-
## 解決したい問題
|
2
|
-
|
3
|
-
よくある3列横並びのカードUIを作っています。
|
4
|
-
カードの構成としては
|
5
|
-
|
6
|
-
```
|
7
|
-
------- ------- -------
|
8
|
-
| | | | | |
|
9
|
-
| | | | | |
|
10
|
-
| | | | | |
|
11
|
-
------- ------- -------
|
12
|
-
|
13
|
-
```
|
14
|
-
のようになっていて、カードの中に上から
|
15
|
-
* 画像
|
16
|
-
* タイトル
|
17
|
-
* カテゴリ名
|
18
|
-
が入っています。
|
19
|
-
カードの横並びは `display:flex`を使って実現しています。
|
20
|
-
|
21
|
-
タイトルが長くなった時に
|
22
|
-
|
23
|
-
画像 画像
|
24
|
-
|
25
|
-
タイトル タイトル
|
26
|
-
タイトル タイトル
|
27
|
-
タイトル
|
28
|
-
カテゴリ
|
29
|
-
カテゴリ
|
30
|
-
|
31
|
-
のように位置がずれてしまいます。(カードそのものの高さは `display:flex` を使っているので揃っています。・
|
32
|
-
タイトルのmax行を決めれば問題はなくなる気がするのですが、運用上それだとダメかもしれないので、位置がずれないようにするにはどうしたらいいかご指導いただけると幸いです。
|
33
|
-
|
34
|
-
|
1
|
+
一部不具合を含んだコードや誤った記述があったため、質問を削除しました。再度調べ直して投稿します。
|
35
|
-
|
36
|
-
```HTML
|
37
|
-
<div class="news-content-cards">
|
38
|
-
<% articles.each do |article| %>
|
39
|
-
<%= link_to article.url(relative: true), class: "news-content-card" do %>
|
40
|
-
<% if cms_fragment_content(:hero_image, article).present? %>
|
41
|
-
<%= image_tag cms_fragment_content(:hero_image, article).first.variant(resize: '480x270').processed, class: "news-content-card-image", alt: "#{cms_fragment_content(:title, article)}>" %>
|
42
|
-
<% else %>
|
43
|
-
<%= image_tag "pages/cms/news/image.png", class: "news-content-card-image" %>
|
44
|
-
<% end %>
|
45
|
-
<div class="news-content-card-info">
|
46
|
-
<p class="news-date"><%= cms_fragment_content(:publish_date, article) %></p>
|
47
|
-
<h3 class="news-title"><%= cms_fragment_content(:title, article) %></h3>
|
48
|
-
<p class="news-category">
|
49
|
-
<% article.categories.each do |article_category| %>
|
50
|
-
<%= article_category.label %>
|
51
|
-
<% end %>
|
52
|
-
</p>
|
53
|
-
</div>
|
54
|
-
<% end %>
|
55
|
-
<% end %>
|
56
|
-
</div>
|
57
|
-
```
|
58
|
-
|
59
|
-
```SCSS
|
60
|
-
.news-content-cards {
|
61
|
-
display: flex;
|
62
|
-
flex-wrap: wrap;
|
63
|
-
|
64
|
-
@media screen and (max-width: 767px) {
|
65
|
-
display: block;
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
.news-content-card {
|
70
|
-
background: $WHITE;
|
71
|
-
border-radius: 12px;
|
72
|
-
max-width: 330px;
|
73
|
-
margin: 0 32px 32px 0;
|
74
|
-
box-shadow: 0px 4px 24px rgba($RICH_BLACK, 0.15);
|
75
|
-
transition: all 0.2s;
|
76
|
-
display: block;
|
77
|
-
|
78
|
-
@media screen and (max-width: 1200px) {
|
79
|
-
width: calc((100% - 64px) / 3);
|
80
|
-
}
|
81
|
-
|
82
|
-
@media screen and (max-width: 767px) {
|
83
|
-
max-width: 350px;
|
84
|
-
margin: 0 0 32px;
|
85
|
-
width: auto;
|
86
|
-
}
|
87
|
-
|
88
|
-
@media screen and (max-width: 414px) {
|
89
|
-
margin: 0 auto 32px;
|
90
|
-
}
|
91
|
-
|
92
|
-
&:hover,
|
93
|
-
&:focus {
|
94
|
-
box-shadow: 0px 4px 36px rgba($RICH_BLACK, 0.3);
|
95
|
-
}
|
96
|
-
|
97
|
-
&:active {
|
98
|
-
box-shadow: 0px 4px 16px rgba($RICH_BLACK, 0.3);
|
99
|
-
}
|
100
|
-
|
101
|
-
&:nth-of-type(3n) {
|
102
|
-
margin: 0 0 32px;
|
103
|
-
|
104
|
-
@media screen and (max-width: 414px) {
|
105
|
-
margin: 0 auto 32px;
|
106
|
-
}
|
107
|
-
}
|
108
|
-
}
|
109
|
-
|
110
|
-
.news-content-card-image {
|
111
|
-
border-radius: 12px 12px 0 0;
|
112
|
-
}
|
113
|
-
|
114
|
-
.news-content-card-info {
|
115
|
-
padding: 24px;
|
116
|
-
}
|
117
|
-
|
118
|
-
.news-date {
|
119
|
-
font-size: 16px;
|
120
|
-
line-height: 16px;
|
121
|
-
margin-bottom: 8px;
|
122
|
-
color: $DARK_GRAY;
|
123
|
-
letter-spacing: 0.03em;
|
124
|
-
}
|
125
|
-
|
126
|
-
.news-title {
|
127
|
-
font-weight: bold;
|
128
|
-
font-size: 18px;
|
129
|
-
line-height: 24px;
|
130
|
-
color: $DARK_GRAY;
|
131
|
-
margin-bottom: 24px;
|
132
|
-
letter-spacing: 0.05em;
|
133
|
-
}
|
134
|
-
|
135
|
-
.news-category {
|
136
|
-
font-weight: bold;
|
137
|
-
font-size: 16px;
|
138
|
-
line-height: 16px;
|
139
|
-
color: $SPANISH_GRAY;
|
140
|
-
}
|
141
|
-
|
142
|
-
```
|
2
コード追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -29,4 +29,114 @@
|
|
29
29
|
カテゴリ
|
30
30
|
|
31
31
|
のように位置がずれてしまいます。(カードそのものの高さは `display:flex` を使っているので揃っています。・
|
32
|
-
タイトルのmax行を決めれば問題はなくなる気がするのですが、運用上それだとダメかもしれないので、位置がずれないようにするにはどうしたらいいかご指導いただけると幸いです。
|
32
|
+
タイトルのmax行を決めれば問題はなくなる気がするのですが、運用上それだとダメかもしれないので、位置がずれないようにするにはどうしたらいいかご指導いただけると幸いです。
|
33
|
+
|
34
|
+
Railsのコードも混ざっているんですが、HTMLとSCSSも載せておきます。
|
35
|
+
|
36
|
+
```HTML
|
37
|
+
<div class="news-content-cards">
|
38
|
+
<% articles.each do |article| %>
|
39
|
+
<%= link_to article.url(relative: true), class: "news-content-card" do %>
|
40
|
+
<% if cms_fragment_content(:hero_image, article).present? %>
|
41
|
+
<%= image_tag cms_fragment_content(:hero_image, article).first.variant(resize: '480x270').processed, class: "news-content-card-image", alt: "#{cms_fragment_content(:title, article)}>" %>
|
42
|
+
<% else %>
|
43
|
+
<%= image_tag "pages/cms/news/image.png", class: "news-content-card-image" %>
|
44
|
+
<% end %>
|
45
|
+
<div class="news-content-card-info">
|
46
|
+
<p class="news-date"><%= cms_fragment_content(:publish_date, article) %></p>
|
47
|
+
<h3 class="news-title"><%= cms_fragment_content(:title, article) %></h3>
|
48
|
+
<p class="news-category">
|
49
|
+
<% article.categories.each do |article_category| %>
|
50
|
+
<%= article_category.label %>
|
51
|
+
<% end %>
|
52
|
+
</p>
|
53
|
+
</div>
|
54
|
+
<% end %>
|
55
|
+
<% end %>
|
56
|
+
</div>
|
57
|
+
```
|
58
|
+
|
59
|
+
```SCSS
|
60
|
+
.news-content-cards {
|
61
|
+
display: flex;
|
62
|
+
flex-wrap: wrap;
|
63
|
+
|
64
|
+
@media screen and (max-width: 767px) {
|
65
|
+
display: block;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
.news-content-card {
|
70
|
+
background: $WHITE;
|
71
|
+
border-radius: 12px;
|
72
|
+
max-width: 330px;
|
73
|
+
margin: 0 32px 32px 0;
|
74
|
+
box-shadow: 0px 4px 24px rgba($RICH_BLACK, 0.15);
|
75
|
+
transition: all 0.2s;
|
76
|
+
display: block;
|
77
|
+
|
78
|
+
@media screen and (max-width: 1200px) {
|
79
|
+
width: calc((100% - 64px) / 3);
|
80
|
+
}
|
81
|
+
|
82
|
+
@media screen and (max-width: 767px) {
|
83
|
+
max-width: 350px;
|
84
|
+
margin: 0 0 32px;
|
85
|
+
width: auto;
|
86
|
+
}
|
87
|
+
|
88
|
+
@media screen and (max-width: 414px) {
|
89
|
+
margin: 0 auto 32px;
|
90
|
+
}
|
91
|
+
|
92
|
+
&:hover,
|
93
|
+
&:focus {
|
94
|
+
box-shadow: 0px 4px 36px rgba($RICH_BLACK, 0.3);
|
95
|
+
}
|
96
|
+
|
97
|
+
&:active {
|
98
|
+
box-shadow: 0px 4px 16px rgba($RICH_BLACK, 0.3);
|
99
|
+
}
|
100
|
+
|
101
|
+
&:nth-of-type(3n) {
|
102
|
+
margin: 0 0 32px;
|
103
|
+
|
104
|
+
@media screen and (max-width: 414px) {
|
105
|
+
margin: 0 auto 32px;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
.news-content-card-image {
|
111
|
+
border-radius: 12px 12px 0 0;
|
112
|
+
}
|
113
|
+
|
114
|
+
.news-content-card-info {
|
115
|
+
padding: 24px;
|
116
|
+
}
|
117
|
+
|
118
|
+
.news-date {
|
119
|
+
font-size: 16px;
|
120
|
+
line-height: 16px;
|
121
|
+
margin-bottom: 8px;
|
122
|
+
color: $DARK_GRAY;
|
123
|
+
letter-spacing: 0.03em;
|
124
|
+
}
|
125
|
+
|
126
|
+
.news-title {
|
127
|
+
font-weight: bold;
|
128
|
+
font-size: 18px;
|
129
|
+
line-height: 24px;
|
130
|
+
color: $DARK_GRAY;
|
131
|
+
margin-bottom: 24px;
|
132
|
+
letter-spacing: 0.05em;
|
133
|
+
}
|
134
|
+
|
135
|
+
.news-category {
|
136
|
+
font-weight: bold;
|
137
|
+
font-size: 16px;
|
138
|
+
line-height: 16px;
|
139
|
+
color: $SPANISH_GRAY;
|
140
|
+
}
|
141
|
+
|
142
|
+
```
|
1
修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
カードの中身の位置を揃えたい
|
1
|
+
【CSS】カードの中身の位置を揃えたい
|
body
CHANGED
File without changes
|