【问题标题】:Website looks off when working on a smaller screen在较小的屏幕上工作时网站看起来不正常
【发布时间】:2020-06-25 07:40:28
【问题描述】:

我需要尽快完成我的工作,但我无法使用更大的显示器。我想老师也有一个大显示器,他会在那里看我的工作,所以这应该不是问题。 但是我的网站只有 70% 看起来正常,而且我很难让它工作,所以我必须在 70% 上工作。

* {
  margin: 0px;
  padding: 0px;
  box-sizing: border-box;
}

body {
  font-family: 'Poppins', sans-serif;
}

header {
  display: flex;
  width: 50%;
  height: 8vh;
  margin: auto;
  align-items: center;
}

.nav-links,
.search-container {
  display: flex;
}

nav {
  position: relative;
  flex: 1;
}

.nav-links {

  justify-content: space-evenly;
  max-width: 300px;
  list-style: none;
}

.nav-link {
  color: #ffffff;
  font-size: 18px;
  text-decoration: none;
}

.search-container {
  flex: 1;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 0;
}

#justdance {
  display: flex;
  width: 50%;
  margin: auto;
  align-items: top;
}

.about {
  background-color: #c4c4c4;
  display: flex;
  width: 50%;
  height: 30vh;
  margin: auto;
  flex-direction: column;
  align-items: flex-start;
}


.quote {
  text-align: center;
  display: block;
  border-radius: 10px;
  border-style: solid;
  box-shadow: rgba(0, 0, 0, 0.42) 0px 2px 2px 0px;
  width: 500px;
  height: 30px;
  margin: 20px auto 0 auto;
}

.description {
  margin: 30px auto 0 auto;
  text-align: justify;
  width: 70%;
  font-size: 13px;
}

.sideimage {
  position: absolute;
  right: 640px;
  top: 390px;
}

.polygon {
  position: absolute;
  right: 960px;
  bottom: 260px;
  width: 0;
  height: 0;
  border-top-width: 82px;
  border-top-style: solid;
  border-top-color: transparent;
  border-right-width: 90px;
  border-right-style: solid;
  border-right-color: #c4c4c4;
  transform: rotate(-180deg);
}

.piirkonnad {
  background-color: #222222;
  display: flex;
  width: 50%;
  height: 29vh;
  margin: auto;
  flex-direction: column;
  align-items: flex-start;
}

.piirkonnad p {
  position: absolute;
  left: 554px;
  bottom: 270px;

  font-family: Roboto;
  font-style: italic;
  font-weight: 300;
  font-size: 20px;
  line-height: 23px;

  color: #FFFFFF;
}

.copyright p {
  position: absolute;
  right: 803px;
  bottom: 24px;

  font-family: Roboto;
  font-style: normal;
  font-weight: normal;
  font-size: 13px;
  line-height: 12px;

  color: #FFFFFF;
}

.social {
  position: absolute;
  right: 550px;
  bottom: -2px;
}

.fa {
  padding: 15px;
  font-size: 30px;
  width: 50px;
  text-align: center;
  text-decoration: none;
  margin: 5px 2px;
  border-radius: 50%;
}

.fa-instagram {
  background: #c4c4c4;
  color: black;
}

.fa-twitter {
  background: #c4c4c4;
  color: black;
}

