我正在尝试将文本置于下拉菜单的每个标题中,同时让菜单的实际“下拉”部分中的文本与左侧对齐。
我的下拉部分按照我想要的方式对齐,但我似乎无法将标题对齐。
HTML代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Clothing Selector</title></head>
<link rel="stylesheet" type="text/css"href="main.css" />
<body background="Pictures/background.png">
<h2 id="home_subhead">Keep Track Of Your Clothes :-)</h2>
<video id="band_shirts_banner" width="20%" autoplay loop>
<source src="band_shirts_banner.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
<div id="menu">
<ul class="menu" align="center">
<li><a>Shirts</a>
<ul>
<li><a href="band_shirts.html">Band Shirts</a></li>
<li><a href="night_shirts.html">Sleeping Shirts</a></li>
<li><a href="trash_shirts.html">Trash Shirts</a></li>
</ul>
</li>
<li><a>Pants</a>
<ul>
<li><a href="royal_bones.html">Royal Bones</a></li>
<li><a href="rude.html">Rude</a></li>
</ul>
</li>
<li><a>Shoes</a>
<ul>
<li><a href="converse.html">Converse</a></li>
<li><a href="boots.html">Boots</a></li>
</ul>
</li>
</ul>
</div>
</body>
</html>
CSS代码:
ul, ul ul {
margin: 0;
padding: 0;
list-style: none;
}
.menu > li > a {
background-color: #616975;
background-image: -webkit-gradient(linear, left top, left bottom, from(rgb(114, 122, 134)),to(rgb(80, 88, 100)));
background-image: -webkit-linear-gradient(top, rgb(255, 0, 0), rgb(0, 0, 0));<!---------COLOR OF BAR @ BOTTOM OF DROPDOWN LIST---------->
background-image: -moz-linear-gradient(top, rgb(114, 122, 134), rgb(80, 88, 100));
background-image: -o-linear-gradient(top, rgb(114, 122, 134), rgb(80, 88, 100));
background-image: -ms-linear-gradient(top, rgb(114, 122, 134), rgb(80, 88, 100));
background-image: linear-gradient(top, rgb(114, 122, 134), rgb(80, 88, 100));
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#727a86', EndColorStr='#505864');
border-bottom: 0.0625em solid #33373d;
-webkit-box-shadow: inset 0px 1px 0px 0px #878e98;
-moz-box-shadow: inset 0px 1px 0px 0px #878e98;
box-shadow: inset 0px 1px 0px 0px #878e98;
width: 100%;
height: 2.75em;
line-height: 2.75em;
text-indent: 2.75em;
display: block;
position: relative;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 600;
color: #fff;
text-shadow: 0px 1px 0px rgba(0,0,0,.5);
}
.menu ul li a {
background: #fff;
border-bottom: 0.0625em solid #efeff0;
width: 100%;
height: 2.75em;
line-height: 2.75em;
text-indent: 2.75em;
display: block;
position: relative;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 0.923em;
font-weight: 400;
color: black;<!---------DROPDOWN MENU TEXT COLOR---------->
}
.menu ul li:last-child a {
border-bottom: 0.0625em solid #33373d;<!---------COLOR OF BAR @ BOTTOM OF DROPDOWN LIST---------->
}
.menu > li > a:hover, .menu > li > a.active {
background-color: #35afe3;
background-image: -webkit-gradient(linear, left top, left bottom, from(rgb(69, 199, 235)),to(rgb(38, 152, 219)));
background-image: -webkit-linear-gradient(top, rgb(255, 0, 0), rgb(255, 0, 0));<!---------COLOR OF HEADER WHEN HOVERING---------->
background-image: -moz-linear-gradient(top, rgb(69, 199, 235), rgb(38, 152, 219));
background-image: -o-linear-gradient(top, rgb(69, 199, 235), rgb(38, 152, 219));
background-image: -ms-linear-gradient(top, rgb(69, 199, 235), rgb(38, 152, 219));
background-image: linear-gradient(top, rgb(69, 199, 235), rgb(38, 152, 219));
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#45c7eb', EndColorStr='#2698db');
border-bottom: 0.0625em solid #103c56;<!---------COLOR OF THIN BAR @ BOTTOM OF HEADER---------->
-webkit-box-shadow: inset 0px 1px 0px 0px #6ad2ef;
-moz-box-shadow: inset 0px 1px 0px 0px #6ad2ef;
box-shadow: inset 0px 1px 0px 0px #6ad2ef;
}
.menu > li > ul li a:before{
content: '▶ ';
font-size: .5em;
color: black;<!---------COLOR OF ARROWS ON THE SIDE OF DROPDOWN LIST---------->
}
.menu > li > ul li:hover a,
.menu > li > ul li:hover a span,
.menu > li > ul li:hover a:before {
color: #32373D;<!---------COLOR OF TEXT IN DROPDOWN LIST---------->
}
.menu li {
float:left;
width:15em;
}
ul li ul{
display: none;
}
ul li:hover ul{
display: block; /* display the dropdown */
}
看看“裤子”是不是处于中间位置?
感谢任何帮助
答案 0 :(得分:0)
您只需要在要在CSS或HTML代码中居中的部分添加text-align: center;
即可。
或者您可以将<center>
标记用于您想要居中的每个标题。
我做的是删除了CSS text-indent: 2.75em;
设计中的.menu > li > a
。
我认为这就是您的标题文字没有居中的原因。