我正在尝试为朋友创建一个网站。挑战是在网站上只有一个图像。但是这些图像在PC和手机上都不一样。所以我现在已经创建了一个函数,因此将显示或隐藏其中一个。
但我现在的问题是响应不起作用。 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>
答案 0 :(得分:2)
您编写的图像标签应如下所示。你已经写了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">
答案 1 :(得分:0)
为什么不使用CSS媒体查询? MDN media query。它比JavaScript简单得多。我建议使用移动优先方法。