gpt4 book ai didi

html - 我如何在超大屏幕内居中和调整图像大小?

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

我试图不只将我的图像居中,而且还调整它的大小,因为它太大了。我希望我的图像像类似的网站一样位于导航的正上方。我怎样才能做到这一点?

.jumbotron {
text-align: center;
}

.navbar-nav.navbar-center {
position: absolute;
left: 50%;
transform: translatex(-50%);
font-size: 20px;
}

.navbar-default {
background-color: white;
border-color: white;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="jumbotron">
<img src="https://images.unsplash.com/photo-1551308719-c0e80e6becc9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80" width="200px">
</div>

<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<ul class="nav navbar-nav navbar-center">
<li><a href="#">HOME</a></li>
<li><a href="#">COLECTION</a></li>
<li><a href="#">SHOP</a></li>
<li><a href="#">CONTACT US</a></li>
</ul>
</div>
</nav>

最佳答案

由于您选择的图像的尺寸,确实没有完美的解决方案。如果将此图像拉伸(stretch) 100% 宽度且仅拉伸(stretch)超大屏幕的高度,图像将非常扭曲。假设您不希望图像高度拉伸(stretch)整个屏幕,您可以这样做:

.jumbotron {
background: url(https://images.unsplash.com/photo-1551308719-c0e80e6becc9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80);
background-size: cover;
background-position: center;
min-height: 400px;
}

.navbar-nav.navbar-center {
position: absolute;
left: 50%;
transform: translatex(-50%);
font-size: 20px;
}

.navbar-default {
background-color: white;
border-color: white;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" media="screen" href="./style.css">
</head>
<body>
<div class="jumbotron">
</div>
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<ul class="nav navbar-nav navbar-center">
<li><a href="#">HOME</a></li>
<li><a href="#">COLECTION</a></li>
<li><a href="#">SHOP</a></li>
<li><a href="#">CONTACT US</a></li>
</ul>
</div>
</nav>
</body>
</html>

关于html - 我如何在超大屏幕内居中和调整图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54947562/

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