基础 5:将我的 img 大小设置为 div 的 100%
Foundation 5: Styling my img size to the be 100% of a div
我正在使用 Foundation 5 来设置一个基本页面。我正在尝试获取一个按钮来更改某个 div 的背景图像。到目前为止这是有效的,但它只显示图像的特定区域。
这是我目前的代码:
function cW() {
document.getElementById("panel").style.backgroundImage =
"url('https://dl.dropboxusercontent.com/u/36821301/csgo%20backgrounds/crimson-web.jpg')";
document.getElementById("panel").backgroundImage.style.maxWidth = "100%";
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Foundation 5 testing</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8" />
<link type="text/css" rel="stylesheet" href="foundation_5.css">
<link type="text/css" rel="stylesheet" href="include/foundation.css">
<script src="include/foundation.min.js"></script>
<script src="include/jquery.js"></script>
<script src="include/modernizer.js"></script>
<script src="foundation_5.js"></script>
</head>
<body>
<div class="row">
<div class="medium-12 columns">
<div id="panel" class="panel">
<h1>Foundation Page</h1>
<p>Resize this responsive page to see the effect!</p>
<ul class="button-group round">
<li>
<button type="button" class="button" value="cW" onclick="cW()">Crimson Web</button>
</li>
<li>
<button type="button" class="button" value="mF" onclick="mF()">Marble Fade</button>
</li>
<li>
<button type="button" class="button" value="d" onclick="d()">Doppler</button>
</li>
<li>
<button type="button" class="button" value="rC" onclick="rC()">Rust Coat</button>
</li>
<li>
<button type="button" class="button" value="dS" onclick="dS()">Damascus Steel</button>
</li>
<li>
<button type="button" class="button" value="s" onclick="hB()">Hyper Beast</button>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>
我想达到的目标:
我想在某个 div.
范围内显示完整尺寸的图像
谢谢
您需要将 background-size
添加到 div 的 CSS。像
background-size: 100% 100%;
或
background-size: cover;
或
background-size: contain;
您必须尝试各种方式才能看到您想要哪一种。无论哪种方式,背景都会整齐地适合 div
希望对您有所帮助
在您的 css 文件中添加以下样式
#panel{
width:100vw;
height:100vh;
}
我正在使用 Foundation 5 来设置一个基本页面。我正在尝试获取一个按钮来更改某个 div 的背景图像。到目前为止这是有效的,但它只显示图像的特定区域。
这是我目前的代码:
function cW() {
document.getElementById("panel").style.backgroundImage =
"url('https://dl.dropboxusercontent.com/u/36821301/csgo%20backgrounds/crimson-web.jpg')";
document.getElementById("panel").backgroundImage.style.maxWidth = "100%";
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Foundation 5 testing</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8" />
<link type="text/css" rel="stylesheet" href="foundation_5.css">
<link type="text/css" rel="stylesheet" href="include/foundation.css">
<script src="include/foundation.min.js"></script>
<script src="include/jquery.js"></script>
<script src="include/modernizer.js"></script>
<script src="foundation_5.js"></script>
</head>
<body>
<div class="row">
<div class="medium-12 columns">
<div id="panel" class="panel">
<h1>Foundation Page</h1>
<p>Resize this responsive page to see the effect!</p>
<ul class="button-group round">
<li>
<button type="button" class="button" value="cW" onclick="cW()">Crimson Web</button>
</li>
<li>
<button type="button" class="button" value="mF" onclick="mF()">Marble Fade</button>
</li>
<li>
<button type="button" class="button" value="d" onclick="d()">Doppler</button>
</li>
<li>
<button type="button" class="button" value="rC" onclick="rC()">Rust Coat</button>
</li>
<li>
<button type="button" class="button" value="dS" onclick="dS()">Damascus Steel</button>
</li>
<li>
<button type="button" class="button" value="s" onclick="hB()">Hyper Beast</button>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>
我想达到的目标: 我想在某个 div.
范围内显示完整尺寸的图像谢谢
您需要将 background-size
添加到 div 的 CSS。像
background-size: 100% 100%;
或
background-size: cover;
或
background-size: contain;
您必须尝试各种方式才能看到您想要哪一种。无论哪种方式,背景都会整齐地适合 div
希望对您有所帮助
在您的 css 文件中添加以下样式
#panel{
width:100vw;
height:100vh;
}