簡體   English   中英

如何使網站垂直響應?

[英]how to make website responsive vertically?

我有一個網頁,並且所有內容都包裹着“正文”。 但是,當我響應此網頁並希望正文放大網頁內容時,正文會停止垂直放大內容。 當我增加寬度但不垂直時,確實會擴大內容。 我不要多余的黑色區域。

 body { background-color: black; padding-bottom: 10vh; padding-top: 10vh; padding-right: 10vh; padding-left: 10vh; margin: 0; height: 100%; align-content: center; justify-content: center; position: relative; } #wrapper { position: static; align-items: center; height: 100%; width: 100%; align-content: center; display: flex; flex-direction: row; margin: 0 auto; justify-content: center; overflow: auto; } #wrapper2 { align-items: center; width: 100%; height: 100%; align-content: center; display: flex; flex-direction: row; margin: 0 auto; justify-content: center; overflow: auto; } img { width: 100%; height: 100%; display: block; } .cell1 { width: calc(100% / 3); text-align: center; background-size: contain; height: 100%; background-position: center; position: relative; } .cell2 { width: calc(100% / 3); text-align: center; background-size: contain; height: 100%; background-position: center; position: relative; } .cell3 { width: calc(100% / 3); text-align: center; background-size: contain; height: 100%; background-position: center; position: relative; } .dogname { color: white; top: 20px; font-family: 'Roboto Condensed', sans-serif; text-align: center; position: absolute; width: 100%; margin: 0; } .dogtext { color: white; top: 0; font-family: 'Roboto Condensed', sans-serif; text-align: center; position: relative; width: 100%; margin-bottom: 30px; margin-top: 0px; display: none; } @media screen and (max-width: 500px) { #wrapper { display: flex; flex-wrap: wrap; flex-direction: row; } #wrapper2 { display: flex; flex-wrap: wrap; flex-direction: row; } .cell1 { width: 100vw; } .cell2 { width: 100vw; } .cell3 { width: 100vw; } .dogname { display: none; } .dogtext { display: block; } body { background-color: black; height: 100%; padding: 0; margin: 0; } } 
 <body> <div id="wrapper"> <div class="cell1"> <p class="dogname">David Neal</p> <img src="images/image1.jpg" /> </div> <p class="dogtext">After the hunt (1870) by David Neal</p> <div class="cell2"> <p class="dogname">BG Tiepolo</p> <img src="images/image2.jpg" /> </div> <p class="dogtext">Portrait of a Toy Spaniel Belonging to the Infanta Maria Josefa of Bourbon (1763) by Giovanni Battista Tiepolo</p> <div class="cell3"> <p class="dogname">AF Desportes</p> <img src="images/image3.jpg" /> <p class="dogtext">Chienne blanche devant un buisson de sureau (1714) by Alexandre-François Desportes</p> </div> </div> <div id="wrapper2"> <div class="cell1"> <p class="dogname">JC Merck</p> <img src="images/image4.jpg" /> <p class="dogtext">Ulmer Dogge (1705) by Johann Christof Merck</p> </div> <div class="cell2"> <p class="dogname">John Wootton</p> <img src="images/image5.jpg" /> <p class="dogtext">A Grey Spotted Hound (1738) by John Wootton</p> </div> <div class="cell3"> <p class="dogname">EH Landseer</p> <img src="images/image6.jpg" /> <p class="dogtext">A Distinguished Member of the Humane Society (1838) by Edwin Henry Landseer</p> </div> </div> </body> 

這實際上取決於您要實現的目標,但是通常,您可以使用媒體查詢來確定高度,並將它們與寬度結合起來。

@media screen and (max-width: 800px) , screen and (max-height: 600px) {
  ...
}

默認情況下,您的網頁會根據內容的高度進行垂直縮放。 要始終使它至少為一個viewheight高,可以將此規則插入到CSS中:

html, body {
    min-height: 100vh;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM