gpt4 book ai didi

jquery - 我在 div 中的图像没有文字显示?

转载 作者:行者123 更新时间:2023-11-28 15:18:33 25 4
gpt4 key购买 nike

我想在我的导航栏下插入一张图片。我要么遇到导航栏覆盖图像的问题,要么在我最小化到移动宽度时图像无法正确缩放,要么图像根本不显示。这与我想要的响应能力一样接近。有什么建议么?我知道所有的 div 都为 0 并且需要一个高度,但是如果我给图像添加一个高度,它就不会响应。

body{
background: silver;
}
#pageOne {
background: url(http://oi68.tinypic.com/21entzo.jpg);
background-size: cover;
background-repeat: no-repeat;
margin-top: 56px;
}
<!DOCTYPE html>
<html>
<head>
<title>Frank's Portfolio</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="myPortfolio.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">

</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" id="my-navbar">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>

<a class="navbar-brand" href="">Frank Lucas</a>
</div> <!-- Navbar header -->
<div class="collapse navbar-collapse navbar-right" id="navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="">About Me</a></li>
<li><a href="">Portfolio</a></li>
<li><a href="">Contact Me</a></li>
</ul>
</div>
</div> <!-- End Container-->
</nav> <!--End navbar -->

<div id="pageOne">
<h1>Some text</h1>
<h1>Some text</h1>
<h1>Some text</h1>
<h1>Some text</h1>
</div>



<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>

最佳答案

我认为您必须为 ID 为#pageOne 的div 赋予高度,以便它覆盖屏幕的一部分。
这里我缩放了#pageOne 相对于视口(viewport)高度的高度

body{
background: silver;
}
#pageOne {
background: url(http://oi68.tinypic.com/21entzo.jpg);
background-size: cover;
height: calc(100vh - 56px);
background-repeat: no-repeat;
margin-top: 56px;
}
<!DOCTYPE html>
<html>
<head>
<title>Frank's Portfolio</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="myPortfolio.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">

</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" id="my-navbar">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>

<a class="navbar-brand" href="">Frank Lucas</a>
</div> <!-- Navbar header -->
<div class="collapse navbar-collapse navbar-right" id="navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="">About Me</a></li>
<li><a href="">Portfolio</a></li>
<li><a href="">Contact Me</a></li>
</ul>
</div>
</div> <!-- End Container-->
</nav> <!--End navbar -->

<div id="pageOne">

</div>



<script src="https://code.jquery.com/jquery-3.1.0.min.js" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>

关于jquery - 我在 div 中的图像没有文字显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38960712/

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