侧边栏位置不正确
我正在创建一个简单的网站,但无法正确定位侧边栏。它应该位于内容的右侧,但它一直放在内容的下方。
* {
font-family: verdana;
background-color: lightgray;
}
p {
font-size: 2vh;
}
.logo {
padding-left: 3vw;
}
.navbar {
background-color: #383838;
width: 100vw;
height: 7vh;
}
.navbar a {
font-size: 5vh;
text-decoration: none;
background-color: #383838;
color: white;
padding-left: 3vw;
padding-right: 3vw;
padding-bottom: 0.75vh;
border-right: 0.2vw solid white;
}
.content {
width: 70vw;
height: 80vh;
background-color: white;
padding-top: 0.5vh;
margin-left: 0;
}
.content h1,
.content p {
background-color: white;
color: black;
margin-left: 3vw;
margin-right: 3vw;
}
.sidebar {
background-color: orange;
width: 10vw;
height: 80vh;
}
<h1 class="logo">Logo</h1>
<div class="navbar">
<a href="www.google.com">Home</a>
<a href="www.google.com">Produkte</a>
<a href="www.google.com">Ueber mich</a>
</div>
<div class="content">
<h1>Inhalt</h1>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</div>
<div class="sidebar"></div>
文本是德语的,应该没有什么区别。另外,“.sidebar”是侧边栏,它应该位于“.content”的右侧。
Im creating a simple website but Im having trouble positioning the sidebar correctly. It should be on the right side of the content but it keeps being put below the content.
* {
font-family: verdana;
background-color: lightgray;
}
p {
font-size: 2vh;
}
.logo {
padding-left: 3vw;
}
.navbar {
background-color: #383838;
width: 100vw;
height: 7vh;
}
.navbar a {
font-size: 5vh;
text-decoration: none;
background-color: #383838;
color: white;
padding-left: 3vw;
padding-right: 3vw;
padding-bottom: 0.75vh;
border-right: 0.2vw solid white;
}
.content {
width: 70vw;
height: 80vh;
background-color: white;
padding-top: 0.5vh;
margin-left: 0;
}
.content h1,
.content p {
background-color: white;
color: black;
margin-left: 3vw;
margin-right: 3vw;
}
.sidebar {
background-color: orange;
width: 10vw;
height: 80vh;
}
<h1 class="logo">Logo</h1>
<div class="navbar">
<a href="www.google.com">Home</a>
<a href="www.google.com">Produkte</a>
<a href="www.google.com">Ueber mich</a>
</div>
<div class="content">
<h1>Inhalt</h1>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata
sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</div>
<div class="sidebar"></div>
The text is in german which shouldn't make a difference. Also ".sidebar" is the sidebar and it should be positioned on the right side of ".content".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非您指定
display
属性,否则div
默认情况下将具有display: block;
,它将 div 一个堆叠在另一个之上。一种解决方案是使用
display: flex
创建一个包装 divUnless you specify a
display
property,div
by default will havedisplay: block;
which stacks divs one on top of another.One solution is to create a wrapper div with
display: flex
您可以在 div 中添加
content
和sidebar
。给该 div 一个相对位置,并将sidebar
位置设置为绝对位置,如下所示。You can add
content
andsidebar
in a div. give that div a position relative and makesidebar
position absolute as shown below.