簡體   English   中英

我的頁面高度沒有填滿整個高度? 如何讓它響應?

[英]My height for my page does not fill full height? How do I make it responsive?

我的身高反應遲鈍。 我引用了這個問題:

為什么最小高度不起作用?

但它仍然無法正常工作。 我要參考的網站是http://horsescowsandcemeteries.com/

我希望它適用於台式機和移動設備。 謝謝。

Vh 不工作。

您可以使用“視口”元標記來縮放您的網站,類似於瀏覽器版本。 只需將下面的代碼放入head元素中。

<meta name="viewport" content="width=device-width, initial-scale=1.0">


如果你想在縮放時修復body背景,你可以使用這個:

body {
    height: fit-content;
}

之前/之后

添加<meta name="viewport" content="width=device-width, initial-scale=1.0">到您的 HTML 並添加試試這個 css

/*Game Play Screen */

body {
  display: flex;
  flex-direction: column;
  margin: auto;
  border: 3px solid green;
  padding: 10px;
  background-image: url(images/road-bg.jpg);
  background-size: cover;
  font-family: "Krona One";
  text-align: center;
}

main {
  display: flex;
  flex: 1;
  margin-bottom: 25px;
}

#container {
  display: flex;
  flex: 1;
  justify-content: space-around;
}

.team-one, .team-two {
  width: 50%;
}

#left-side,
#right-side {
  display: flex;
  flex: 1;
  height: 100%;
  flex-direction: column;
}

#instructions {
  margin-bottom: 2em;
  text-align: center;
  background-color: green;
  font-size: 140%;
}

#instructionsButton {
  background-color: green;
  color: white;
  padding: 0.5em 1em 0.5em 1em;
  text-decoration: none;
  font-size: 1.5em;
  border-radius: 10px;
}

.teamBox {
  color: white;
  background: #333;
  padding: 1em;
  border-radius: 5px;
  border: 6px solid white;
  width: 160px;
  height: 80px;
  margin-bottom: 1em;
  display: inline-block;
  -webkit-box-shadow: 3px 3px 5px 0px rgba(0, 0, 0, 0.44);
  -moz-box-shadow: 3px 3px 5px 0px rgba(0, 0, 0, 0.44);
  box-shadow: 3px 3px 5px 0px rgba(0, 0, 0, 0.44);
  margin: 5em auto;
}

.teamBox h3,
p {
  margin-top: 0;
  margin-bottom: 0;
}

#scoreTotalTeamOne,
#scoreTotalTeamTwo {
  font-size: 2.5em;
}

#endButton {
  background-color: #be1e2d;
  color: white;
  padding: 0.5em 1em 0.5em 1em;
  text-decoration: none;
  font-size: 2em;
  border-radius: 10px;
  margin-bottom: 2em;
}

.gameplaybutton {
  width: 200px;
  height: 200px;
  margin: auto;
}

/* First breakpoint, elimates the road */
@media only screen and (max-width: 675px) {
  body {
    height: auto;
    background: url(images/road-bg-sm.jpg);
    background-size: cover;
  }
  .teamBox {
    width: 100px;
    height: 100px;
  }
 #instructionsButton{
   font-size: 1em;
 }
}

/* Second breakpoint */
@media only screen and (max-width: 550px) {
  .gameplaybutton {
    width: 150px;
    height: 150px;
  }
}

暫無
暫無

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

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