gpt4 book ai didi

html - header 和 div 出现在同一行

转载 作者:行者123 更新时间:2023-11-28 00:35:52 25 4
gpt4 key购买 nike

所以我有一个带有背景图像集的标题,我想在它下面创建一个 div,这样我就可以在那里写文本,但是当我创建新的 div 时,我在里面写的文本会出现在已经创建标题。我认为这是由于我设置的背景图像。这是我第一个完全自己制作的元素之一,所以如果你们能帮助我,我将不胜感激。

这些是 HTML 和 CSS 文件:

body {
margin: 0;
padding: 0;
background-color:#f4f4f4;
float: left;
}

header{
overflow: hidden;
margin: auto;
}

nav {
width: 100%;
height: 50px;
background-color: rgba(192,192,192,0.3);
margin: auto;
}


.wtf {
padding-right: 50px;
position: relative;
bottom: 3px;
}

#logo {
float: left;
color: white;
font-family: 'Concert One', cursive;
padding-left: 20px;
}


p.highlight {
margin: 0;
position: relative;
bottom: 7px;
}


ul {
float:right;
}

li {
display: inline;
padding: 0 10px 0 10px;
}

a {
text-decoration: none;
color: white;
font-size: 21px;
margin: 0 0 3px 0;
font-family: 'Montserrat', sans-serif;
}

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

.image {
background-image: url('nebula-stars-universe-galaxy-space-4k-kx-1920x1080.jpg');
}

.main {
width: 100%;
height: 400px;
color: white;
text-align: justify;
position: absolute;
font-family: 'Montserrat', sans-serif;
background-image: url('nebula-stars-universe-galaxy-space-4k-kx-1920x1080.jpg')
}

.main p,h1,h3 {
text-align: center;
position: relative;
}

.main h1 {
top: 100px;
font-size: 50px;
}

.main h3 {
top: 120px;
}

.main p {
top: 90px;
font-size: 20px;
}

.development {
position: relative;
}

.development p {
color: red;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Упражнение</title>
<link rel="stylesheet"
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Concert+One" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/solid.css" integrity="sha384-+0VIRx+yz1WBc


</head>
<body>

<header>
<div class="image">
<nav>
<div id="logo">
<h1><p class="highlight">ATANAS DEVELOPING</p></h1>
</div>

<div class="wtf">
<ul>
<li class="current">
<a href="#">Home</a>
</li>
<li>
<a href="#">Services</a>
</li>
<li>
<a href="#">Clients</a>
</li>
<li>
<a href="#">Team</a>
</li>
<li>
<a href="#">Contact</a>
</li>
</ul>
</div>
</nav>

<div class="main">
<p>Can you build the website of my dreams?</p>
<h1>YUP, WE CAN DO THAT.</h1>
<h3>Learn More</h3>
</div>
</div>
</header>

<br>
<div class="development">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi aliquam lacus quis ex malesuada fermentum. Sed fringilla porttitor massa sit amet sollicitudin.</p>
</div>


</body>
</html>

最佳答案

您绝对定位了您的 .main:

.main {
position: absolute;
}

通过这种样式,您可以将 .main 从正常的文档流中取出,并将其放置在左上角。其他元素保持正常流动并位于其正上方。只要摆脱这种定位,你就可以开始了。

body {
margin: 0;
padding: 0;
background-color:#f4f4f4;
float: left;
}

header{
overflow: hidden;
margin: auto;
}

nav {
width: 100%;
height: 50px;
background-color: rgba(192,192,192,0.3);
margin: auto;
}


.wtf {
padding-right: 50px;
position: relative;
bottom: 3px;
}

#logo {
float: left;
color: white;
font-family: 'Concert One', cursive;
padding-left: 20px;
}


p.highlight {
margin: 0;
position: relative;
bottom: 7px;
}


ul {
float:right;
}

li {
display: inline;
padding: 0 10px 0 10px;
}

a {
text-decoration: none;
color: white;
font-size: 21px;
margin: 0 0 3px 0;
font-family: 'Montserrat', sans-serif;
}

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

.image {
background-image: url('https://picsum.photos/200/300?image=15');
}

.main {
width: 100%;
height: 400px;
color: white;
text-align: justify;
/* position: absolute; <-- do not position this absolutely */
font-family: 'Montserrat', sans-serif;
background-image: url('https://picsum.photos/1920/1080?image=10')
}

.main p,h1,h3 {
text-align: center;
position: relative;
}

.main h1 {
top: 100px;
font-size: 50px;
}

.main h3 {
top: 120px;
}

.main p {
top: 90px;
font-size: 20px;
}

.development {
position: relative;
}

.development p {
color: red;
}
	<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Concert+One" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/solid.css" >


<div class="image">
<nav>
<div id="logo">
<h1><p class="highlight">ATANAS DEVELOPING</p></h1>
</div>

<div class="wtf">
<ul>
<li class="current">
<a href="#">Home</a>
</li>
<li>
<a href="#">Services</a>
</li>
<li>
<a href="#">Clients</a>
</li>
<li>
<a href="#">Team</a>
</li>
<li>
<a href="#">Contact</a>
</li>
</ul>
</div>
</nav>

<div class="main">
<p>Can you build the website of my dreams?</p>
<h1>YUP, WE CAN DO THAT.</h1>
<h3>Learn More</h3>
</div>

</div>


<div class="development">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi aliquam lacus quis ex malesuada fermentum. Sed fringilla porttitor massa sit amet sollicitudin.</p>
</div>

关于html - header 和 div 出现在同一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54159262/

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