.fa-facebook {
  background: #c4c4c4;
  color: black;
}
<!doctype html>
<html>

  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes">
    <title>Just Dance</title>
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  </head>
  <style>
    body {
      background-color: #000000;
    }

  </style>

  <body>
    <header>
      <nav>
        <ul class="nav-links">
          <li><a class="nav-link" href="#">Avaleht</a></li>
          <li><a class="nav-link" href="#">Meist</a></li>
          <li><a class="nav-link" href="#">Login</a></li>
        </ul>
        <div class="search-container">
          <input type="text" placeholder="Otsing" name="search">
        </div>
      </nav>
    </header>

    <main>
      <img src="header.jpg" alt="Just Dance" id="justdance" ;>
      <div class="about">
        <div class="quote">“Dance is the hidden language of the soul” - Marta Graham</div>
        <div class="description">
          <div class="text">
            <p>Kunagi pole liiga hilja alustada. Just Dance veebilehelt leiad<br>
              tantsukursusi üle Eesti.</p>
            <br>
            <p>Sulle sobiva kursuse leidmine on imelihtne - vali piirkond või<br>
              tantsustiil ning sulle avaneb loetelu kursustest.</p>
            <br>
            <p>Ka tantsukaaslaste leidmine on imelihtne. Kirjuta sulle sobiva<br>
              kursuse kommentaaridesse oma kaaslaseotsingust ning jää<br>
              ootama vastust. Ehk leiad juba homme oma unelmate partneri?<br>
              Kursuste kommenteerimiseks registreeru "Just Dance" kasutajaks.</p>
          </div>
          <div class="sideimage">
            <img src="dancers.png" alt="Dancers" id="dancer" ;>
          </div>
          <div class="polygon"></div>
        </div>
    </main>

    <section>
      <div class="piirkonnad">
        <p>Piirkonnad</p>
      </div>
      <div class="row1">
        <img src="1.jpg" alt="Harjumaa" width="170" height="100">
      </div>

    </section>

    <footer>
      <div class="copyright">
        <p>Just Dance © Noor Meister Kõik õigused kaitstud</p>
      </div>
      <div class="social">
        <a href="#" class="fa fa-instagram"></a>
        <a href="#" class="fa fa-twitter"></a>
        <a href="#" class="fa fa-facebook"></a>
      </div>
    </footer>

  </body>

</html>

我已经听说过响应式设计,但我想不通。我不是最擅长编码的,而且很难实现我所拥有的,因此非常感谢您的帮助。

【问题讨论】:

标签: html css


【解决方案1】:

你的代码有一些错误,你的img元素上有;,你的style元素应该在head标签中,你的网站没有响应的原因是因为你是使用position:absolute,保持您的网站简单,或者如果您真的想仍然使用position:absolute,那么该div 应该包含在另一个div 中,但将其设置为position:relative。 无论如何,我修复了它,现在完全响应了,这里是:

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    padding-top:20px;
}

header{
    display:flex;
    justify-content:space-evenly;
    width: 50%;
    margin: auto;
    flex-wrap:wrap;
    
}

.nav-links{
    display: flex;
}


.nav-links{
    justify-content: space-evenly;
    max-width: 300px;
    list-style: none;
}

.nav-link{
    color: #ffffff;
    font-size: 18px;
    padding:10px;
    text-decoration: none;
}


#justdance {
    display: flex;
    width: 50%;
    margin: auto;
    align-items: top;
}

.about {
  padding:10px;
    background-color: #c4c4c4;
    width: 50%;
    margin: auto;
    
    
  }
  .search-container{
    min-width:30px

}
.quote {
  
    text-align: center;
    display: block;
    border-radius: 10px;
    border-style: solid;
    box-shadow: rgba(0, 0, 0, 0.42) 0px 2px 2px 0px;
   padding:5px;
    margin: 10px auto 0 auto;
}

.description {
    margin: 30px auto 0 auto;
    
    width: 70%;
    font-size: 13px;
}


.polygon {

    height: 0;
    border-top-width: 82px;
    border-top-style: solid;
    border-top-color: transparent;
    border-right-width: 90px;
    border-right-style: solid;
    border-right-color: #c4c4c4;
    transform: rotate(-180deg);
}

.piirkonnad {
  position:relative;
  display:flex;
    background-color: #222222;
    display: flex;
    width: 50%;
    padding-top:30px;
    height: 29vh;
    margin: auto;
    justify-content:space-evenly;
}

