質問するログイン新規登録

Q&A

解決済

1回答

114閲覧

ナビバーの要素を全て中央揃えにしたい

PythonNINJYA

総合スコア22

CSS3

CSS(Cascading Style Sheet)の第3版です。CSS3と略されることが多いです。色やデザインを柔軟に変更することが可能になります。

HTML5

HTML5 (Hyper Text Markup Language、バージョン 5)は、マークアップ言語であるHTMLの第5版です。

0グッド

0クリップ

投稿2026/01/21 08:26

編集2026/01/21 09:41

0

0

実現したいこと

画像とナビゲーション項目を全て中央に揃えたい

発生している問題・分からないこと

ナビゲーション項目が上下で中央揃えにならず、上にずれてしまう。(画像参照イメージ説明

該当のソースコード

HTML

1{% extends "base.html" %} 2 3{% block header %} 4<link rel="preconnect" href="https://fonts.googleapis.com"> 5<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> 6<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+JP:wght@200..900&display=swap" rel="stylesheet"> 7<link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet" type="text/css" media="all"/> 8<title>一種オンリー貯金サイト</title> 9{% endblock %} 10 11 12{% block content %} 13 <header class="entrance_header"> 14 <div class="header_inner"> 15 <a class="header_title" href="{{ url_for('index') }}"> 16 <img src="{{ url_for('static', filename='images/title_image_big.png') }}" alt= "一種オンリー貯金サイト"> 17 </a> 18 <div class="header_menu"> 19 <nav class="link_list"> 20 <ul> 21 <li><a href="#">CONCEPT</a></li> 22 <li><a href="#">FUNCTION</a></li> 23 <li><a href="#">LOGIN</a></li> 24 <li><a href="#">SIGNUP</a></li> 25 </ul> 26 </nav> 27 </div> 28 </div> 29 </header> 30 <main> 31 <div class="entrance_background"> 32 <p class="entrance_subtitle whitezone">今日も一枚。明日も一枚。</p> 33 <div class="buttons_container whitezone"> 34 <a class="entrance_button" href="{{ url_for('login') }}"><span class="text">LOGIN</span></a> 35 <a class="entrance_button" href="{{ url_for('register') }}"><span class="text">CREATE ACCOUNT</span></a> 36 </div> 37 </div> 38 <div class="entrance_info_container"> 39 <h2>このWebサイト(アプリケーション)の紹介</h2> 40 41 <p class="title">択べる硬貨は6種類</p> 42 <div class="info_container"> 43 <p class="texts"> 44 アカウントの登録時に<br> 45 日本円の1円、5円、10円、50円<br> 46 100円、500円から選ぶことが出来ます。<br> 47 目標とする枚数も決定できます。 48 </p> 49 <img class="image" src="{{ url_for('static', filename='images/kino_1.png') }}" alt= "イキスギィ!"> 50 </div> 51 52 <p class="title">履歴機能</p> 53 <div class="info_container"> 54 <p class="texts"> 55 毎日の貯金が目で見て分かるようになります。<br> 56 日付とその日に何枚貯金したか<br> 57 一目でわかります<br> 58 </p> 59 <img class="image" src="{{ url_for('static', filename='images/kino_2.png') }}" alt= "イキスギィ!"> 60 </div> 61 </div> 62 <main> 63 <footer> 64 </footer> 65{% endblock %}

CSS

1*, 2::before, 3::after{ 4 margin: 0; 5 padding: 0; 6 box-sizing: border-box; 7} 8 9body{ 10 font-family: Arial,serif,"Silkscreen"; 11 font-size: 16px; 12 line-height: 1; 13} 14 15img{ 16 max-width: 100%; 17} 18 19h1, 20h2{ 21 color: #333333; 22 text-align: center; 23 margin-top: 20px; 24} 25 26ul, 27ol{ 28 list-style: none; 29} 30 31a{ 32 color: inherit; 33 text-decoration: none; 34}

ヘッダー関連

css

1.entrance_header{ 2 padding-top: 0px; 3} 4 5.header_title{ 6 display: block; 7 width: 300px; 8} 9 10.header_inner{ 11 max-width: 1200px; 12 height: 50px; 13 margin-left: auto; 14 margin-right: auto; 15 padding-left: 40px; 16 padding-right: 40px; 17 display: flex; 18 justify-content: space-between; 19 align-items: center; 20} 21 22.header_menu ul{ 23 display: flex; 24} 25 26.header_menu ul li{ 27 margin-left: 20px; 28 margin-right: 20px; 29}

メインビジュアル(entrance_background)

css

1.entrance_background{ 2 background: url(../images/entrance_logo.jpg); 3 background-size: cover; 4 background-repeat: no-repeat; 5 background-position: top center; 6 width: 100%; 7 height: 350px; 8 position: relative; 9 display: flex; 10 justify-content: center; 11 border: solid 2px black; 12} 13 14.entrance_subtitle{ 15 font-size: 96px; 16 margin-top: 0.5em; 17 color: white; 18 text-align: center; 19} 20 21.entrance_background::before{ 22 content: ''; 23 background-color: rgba(0,0,0,.5); 24 position: absolute; 25 top: 0; 26 right: 0; 27 bottom: 0; 28 left: 0; 29} 30 31.entrance_background .whitezone{ 32 position: absolute; 33 color: #fff; 34} 35 36.buttons_container{ 37 text-align: center; 38 margin-top: 15em; 39 display: flex; 40 justify-content: center; 41 gap: 50px; 42 position: absolute; 43} 44 45.entrance_button{ 46 display: inline-block; 47 background: rgba(0,0,0,0); 48 width: 200px; 49 line-height: 50px; 50 color: white; 51 font-size: auto; 52 border: solid 2px white; 53 text-decoration: none; 54 -webkit-transition: 0.5s all; 55 transition: 0.5s all; 56 z-index: 1; 57} 58 59.entrance_button:hover{ 60 background: rgba(255,255,255,1); 61 color: black; 62 cursor: pointer; 63}

情報セクション(entrance_info_container)

css

1.entrance_info_container{ 2 margin-top: 50px; 3 background-color: #a3e4ff; 4 font-family: "Noto Serif JP"; 5 font-size: 36px; 6 padding-bottom: 20px; 7} 8 9.entrance_info_container .title{ 10 font-size: 72px; 11 text-align: left; 12 margin-top: 15px; 13} 14 15.entrance_info_container .info_container{ 16 display: flex; 17 justify-content: space-between; 18 margin : 0px 150px 0px 150px; 19 height : 5.5em; 20} 21 22.info_container .texts{ 23 font-size: 24px; 24 text-align: left; 25 color: black; 26 width: 50%; 27} 28 29.info_container img{ 30 width: 50%; 31 height: 100%; 32 object-fit: contain; 33 border-left: solid 3px #333333; 34}

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

header_menu ulにもalign-items: center;をつけた。
結果:改善せず何も変わらない。

補足

左にあります画像はサイズが1500x250であります。

デベロッパツールを確認したところ、header_menuとlink_listで横幅は同じでしたが、縦幅がそれぞれ32px,16pxと違いました

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

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

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

guest

回答1

0

自己解決

どうやらbase.htmlのbootstrapが悪さしてたっぽいです。お騒がせしました

投稿2026/01/21 11:06

PythonNINJYA

総合スコア22

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.29%

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

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

質問する

関連した質問