gpt4 book ai didi

css - float :right sidebar enjoys sitting below my content

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

我的边栏看起来非常舒服,位于我的内容下方,即页面的左侧。我怎样才能说服它留在它身边?它应该位于页面的右侧,内容位于左侧。我一直在尝试以前对类似问题的回答,但没有任何改变我得到的结果。 This is what I would like the basic format to appear as.

CSS:

#header {
background-color:#ffffff;
color:white;
text-align:center;
padding:5px;
}
#navbar {
background-color:#ffffff;
color:#000000
text-align:left;
padding:5px;
}
#section {
background-color:#ffffff;
width:500px;
float:left;
padding:10px;
}
#sidebar {
line-height:30px;
background-color:#14004d;
height:300px;
width:200px;
float:right;
padding:5px;
}
#footer {
background-color:#14004d;
color:#ffffff;
clear:both;
text-align:center;
padding:5px;
}

HTML:

<body bgcolor="#ffffff">

<div id="header">
<h1><center>header image here</center></h1>

<div id="navbar">
<p style="color:#14004d">
Home&emsp;&emsp;&emsp; Services&emsp;&emsp;&emsp; Portfolio&emsp;&emsp;&emsp; Testimonials
</p>
</div>

<div id="section">
text text text text text text text text text text text text text text text
</div>

<div id="sidebar">
<p style="color:#ffffff">
contact info will be listed here.</p>
</div>


<div id="footer">
Copyright © Cassidy v. Ros Online Marketing Solutions
</div>

</body>

https://jsfiddle.net/3sxn3yaf/

最佳答案

考虑改用百分比宽度(除了 box-sizing 样式之外)。

#section {
/* ... */
width: 70%;
box-sizing: border-box;
/* ... */
}
#sidebar {
/* ... */
width: 30%;
box-sizing: border-box;
/* ... */
}

#header {
background-color: #ffffff;
color: white;
text-align: center;
padding: 5px;
}
#navbar {
background-color: #ffffff;
color: #000000 text-align: left;
padding: 5px;
}
#section {
background-color: #ffffff;
width: 70%;
box-sizing: border-box;
float: left;
padding: 10px;
}
#sidebar {
line-height: 30px;
background-color: #14004d;
height: 300px;
width: 30%;
box-sizing: border-box;
float: right;
padding: 5px;
}
#footer {
background-color: #14004d;
color: #ffffff;
clear: both;
text-align: center;
padding: 5px;
}
<body bgcolor="#ffffff">

<div id="header">
<h1><center>header image here</center></h1>
</div>

<div id="navbar">
<p style="color:#14004d">
Home&emsp;&emsp;&emsp; Services&emsp;&emsp;&emsp; Portfolio&emsp;&emsp;&emsp; Testimonials
</p>
</div>

<div id="section">
text text text text text text text text text text text text text text text
</div>

<div id="sidebar">
<p style="color:#ffffff">
contact info will be listed here.</p>
</div>


<div id="footer">
Copyright © Cassidy v. Ros Online Marketing Solutions
</div>

</body>

关于css - float :right sidebar enjoys sitting below my content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37096295/

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