html - 当有垂直导航栏/侧边栏时,如何使文本居中?

标签 html css

我的网站左侧有一个垂直导航栏,因此当我将文本居中时,它会居中,但不会在绿色部分居中。

.sidebar {
    position: fixed;
    height:100%;
    left: 0;
    top: 0px;
    width: 300px;
    background:#6495ED;
}
 
h1 {
    text-align: center;
}
 
ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    width: 300px;
    background-color: #6495ED;
}
 
li a {
    display: block;
    color: #000000;
    padding: 8px 0 8px 16px;
    text-decoration: none;
    font-size: 50px;
    font-family: "Verdana", Geneva, sans-serif;
}
 
 
li a:hover {
    background-color:#27C0FD;
    color: #000000;
}
 
<html>
<link rel="stylesheet" type="text/css" href="css.css">
<body bgcolor="#81F781">
<head>
<h1> Informational Tech Site</h1>
 
</head>
 
<body>
<div class="sidebar">
    <ul>
    <li><a href="#home">Home</a> </li>
    <li><a href="#news">News</a></li>
    <li><a href="#contact">Contact</a></li>
    <li><a href="#about">About</a></li>
</ul>  
</div>
 
</body>
  

代码在这里。 http://pastebin.com/xgvt4P0a

这是文本居中的图像,但绿色部分未居中。 /image/8MuaC.jpg 谢谢!

最佳答案

您使用了错误的 HTML,所以我不会继续。

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css.css">
</head>
<body bgcolor="#81F781">
<div id="sidebar">
    <ul>
        <li><a href="#home">Home</a> </li>
        <li><a href="#news">News</a></li>
        <li><a href="#contact">Contact</a></li>
        <li><a href="#about">About</a></li>
    </ul>  
</div>
<div id="content">
    <h1> Informational Tech Site</h1>
<div>
</body>
</html>

关于html - 当有垂直导航栏/侧边栏时,如何使文本居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36028832/

相关文章:

javascript - 需要简单的 JavaScript HTML DOM 函数的帮助

html - 移动设备上的响应式 Web 问题

css - 如何避免应用来自外部样式表文件的样式?

javascript - 用透明区域覆盖div

html - 在页面中居中导航列表

jquery - jQuery FancyTree 没有可见的连接器或图标

css - polymer 中的::part() 与 Microsoft-Edge 不兼容

CSS 第一个和最后一个子元素

jquery - 在 Jquery/HTML 上实现拖放功能

php - 将所有输入字段扩展到值的大小或使用 javascript 删除所有输入字段。