gpt4 book ai didi

html - 正确的 Jumbotron 图像尺寸

转载 作者:太空宇宙 更新时间:2023-11-04 08:58:20 25 4
gpt4 key购买 nike

我在 Bootstrap 中使用超大屏幕容器并尝试使用图像作为背景。但是,似乎所有图像都随着屏幕尺寸的变化而扭曲,或者没有显示照片的正确部分。我应该设置一个正确的尺寸来保存我的图像吗?还是一种消除/最小化屏幕调整大小失真的方法?如有必要,我可以向您展示我的代码。

提前致谢!

CSS:

*{
margin: 0;
padding: 0;
}

.navbar-default{
background-color: rgb(66, 134, 244);
}
.under {
border-bottom: 15px solid rgb(66, 134, 244);
}
.size {
width: 300px;
}
.jumbotron{
height: 400px;
background: url("../images/parakeet.jpg");
background-size: cover;
}

HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Case</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="css/custom.css" rel="stylesheet">
</head>
<body>

<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">

<!-- Button nav for small screens -->

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Brand name -->

<a class="navbar-brand" href="#">WebSiteName</a>
</div>

<!-- Makes nav not expand on resize -->

<div class="collapse navbar-collapse" id="myNavbar">

<!-- Menu -->
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>

<!-- Dropdown menu -->
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Page 1-1</a></li>
<li><a href="#">Page 1-2</a></li>
<li><a href="#">Page 1-3</a></li>
</ul>
</li>
<!-- Non dropdown -->
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</div>
</div>
</nav>
<div class="jumbotron text-center under">
<h1>Website Heading</h1>
<p>Information about the website!</p>
</div>
<div class="container">
<div class="row">
<div class="col-sm-4 text-center">
<h2>Text</h2>
<p>More text describing the heading!</p>
<span class="glyphicon glyphicon-leaf size"></span>

</div>
<div class="col-sm-4 text-center">
<h2>Text</h2>
<p>More text describing the heading!</p>
<span class="glyphicon glyphicon-hourglass btn-lg"></span>

</div>

<div class="col-sm-4 text-center">
<h2>Text</h2>
<p>More text describing the heading!</p>
<span class="glyphicon glyphicon-plus btn-lg"></span>
</div>

</div>

</div>
</body>
</html>

最佳答案

那完全没问题。现在你需要使用 background-position现在,如果你运行这段代码。你会看到一些可爱的狗的图像。现在在较小的设备上,您会看到中间的 3 个狗。为什么?因为 background-position 在 x 上设置为 50%,在 y 上设置为 50%(图像的中心)

假设您希望在手机上显示最右边的黑头小狗。这很简单,您只需将 background-position 设置为 100% 和 50%。

*{
margin: 0;
padding: 0;
}

.navbar-default{
background-color: rgb(66, 134, 244);
}
.under {
border-bottom: 15px solid rgb(66, 134, 244);
}
.size {
width: 300px;
}
.jumbotron{
height: 400px;
background: url("https://puppydogweb.com/wp-content/uploads/2015/05/54_2383_Cute-Puppies-puppies-16094619-1280-800.jpg");
background-size: cover;
background-position: 0 50%;
}
<body>

<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">

<!-- Button nav for small screens -->

<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Brand name -->

<a class="navbar-brand" href="#">WebSiteName</a>
</div>

<!-- Makes nav not expand on resize -->

<div class="collapse navbar-collapse" id="myNavbar">

<!-- Menu -->
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>

<!-- Dropdown menu -->
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Page 1 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Page 1-1</a></li>
<li><a href="#">Page 1-2</a></li>
<li><a href="#">Page 1-3</a></li>
</ul>
</li>
<!-- Non dropdown -->
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</div>
</div>
</nav>
<div class="jumbotron text-center under">
<h1>Website Heading</h1>
<p>Information about the website!</p>
</div>
<div class="container">
<div class="row">
<div class="col-sm-4 text-center">
<h2>Text</h2>
<p>More text describing the heading!</p>
<span class="glyphicon glyphicon-leaf size"></span>

</div>
<div class="col-sm-4 text-center">
<h2>Text</h2>
<p>More text describing the heading!</p>
<span class="glyphicon glyphicon-hourglass btn-lg"></span>

</div>

<div class="col-sm-4 text-center">
<h2>Text</h2>
<p>More text describing the heading!</p>
<span class="glyphicon glyphicon-plus btn-lg"></span>
</div>

</div>

</div>
</body>

因此所有具有分辨率 < 平板电脑分辨率的东西都会看到黑头小狗。

@media (max-width: 768px) {
.jumbotron{
background-position: 100% 50%;
}
}

关于html - 正确的 Jumbotron 图像尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42960618/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com