前提・実現したいこと
responsive対応の時HTML/CSSで子要素に合わせて親要素の高さを可変にしたい。
- #topを可変にしたい。
- できれば.top-contentも
発生している問題・エラーメッセージ
子要素の高さを指定しているのにも関わらず、親要素の高さが0になる
該当のソースコード
HTML
1 <main> 2 <div id="top"> 3 <div class="top-content"> 4 <h1>Tastybox</h1> 5 <p> 6 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vitae 7 molestie dolor. Donec vel pretium velit. Pellentesque consectetur 8 dictum urna et mattis. Mauris vel tempor tortor, id viverra ipsum. 9 Nunc in molestie leo. Etiam fermentum, leo consequat posuere 10 ultricies, felis ante placerat ligula, vitae sodales turpis sapien 11 non lacus. Fusce vitae nunc quis elit malesuada sodales. Cras lorem 12 lacus, tincidunt non aliquam quis, eleifend eget nisl. Aenean 13 blandit tortor sit amet odio porttitor, id posuere felis laoreet. 14 Nullam venenatis turpis eros. Mauris egestas luctus finibus. Donec 15 semper varius fermentum. 16 </p> 17 <div class="top-buttons"> 18 <button 19 type="button" 20 class="btn btn-outline-primary btn-lg login-button" 21 onclick="location.href='login.html'" 22 > 23 Login 24 </button> 25 <button 26 type="button" 27 class="btn btn-outline-primary btn-lg new-account-button" 28 > 29 Create new account 30 </button> 31 </div> 32 </div> 33 </div> 34 35<省略> 36 37<main>
CSS
1@media screen and (max-width: 800px) { 2 main { 3 height: 100%; 4 width: 100%; 5 } 6 7 #top { 8 display: flex; 9 flex-direction: column; 10 height: 100%; 11 width: 100%; 12 } 13 14 #top .top-content { 15 /* padding: 10px; */ 16 height: 2000px; 17 } 18 19 #top .top-content h1 { 20 height: 50px; 21 margin-top: 30px; 22 margin-bottom: 15px; 23 } 24 25 #top .top-content p { 26 height: 500px; 27 margin-top: 15px; 28 } 29 30 #top .top-content .top-buttons button { 31 width: 100%; 32 height: 40px; 33 margin: 0; 34 padding: 0; 35 margin-bottom: 10px; 36 } 37} 38 39main { 40 width: 100%; 41 height: 3646px; 42 /* height: calc(166px + 700px + 500px); */ 43 position: relative; 44 padding-bottom: 10px; 45} 46 47#top { 48 background-image: url("../images/background-img.png"); 49 width: auto; 50 height: 700px; 51 position: relative; 52} 53 54#top::after { 55 background-color: rgba(254, 216, 177, 0.5); 56 content: ""; 57 position: absolute; 58 left: 0; 59 right: 0; 60 top: 0; 61 bottom: 0; 62} 63 64#top .top-content { 65 position: absolute; 66 top: 0; 67 right: 0; 68 bottom: 0; 69 left: 0; 70 margin: auto; 71 max-width: 80vw; 72 height: 400px; 73 text-align: center; 74 color: white; 75 z-index: 1; 76} 77 78#top .top-content h1 { 79 height: 100px; 80 font-family: "Balsamiq Sans", cursive; 81} 82
試したこと
- #top, .top-contentのheightをautoまたは100%
補足情報(FW/ツールのバージョンなど)
- Mac , VSCode

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