gpt4 book ai didi

php - 标题响应问题下方的导航栏

转载 作者:行者123 更新时间:2023-11-28 02:38:48 25 4
gpt4 key购买 nike

我正在尝试启动我的博客,但我被这个问题困住了。我试图在顶部获得一个星空设计的标题,然后在它下面有一个小的导航栏,但是每当我调整页面大小时,标题图像就会出现在页面上,并且下面的导航栏会与其断开连接。如何将导航栏附加到标题,以便在调整大小时,它们连接在一起并且不会分开?这是我的代码

body {
background-color: #D3D3D3;
margin: 0 0 100px;
font-family: "PT-Sans", sans-serif;
}
.header {
position: relative;
left: 0;
top: 0;
width: 100%;
height: 25%;
background-image: url("./img/header-img.png");
background-repeat: no-repeat;
background-size: 100%;
}
.topnav {
background-color: #333;
overflow: hidden;
position: relative;
top: 0;
}

.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}

.topnav a:hover {
background-color: #ddd;
color: black;
}

.topnav a.active {
background-color: #4CAF50;
color: white;
}
.item-right {
}
<html>
<title>Political Blog</title>
<link rel="stylesheet" type="text/css" href="/blog/bootstrap.css">
<link rel="stylesheet" type="text/css" href="/blog/style.css">
<head>

</head>
<body>
<div class="header">

</div>
<div class="topnav">
<a href="/">Home</a>
<a href="./latest">Latest</a>
<a href="./all">All</a>
<a href="./about">About</a>
</div>
</body>
<hr>

最佳答案

这是工作演示:https://jsfiddle.net/ma5sn8c0/

body {
background-color: #D3D3D3;
margin: 0 0 100px;
font-family: "PT-Sans", sans-serif;
}
.header {
display: block;
width: 100%;
height: 200px;
background-image: url("http://via.placeholder.com/900x150/42f4aa/ffffff");
background-repeat: no-repeat;
background-size: 100%;
background-size:cover;
background-position: center center;
}

.topnav {
background-color: #333;
overflow: hidden;
position: relative;
top: 0;
}

.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}

.topnav a:hover {
background-color: #ddd;
color: black;
}

.topnav a.active {
background-color: #4CAF50;
color: white;
}
.item-right {
}
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<div class="header">
</div>
<div class="topnav">
<a href="/">Home</a>
<a href="./latest">Latest</a>
<a href="./all">All</a>
<a href="./about">About</a>
</div>

关于php - 标题响应问题下方的导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45567339/

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