网页没有响应

时间:2019-02-23 20:47:12

标签: twitter-bootstrap web responsive-design

我想使我的网页具有响应能力。它可以工作到320px,但是当我进一步减小屏幕尺寸时,它根本不起作用,只有一半的内容可见。

这是必需的代码

HTML:

<div class="container">
    <div class="row">
        <div class="col-md-6">
            <img
                src="assets/img/profile.png"
                height="520"
                width="500"
                hspace="20"
                class="responsive"
            />
        </div>
        <div class="col-md-6">
            <p>
                Lorem Khaled Ipsum is a major key to success. To succeed you must
                believe. When you believe, you will succeed. Mogul talk. Find peace,
                life is like a water fall, you’ve gotta flow. Lion! Fan luv. Eliptical
                talk.
            </p>
        </div>
    </div>
</div>

CSS:

.responsive {
    max-width: 100%;
    display: block;
    height: auto;
    margin: auto;
}

img {
    float: left;
    margin-left: 20px;
}

@media screen and (max-width: 768px) {
    .nav-menu {
        background-color: #ffffff;
    }

    .nav-toggle:hover {
        background-color: transparent;
    }

    .nav-toggle span {
        background-color: #dfdfdf;
    }

    .nav-toggle span:hover {
        background-color: #fff;
    }
}

它可以正常工作到320px左右: enter image description here

但是在将其进一步减小到小于320像素之后,图像不适合屏幕: enter image description here

谢谢!

1 个答案:

答案 0 :(得分:0)

这就是我所做的:

我删除了img.responsive样式,并使用了Bootstrap .img-fluid类(选中here):

/* Deleted, because it isn't relevant anymore. */
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <title>Document</title>
</head>
<body>
  <div class="container">
    <div class="row">
      <div class="col-md-6">
        <img src="https://via.placeholder.com/1150" class="img-fluid" />
      </div>
      <div class="col-md-6">
        <p>
          Lorem Khaled Ipsum is a major key to success. To succeed you must believe. When you believe, you will succeed. Mogul talk. Find peace, life is like a water fall, you’ve gotta flow. Lion! Fan luv. Eliptical talk.
        </p>
      </div>
    </div>
  </div>

</body>
</html>

我在计算机上尝试过此操作。图像宽1150像素,但视口仅宽300像素。图像完美适应:

enter image description here

希望有帮助。