【问题标题】:My responsive website doesn't scale perfect on mobile and other devices我的响应式网站无法在移动设备和其他设备上完美扩展
【发布时间】:2017-07-28 10:11:46
【问题描述】:

我使用 bootstrap 3 创建了一个响应式网站。这是一个带有图片库的投资组合网站。该网站确实可以响应,但是当我从移动设备或其他设备查看它时,它不能完美地扩展。当我重新加载页面时,它起初看起来是正确的,但是当它完成加载时它会改变。有谁知道我哪里出错了?

body {
  padding: 0;
  border: 0;
  vertical-align: baseline
}

.main {
  margin-top: 170px;
  margin-right: auto;
  margin-left: auto;
  margin-bottom: 20px;
}

.navbar {
  min-height: 130px;
  margin-bottom: 20px;
}

.navbar-toggle {
  margin-top: 25px;
}

@media (min-width: 768px) {
  .navbar-nav.navbar-right:last-child {
    margin-right: 0;
  }
}

.box {
  padding: 5px;
  margin: 0;
}

.img {
  display: block;
  position: relative;
  margin: 0px;
  z-index: 1;
}

.imgoverlay {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

.img:hover .imgoverlay {
  opacity: 0.75;
}

.text {
  position: absolute;
  bottom: 0;
  padding-bottom: 6px;
  margin: auto auto auto 10px;
}


/*///////////POP UP////////*/

.overlay {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  visibility: hidden;
  opacity: 0;
  z-index: 2;
}

.overlay:target {
  visibility: visible;
  opacity: 1;
}

.popup {
  margin: 150px auto;
  position: relative;
}

.popup .content {
  max-height: 30%;
  overflow: auto;
}
<!DOCTYPE html>
<html lang="en">

<head>

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
  <title></title>

  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

  <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700" rel="stylesheet">

  <link rel="stylesheet" href="styles/main.css">

</head>

<body>
  <section class="main">
    <div class="container">
      <div class="row">
        <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12 box">
          <a href="#" class="img">
            <img src="" alt="" class="img-responsive">
            <div class="imgoverlay">
              <div class="text"></div>
            </div>
          </a>
        </div>

        <!--///////////// POP UP /////////////////////-->
        <div id="popup1" class="overlay">
          <div class="col-md-12 popup">
            <div class="col-md-6 col-md-offset-1 iframe">
              <iframe src="" frameborder="0" allowfullscreen></iframe>
            </div>
            <div class="col-md-4 content">
              <h2></h2>
              <p class="info"></p>
            </div>
            <a class="col-md-1 close" href="#">&times;</a>
          </div>
        </div>
      </div>
    </div>
  </section>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>

</html>

【问题讨论】:

    标签: css twitter-bootstrap mobile responsive


    【解决方案1】:

    使用媒体查询

    @media (min-width: 576px) { ... }
    

    在大括号内定义样式

    媒体查询用于定义用于为不同媒体类型/设备定义不同样式的规则。

    如果设备屏幕的宽度最小为 567px,那么它将被渲染为定义的样式。

    【讨论】:

    • 这如何回答这个问题?它有什么作用?解释你自己!
    • 编辑您的答案。不要把它作为评论。但你还没有完全说出那是什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-22
    • 1970-01-01
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    相关资源
    最近更新 更多