繁体   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