fixed sidebar overlapping page content?(修复了侧边栏重叠的页面内容?)
问题描述
我使用css和html制作了一个侧边栏。然而,无论我做什么,当我试图在我的HTML页面上放入一些内容时,它都会放在页面的左上角,在侧边栏下面。如何将固定内容放置在页面的右侧?
下面显示的是我的css代码,如果有什么东西阻止主要内容位于页面的右中心,请告诉我。 数据-lang="js"数据-隐藏="假"数据-控制台="真"数据-巴贝尔="假">
.sidebar a {
display: block;
padding: 10px;
}
body {
background-color: white;
}
.sidebar {
margin: 14px;
padding: 0;
width: 175px;
position: fixed;
height: 100%;
overflow: auto;
text-align: left;
margin-left: 30px;
}
<!DOCTYPE HTML>
<html lang="en" dir="ltr">
<head>
<link href="myMenuStyle.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css? family=Bungee+Hairline&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Montserrat&display=swap" rel="stylesheet">
<meta charset="utf-8">
<link rel="import" href="TableOfContent.html">
<title>about me</title>
<link rel="icon" href="cool.ico">
</head>
<body>
<!-- The sidebar -->
<div class="sidebar">
<a id='one' href="TableOfContent.html" style="font-weight: bold">Table of Content</a>
<p><u>Visual Communication:</u></p>
<bl>
<a id='two' class='click' href="GraphicD.html">Graphic Design</a>
<a id='three' class='click' href="Illustration.html">Illustration</a>
<a id='four' class='click' href="Photography.html">Photography</a>
<p><u>Multi Media/Digital Media:</u></p>
<a id='five' class='click' href="Scripting.html">Scripting</a>
<a id='six' class='click' href="Sound.html">Sound</a>
<p><u>Programming:</u></p>
<a id='seven' class='click' href="Coding.html">Coding</a>
<a id='eight' class='click' href="Game.html">Interactive/Game Design</a>
<a id='nine' class='click' href="Arduino.html">Hardware/Electrical Circuit</a>
<p><br></p>
</div>
<!-- Page content -->
<p>Testing</p>
</body>
</html>
推荐答案
您需要首先定义FlexBox布局以从左到右组织内容,这与默认的从上到下的HTMLDOM行为形成对比。要做到这一点,首先将整个容器包装在div
中,然后在其上应用display: flex
。然后将flex-direction: row
设置为从左到右进行排序。但是,当您将块定义为position: fixed
时,它将从文档模型中取出,因此您的右侧内容将显示在左侧fixed
位置块下。要解决这一问题,请在右侧内容上加上左边距(根据左侧容器的宽度,约为15%)。
我对HTML文件进行了几处更改以应用FlexBox:
数据-lang="js"数据-隐藏="假"数据-控制台="真"数据-巴贝尔="假">.sidebar a {
display: block;
padding: 10px;
}
body {
background-color: white;
}
.sidebar {
margin: 14px;
padding: 0;
width: 175px;
position: fixed;
height: 100%;
text-align: left;
margin-left: 30px;
}
.main {
display: flex;
flex-direction: row;
}
.content {
margin-top: 20px;
margin-left: 15%;
}
<!DOCTYPE HTML>
<html lang="en" dir="ltr">
<head>
<link href="myMenuStyle.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css? family=Bungee+Hairline&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Montserrat&display=swap" rel="stylesheet">
<meta charset="utf-8">
<link rel="import" href="TableOfContent.html">
<title>about me</title>
<link rel="icon" href="cool.ico">
</head>
<body>
<!-- The sidebar -->
<div class="main">
<div class="sidebar">
<a id='one' href="TableOfContent.html" style="font-weight: bold">Table of
Content</a>
<p><u>Visual Communication:</u></p>
<bl>
<a id='two' class='click' href="GraphicD.html">Graphic Design</a>
<a id='three' class='click' href="Illustration.html">Illustration</a>
<a id='four' class='click' href="Photography.html">Photography</a>
<p><u>Multi Media/Digital Media:</u></p>
<a id='five' class='click' href="Scripting.html">Scripting</a>
<a id='six' class='click' href="Sound.html">Sound</a>
<p><u>Programming:</u></p>
<a id='seven' class='click' href="Coding.html">Coding</a>
<a id='eight' class='click' href="Game.html">Interactive/Game Design</a>
<a id='nine' class='click' href="Arduino.html">Hardware/Electrical Circuit</a>
<p><br></p>
</div>
<!-- Page content -->
<div class="content">
<p>Testing</p>
</div>
</div>
</body>
</html>
有关Flexbox的详细信息-here
这篇关于修复了侧边栏重叠的页面内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:修复了侧边栏重叠的页面内容?


- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01