.piirkonnad p {
   text-align:center;
    font-family: Roboto;
    font-style: italic;
    font-weight: 300;
    font-size: 20px;
    line-height: 23px;

    color: #FFFFFF;
}
footer{
  margin-top:1em;
}
.copyright p {
  text-align:center;
font-family: Roboto;
font-style: normal;
font-weight: normal;
font-size: 13px;
line-height: 12px;

color: #FFFFFF;
}

.social {
    display:flex;
    justify-content:center;
}

.fa {
    padding: 15px;
    font-size: 30px;
    width: 50px;
    text-align: center;
    text-decoration: none;
    margin: 5px 2px;
    border-radius: 50%;
  }

.fa-instagram {
    background: #c4c4c4;
    color: black;
  }

.fa-twitter {
    background: #c4c4c4;
    color: black;
  }

.fa-facebook {
    background: #c4c4c4;
    color: black;
  }
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes">
<title>Just Dance</title>
    <link rel="stylesheet" href="./style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <style>
    body {
        background-color: #000000;
    }
</style>
</head>


<body>
    <header>
    <nav>
    <ul class="nav-links">
        <li><a class="nav-link" href="#">Avaleht</a></li>
        <li><a class="nav-link" href="#">Meist</a></li>
        <li><a class="nav-link" href="#">Login</a></li>
        </ul>
        
        </nav>
        <div class="search-container">
                <input type="text" placeholder="Otsing" name="search">
            </div>
        </header>

    <main>
    <img src="header.jpg" alt="Just Dance" id="justdance">
    <div class="about">
            <div class="quote">“Dance is the hidden language of the soul” - Marta Graham</div>
            <div class="description">
                <div class="text">
                <p>Kunagi pole liiga hilja alustada. Just Dance veebilehelt leiad<br>
                tantsukursusi üle Eesti.</p>
                <br>
                <p>Sulle sobiva kursuse leidmine on imelihtne - vali piirkond või<br>
                tantsustiil ning sulle avaneb loetelu kursustest.</p>
                <br>
                <p>Ka tantsukaaslaste leidmine on imelihtne. Kirjuta sulle sobiva<br>
                kursuse kommentaaridesse oma kaaslaseotsingust ning jää<br>
                ootama vastust. Ehk leiad juba homme oma unelmate partneri?<br>
                Kursuste kommenteerimiseks registreeru "Just Dance" kasutajaks.</p>
                </div>
                
            </div>
            </div>
            <section>
              
        <div class="piirkonnad">
          
                <div class="polygon"></div>
                <p>Piirkonnad</p>
                <div class="sideimage">
                    <img src="dancers.png" alt="Dancers" id="dancer">
                </div>
                </div>
        <div class="row1">
            <img src="1.jpg" alt="Harjumaa" width="170" height="100">
          </div>

    </section>
    </main>
    <footer>
        <div class="copyright">
            <p>Just Dance © Noor Meister  Kõik õigused kaitstud</p>
    </div>
    <div class="social">
        <a href="#" class="fa fa-instagram"></a>
        <a href="#" class="fa fa-twitter"></a>
        <a href="#" class="fa fa-facebook"></a>
    </div>
    </footer>

</body>
</html>

【讨论】:

    【解决方案2】:

    为了使网站具有响应性,您需要避免使用 px 并使用 %、vw(视口宽度)或 vh(视口高度)。 在你的 CSS 之后,你需要声明 @media only screen and (max-width: screenSizepx) 并在里面为每个屏幕制作响应式布局。 通常我会这样做:

    • @media only screen and (max-width: 1000)
    • @media only screen and (max-width: 550px)
    • @media only screen and (max-width: 400px)

    【讨论】:

      猜你喜欢
      • 2016-07-27
      • 2020-07-23
      • 1970-01-01
      • 1970-01-01
      • 2014-06-18
      • 1970-01-01
      • 2016-09-10
      • 2022-01-25
      • 1970-01-01
      相关资源
      最近更新 更多