【问题标题】:Body is not adjusting when CSS attributes are changing当 CSS 属性发生变化时,正文没有调整
【发布时间】:2018-10-02 19:25:53
【问题描述】:

我习惯于使用 codepen.io 并忘记了正确格式化的基础知识。我现在正在使用 Visual Studio 代码。 现在我正试图将所有东西移到中心并改变我的颜色。 我注意到,当我在这里运行代码时,一切都很好。所以,当我在 Visual Studio 代码中预览它时,我不确定我错过了什么。

每当我预览代码时,Visual Studio 代码都会得到这样的图像:HERE,但每当我通过 StackOverflow 查看我的代码时,我都会看到:HERE

检查我收到这些错误的页面:

加载资源失败:服务器响应状态为 404(未找到)styles.css 加载资源失败:服务器响应状态为 404 (Not Found) favicon.ico 加载资源失败:服务器响应状态为 404 (Not Found) styles.css

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

body {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-family: cursive;
    text-align: center;
    min-height: 100vh;
    min-width: 370px;
    background-image: linear-gradient(135deg,#00ccff,#9933ff 31%,#e646b6 52%,#fff9aa 77%,#00ff99,#00ccff);
    background-size: 200%;
}

header h1 {
    padding: 20px 10px;
    letter-spacing: 0.2em;
    color: white;
}

form * {
    background: rgba(256, 256, 256, 0.3);
    color: white;
}

form.search form .btn {
    padding: 10px;
    border-radius: 2px;
    font-size: 16px;
    border: 1px solid white;
  
}

::placeholder {
    color: white;
}

form.search {
    width: 40%;
    min-width: 200px;
    max-width: 600px;
}

form.search:focus {
    outline: 0;
    color: #333; 
    background: white;
    box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.3), 
}

form.btn {
    cursor: pointer;
    width: 60px;
}
form.clear:hover {
    background: ;
}

.giphy {
    padding: 20px 0px 15px 0;
}

.giphy img {
    width: 200px;
    max-width: 800px;
    margin: auto;
    display: block;
}

giphy img.gif {
    width: 50%;
    max-width: 600px;
    box-shadow: 0 0 1px 1px rgba(256,256,256,0.3);
  }

  footer {
    padding: 5px;
    font-size: 14px;
    color: white;
  }
  
  footer a {
    color: #333;
    text-decoration: none;
  }
  footer a:hover {
    color: white;
    text-decoration: underline;
  }
  
<html>
<head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.css">

<title>Giphy</title>
</head>
<header>
    
<body>

<h1>Giphy Hooligan</h1>

<form method="post">
    <label style="display: none;">Search</label>
    <input class="search" type="text" name="search" placeholder="Search" required>
    <input class="btn" type="submit" value="OK">
    <input class="btn" type="button" value="Favorites">
</form>
</header>

<section>
    <div class="giphy">
        <a href="https://giphy.com/" target="blank">
        <img src="https://res.cloudinary.com/beumsk/image/upload/v1520544016/giphy-logo-6611-s-_vme7aa.png" alt="giphy">
        </a>
    </div>
</section>

<footer>
    <p>Dakota Coleman</p>
</footer>












</body>
</html>

【问题讨论】:

    标签: html css


    【解决方案1】:

    如果只是将正文中的项目与中心对齐,那么您需要

    align-items:center; 
    

    ...在body

    您可能需要为子级添加额外的居中方法(例如form),并且 flex-children 不会继承 flexbox。

    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    body {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      /* add this */
      font-family: cursive;
      text-align: center;
      min-height: 100vh;
      min-width: 370px;
      background-image: linear-gradient(135deg, #00ccff, #9933ff 31%, #e646b6 52%, #fff9aa 77%, #00ff99, #00ccff);
      background-size: 200%;
    }
    
    header h1 {
      padding: 20px 10px;
      letter-spacing: 0.2em;
      color: white;
    }
    
    form * {
      background: rgba(256, 256, 256, 0.3);
      color: white;
    }
    
    form.search form .btn {
      padding: 10px;
      border-radius: 2px;
      font-size: 16px;
      border: 1px solid white;
    }
    
    ::placeholder {
      color: white;
    }
    
    form.search {
      width: 40%;
      min-width: 200px;
      max-width: 600px;
    }
    
    form.search:focus {
      outline: 0;
      color: #333;
      background: white;
      box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.3),
    }
    
    form.btn {
      cursor: pointer;
      width: 60px;
    }
    
    form.clear:hover {
      background: ;
    }
    
    .giphy {
      padding: 20px 0px 15px 0;
    }
    
    .giphy img {
      width: 200px;
      max-width: 800px;
      margin: auto;
      display: block;
    }
    
    giphy img.gif {
      width: 50%;
      max-width: 600px;
      box-shadow: 0 0 1px 1px rgba(256, 256, 256, 0.3);
    }
    
    footer {
      padding: 5px;
      font-size: 14px;
      color: white;
    }
    
    footer a {
      color: #333;
      text-decoration: none;
    }
    
    footer a:hover {
      color: white;
      text-decoration: underline;
    }
    <html>
    
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.css">
    
      <title>Giphy</title>
    </head>
    <header>
    
      <body>
    
        <h1>Giphy Hooligan</h1>
    
        <form method="post">
          <label style="display: none;">Search</label>
          <input class="search" type="text" name="search" placeholder="Search" required>
          <input class="btn" type="submit" value="OK">
          <input class="btn" type="button" value="Favorites">
        </form>
    </header>
    
    <section>
      <div class="giphy">
        <a href="https://giphy.com/" target="blank">
          <img src="https://res.cloudinary.com/beumsk/image/upload/v1520544016/giphy-logo-6611-s-_vme7aa.png" alt="giphy">
        </a>
      </div>
    </section>
    
    <footer>
      <p>Dakota Coleman</p>
    </footer>
    
    
    
    
    
    
    
    
    
    
    
    
    </body>
    
    </html>

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 2011-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-19
      • 2015-01-09
      • 2017-01-28
      • 1970-01-01
      相关资源
      最近更新 更多