gpt4 book ai didi

html - (HTML)(CSS) 为什么我的多列布局的左侧看起来比另一个小?

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

https://jsfiddle.net/drqjmssy/

从 jsfiddle 链接,我试图让“div class='main_content'”与“div class='sidebar'”的垂直高度相同。如何做到这一点?如果您无法加载 fiddle 或它的格式很糟糕,这是我的代码:

<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>My project</title>
<style>

body {
background-color: #5A4E3C;
color: #E9EBBF;
}

header {
background-color: #D8E472;
padding: 2%;
}

nav {
background-color: #D8E472;
}

footer {
background-color: #D8E472;
padding: 2%;
color: #5A4E3C;
}

h1 {
color: #5A4E3C;
}

li {
display: inline-block;
}

nav > ul {
margin-top: 0;
margin-bottom: 0;
}

.wrapper {
width: 85%;
background-color: #418E8E;
margin: 0 auto;
}

.main_content {
width: 56%;
padding: 2%;
column-count: 1;
float: left;
background-color: #418E8E;
margin: 0;
}

.sidebar {
width: 36%;
padding: 2%;
column-count: 1;
float: left;
background-color: #418E8E;
}

</style>
</head>
<body>

<div class='wrapper'>

<header>
<h1>Main Heading</h1>
</header>

<nav>
<ul>
<li><a href='1.html'>Page 1</a></li>
<li><a href='2.html'>Page 2</a></li>
</ul>
</nav>

<div class='main_content'>
<article>
<h2>Subhead</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</article>
</div>

<div class='sidebar'>
<article>
<h2>Subhead</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</article>
</div>

<footer>
&copy Yazen 2018.
</footer>

</div>

</body>
</html>

抱歉,如果其中任何内容令人困惑。//////////////////////////////////////////////////////////////////////////////

最佳答案

您可以将元素包装在一个新标签中(我使用了 section)并添加 display: flex

body {
background-color: #5A4E3C;
color: #E9EBBF;
}

header {
background-color: #D8E472;
padding: 2%;
}

nav {
background-color: #D8E472;
}

footer {
background-color: #D8E472;
padding: 2%;
color: #5A4E3C;
}

h1 {
color: #5A4E3C;
}

li {
display: inline-block;
}

nav>ul {
margin-top: 0;
margin-bottom: 0;
}

.wrapper {
width: 85%;
background-color: #418E8E;
margin: 0 auto;
}

.main_content {
width: 56%;
padding: 2%;
column-count: 1;
float: left;
background-color: #418E8E;
margin: 0;
}

.sidebar {
width: 36%;
padding: 2%;
column-count: 1;
float: left;
background-color: #418E8E;
}

section {
display: flex;
}
<div class='wrapper'>

<header>
<h1>Main Heading</h1>
</header>

<nav>
<ul>
<li><a href='1.html'>Page 1</a></li>
<li><a href='2.html'>Page 2</a></li>
</ul>
</nav>
<section>
<div class='main_content'>
<article>
<h2>Subhead</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</article>
</div>

<div class='sidebar'>
<article>
<h2>Subhead</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</article>
</div>
</section>
<footer>
&copy Yazen 2018.
</footer>

</div>

关于html - (HTML)(CSS) 为什么我的多列布局的左侧看起来比另一个小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48897321/

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