gpt4 book ai didi

css - 具有固定顶部和底部文本的垂直/水平居中/中间缩放图像

转载 作者:行者123 更新时间:2023-11-28 01:59:29 25 4
gpt4 key购买 nike

我正在尝试使用 bootstrap 创建一个简单的网页,其中一些文本固定在顶部居中,一些更居中的文本固定在页面底部。

在页面中间,我需要一个居中水平和垂直放置的图像,该图像根据分辨率/设备进行缩放。

页面需要是视口(viewport)的全高。

我试过使用下面的代码,但它不能正常工作,是一个错误,一定有更简单的方法吗?

Logo 图像为 450 像素 x 480 像素

 <!DOCTYPE html>
<html lang="en">
<head>

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="" />
<meta name="author" content="" />
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
<style>


html, body {
height: 100%;
}

.holder {
width: 100%;
height: 100%;
min-height: 100%;
display: block;
}

.fill {
min-height: 100%;
height: 100%;
}

.col-md-12 {
position: relative;
min-height:100vh!important;
}

.toptext{
background-color:#ffffff!important;
z-index:99999!important;
}

.bottomtext {
position: absolute;
width: 100%;
left: 0;
bottom: 0;
text-align: center;
margin-bottom: 20px;
background-color: #ffffff !important;
z-index: 99999 !important;
}

.middleimage > img {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index:1!important;
max-height:350px!important;
}

@media screen and (min-width:1px) and (max-width: 767px) {
h3 {
font-size: 16px !important;
}
.bottomtext{
bottom:80px!important;
}
html,body {
overflow: hidden!important;
}
}

@media screen and (min-width:567px) and (max-width: 767px) {

.bottomtext {
bottom: 80px !important;
}

html, body {
overflow:visible !important;
}

.middleimage>img{
max-height:100px!important;
}

}

@media screen and (min-width:760px) {

.bottomtext {
bottom: 0 !important;
}

html, body {
overflow: visible !important;
}

.middleimage > img {
max-height: 480px !important;
}
}

</style>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
</head>
<body>


<div class="container fill">
<div class="holder">

<div class="row">

<div class="col-md-12 col-sm-12">

<div class="toptext text-center">
<h3>Top of page info</h3>
<hr>
</div>

<div class="middleimage">
<img src="/holdingfiles/mylogo.png" alt="" class="img-responsive " />
</div>

<div class="bottomtext">
<hr>
Bottom of page / footer info
</div>

</div>

</div>

</div>

</div>

</body>
</html>

最佳答案

卡尔,

由于您使用的是 Bootstrap ,因此请在 div/img 上使用“img-responsive”类,它应该可以很好地缩放。

已编辑:您可以将它用作您的 div 的背景图片:查看以下链接,它应该可以为您提供您想要的内容

https://css-tricks.com/perfect-full-page-background-image/

关于css - 具有固定顶部和底部文本的垂直/水平居中/中间缩放图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49430903/

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