引导(响应式映像)不起作用(PC/移动)



我正在为一个朋友创建一个网站。面临的挑战是在网站上只有一张图片。但是电脑和手机上的图像不可能是一样的。所以我现在已经制作了一个函数,所以其中一个将被显示或隐藏。

但我现在的问题是,响应不起作用。电脑和手机的代码会一样吗?

<!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>Danish Bread Studio</title>
    <!-- Almindelig CSS -->
    <link href="stylesheet.css" rel="stylesheet">
    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.js"></script>
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
        <img src="baggrund2.jpg" class="visible-xs" class="img-responsive" alt="responsive image">
        <img src="baggrund.jpg" class="visible-lg" class="img-responsive" alt="responsive image">
    <div class="box">
        <p><center>Danish Bread Studio's hjemmeside er i øjeblikket under opbygning.</center></p>   
    </div>
  </body>
</html>

您编写的图像标记应该如下所示。您已经编写了2次类属性。

<img src="baggrund2.jpg" class="visible-xs img-responsive" alt="responsive image">
<img src="baggrund.jpg" class="visible-lg img-responsive"  alt="responsive image">

为什么不使用CSS媒体查询?MDN媒体查询。它比JavaScript简单得多。我建议采用移动优先的方法。

最新更新