我使用固定位置的侧边栏导航。问题是它在每个打开的页面上阻止了它背后的内容:
并不是这样的。当屏幕改变它的大小时,我希望侧边栏和页面内容并排,而不是一个在另一个上面。我怎样才能实现呢?侧栏的HTML和CSS代码如下:
HTML:
<div class="sidenav">
@Html.ActionLink("Home", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
@Html.ActionLink("Vendedores", "Index", "Vendedores", new { area = "" }, new { @class = "navbar-brand" })
@Html.ActionLink("Vendas", "Index", "Venda", new { area = "" }, new { @class = "navbar-brand" })
<footer class="footer">
<p>© @DateTime.Now.Year - Vendedores</p>
</footer>
</div>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<div class="container body-content">
@RenderBody()
<hr />
</div>
CSS:
/*CSS da barra lateral*/
.sidenav {
height: 100%;
width: 250px;
position: fixed;
z-index: 1;
float: left;
top: 0;
left: 0;
background-color: #111;
padding-top: 60px;
}
.sidenav a {
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s;
}
/* 2017 - Vendedores*/
.footer {
color: #818181;
position: fixed;
left: 2%;
bottom: 0px;
width: 100%;
}
答案 0 :(得分:1)
为您的主要内容提供与您的固定边栏相同宽度的左边距.. IE ..
margin-left: 100px;
答案 1 :(得分:1)
你有几种可能性:
position:fixed
,只需浮动:左。
body
{
display:flex;
flex-direction: row;
width:100%;
height:200px
}
nav
{
height: 100%;
width: 250px;
background-color: #111;
color:white;
}
section
{
flex:1;
background-color:red;
}
<body>
<nav>
navigation bar
</nav>
<section>
</section>
</body>