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

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

新規登録して質問してみよう
ただいま回答率
85.48%
CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

Q&A

解決済

1回答

2109閲覧

display: grid;でのjustify-selfが効かない

Iori

総合スコア55

CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

0グッド

0クリップ

投稿2022/10/31 13:35

前提

YouTubeの
Responsive hero | Build a responsive website from scratch (Part 7)
https://www.youtube.com/watch?v=oR4y973fDQ4&t=777s
34:00あたりにきてます。

実現したいこと

copyrightを右に寄せたいです。
お手本の動画
イメージ説明

発生している問題・エラーメッセージ

現状
イメージ説明

該当のソースコード

該当箇所に🙋🙋マークがあります。

html

1 <div class="footer__cta"> 2 <a href="#" class="button">Request invite<a> 3 4 </div> 5 6 <div class="footer__copyright"> 7 <!-- ⭐特殊記号!! --> 8 &copy; EasyBank. All Rights Reserved.</div> 9

footer.css

1.footer { 2 background-color: #2D314D; 3 color: white; 4 text-align: center; 5 padding: 2.5rem; 6} 7 8.footer a { 9 color: white; 10 11} 12 13 14.footer__logo { 15 /* 7/7 19:10 the margin did 16work for the other elements because those are divs and is by nature they are 17by default display block elements */ 18 display: inline-block; 19 margin-bottom: 1.875rem; 20 21} 22 23 24 25.footer__social { 26 margin-bottom: 1.875rem; 27} 28 29.footer__social a { 30 display: inline-block; 31} 32 33/* 7/7 20:00⭐not last-childがないときれいにセンターにならない */ 34.footer__social a:not(:last-child) { 35 margin-right: 1rem 36} 37 38 39.footer__links { 40 41 display: flex; 42 /* ⭐7/7 21:00 */ 43 flex-direction: column; 44 /* because it's vertical align items should control the width of 45the children */ 46align-items: center; 47 48} 49 50.footer__links a { 51 /* a 自体にline-height */ 52 line-height: 2.5; 53} 54 55.col1 { 56} 57 58.col2 { 59 /* margin-bottom: 1.875rem; */ 60} 61 62.footer__cta { 63 margin: 1.875rem; 64 65} 66 67🙋🙋 68.footer__copyright { 69 font-size: 0.8125rem; 70 color: hsl(233, 8%, 62%); 71 72} 73 74.attribution { 75 margin-top: 1.875rem; 76 77} 78 79

mixin.css

1@media screen and (min-width: 768px) { 2 3 .footer__links { 4 align-items: baseline; 5 } 6 7 8 /* grid */ 9 .grid-container { 10 display: grid; 11 grid-template-columns: 2fr 1fr 1fr 3fr; 12 /* grid-template-rows: repeat(2, 1fr); */ 13 grid-template-rows: 1fr auto; 14 grid-template-areas: 15 /* 複数のrowを同じのがまたぐときは2回言う */ 16 "logo links1 links2 cta" 17 "social links1 links2 copyright"; 18 19 justify-items: start; 20 text-align: left; 21 22 23 } 24 25 .footer__logo { 26 grid-area: logo; 27 } 28 29 .col1 { 30 grid-area: links1; 31 } 32 33 .col2 { 34 grid-area: links2; 35 36 37 } 38 39 .footer__cta { 40 grid-area: cta; 41 42 /* margin: 0 0 1.875rem 0; */ 43 justify-self: end; 44 text-align: right; 45 46 } 47 48 .footer__social { 49 grid-area: social; 50 51 } 52 53🙋🙋 54 .footer__copyright { 55 grid-area: copyright; 56 57 justify-self: end; 58 text-align: right; 59 } 60 61} 62

試したこと

mixin.css内で

mixin.css

1 .footer__copyright { 2 grid-area: copyright; 3 4 display: flex; 5 justify-self: end; 6 }

をしてみましたが、変わりませんでした。。。

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

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

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

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

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

hatena19

2022/10/31 23:56

現象を再現できるコードを提示してください。 HTMLに grid-containerクラスがないので、再現できません。 あと、a要素の閉じタグがないのでまずはそれを修正してみてください。
Iori

2022/11/01 00:12

ありがとうございます。</a>に直したら正常に表示されました。
guest

回答1

0

ベストアンサー

a要素の閉じタグがないのを修正して、grid-containerクラスのブロックで囲んだら、justify-self: end; は効きましたよ。

html

1<div class="grid-container"> 2 <div class="footer__cta"> 3 <a href="#" class="button">Request invite</a><!-- 閉じタグに修正!! --> 4 </div> 5 6 <div class="footer__copyright"> 7 <!-- ⭐特殊記号!! --> 8 &copy; EasyBank. All Rights Reserved. 9 </div> 10</div>

投稿2022/11/01 00:19

hatena19

総合スコア33715

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問