gpt4 book ai didi

html - h2 元素将其他 h2 和 div 向下推。两个 div,两个标题,它们被包裹在一个父 div 中

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

我有两个 div“.left-panel”和“.right-panel”包裹在一个名为“.container”的 div 父元素中。一切都很好,我让两个面板在中间对齐,然后我决定为面板添加两个 h2 标题,h2 元素相互向下推。如何在同一行中获取 h2 元素?我试过 float 它们,设置它们的宽度、边距、填充、显示样式……我看了其他答案,但我认为我的不同,因为它被包裹在 div 和 .container div 中!在我的屏幕截图中,它显示 h2 元素跨越整行,我希望在同一行中的两个 h2 元素作为两个 div 的标题。感谢所有帮助,谢谢! h2 element pushing .right-panel and other h2 down

HTML代码

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

<title>Remember Your Diet</title>
<link rel="stylesheet" href="css/style.css">

</head>

<body>

<div class="main-wrapper">
<header class="main-header">
<h1 id="main-logo"><a href="#"> Food </a></h1>

<ul id="main-nav">

<li> <a href="#">How Much </a></li>
<li> <a href="#">Nutrition </a></li>
<li> <a href="#">How Often </a></li>

</ul>

</header>

<div class="container">
<br>
<h2 id="left-header">Food Source</h2>
<div class="left-panel">
<p> The first key to keeping the tracked changes with the text being copied is to make sure the “Track Changes” feature is turned off. To do this, click the “Review” tab on the ribbon. If the “Track Changes” button in the “Tracking” section is highlighted in blue, the “Track Changes” feature is on. Click the lower-half of the “Track Changes” button and select “Track Changes” from the drop-down menu. The “Track Changes” button should not be highlighted when the feature is off</p>



</div>

<h2 id="right-header">Nutritional Facts</h2>
<div class="right-panel">
<p> The first key to keeping the tracked changes with the text being copied is to make sure the “Track Changes” feature is turned off. To do this, click the “Review” tab on the ribbon. If the “Track Changes” button in the “Tracking” section is highlighted in blue, the “Track Changes” feature is on. Click the lower-half of the “Track Changes” button and select “Track Changes” from the drop-down menu. The “Track Changes” button should not be highlighted when the feature is off</p>



</div>

<div class="current-day">
<p> Today is November 10th, 2015

</div>

</div>







</div>
</body>
</html>`

下面的 CSS 代码

    body {
height: 100%;
background-color: green;
}

header {
margin-top: -8px;
margin-left: -10px;
padding: 10px;
background-color: darkgrey;
width: 100%;
}

#main-logo,
#main-nav,
#main-nav li {
display: inline-block;
margin-top: 0px;
margin-bottom: 0px;
}

#main-logo,
#main-nav li {
border-radius: 5px;
list-style-type: none;
}

#main-logo {
background-color: forestgreen;
margin-right: 30px;
}

#main-nav li {
background-color: gold;
margin-right: 10px;
}

#main-logo a,
#main-nav li a {
text-decoration: none;
text-align: center;
}

#main-logo a {
padding: 10px 20px;
color: gold;
}

#main-nav li a {
color: forestgreen;
padding: 20px 40px;
}

.container {
display: inline-block;
width: 100%;
min-height: 550px;
}

#left-header {
max-width:40%;
margin-left: 3%;
color: black;
padding: 0px;
}

#right-header {
max-width:40%;
margin-left: 10%;
color: black;
padding: 0px;
}

.left-panel {
border: 2px solid black;
width: 40%;
min-height: 300px;
display: inline-block;
margin-left: 3%;
background-color: gold;
}

.right-panel {
border: 2px solid black;
width: 40%;
min-height: 300px;
display: inline-block;
margin-left:10%;
background-color: gold;

}

.current-day {
width: 40%;
margin-left: 2.5%;
}

最佳答案

将 H2 元素放在 div 面板中。

<div class="left-panel">
<h2 id="left-header">Food Source</h2>
<p> The first key to keeping the tracked changes with the text being copied is to make sure the “Track Changes” feature is turned off. To do this, click the “Review” tab on the ribbon. If the “Track Changes” button in the “Tracking” section is highlighted in blue, the “Track Changes” feature is on. Click the lower-half of the “Track Changes” button and select “Track Changes” from the drop-down menu. The “Track Changes” button should not be highlighted when the feature is off</p>
</div>

<div class="right-panel">
<h2 id="right-header">Nutritional Facts</h2>
<p> The first key to keeping the tracked changes with the text being copied is to make sure the “Track Changes” feature is turned off. To do this, click the “Review” tab on the ribbon. If the “Track Changes” button in the “Tracking” section is highlighted in blue, the “Track Changes” feature is on. Click the lower-half of the “Track Changes” button and select “Track Changes” from the drop-down menu. The “Track Changes” button should not be highlighted when the feature is off</p>
</div>

然后更改CSS中的样式,从整个div中移除金色背景和边框,并将其仅分配给P标签。

.left-panel {
width: 40%;
min-height: 300px;
display: inline-block;
margin-left: 3%;
}

.right-panel {
width: 40%;
min-height: 300px;
display: inline-block;
margin-left:10%;
}
.left-panel p,
.right-panel p{
border: 2px solid black;
background-color: gold;
}

这是最简单的方法。

关于html - h2 元素将其他 h2 和 div 向下推。两个 div,两个标题,它们被包裹在一个父 div 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33664556/

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