此处发生了什么,除非我向width:40%
添加.menu
之类的内容,否则我似乎无法将导航菜单置于中心位置,但这并不是#&# 39; t工作得很好,会在较小分辨率的显示器上敲下文本
.nav {
width:100%;
height:40px;
display:block;
background-color:#313131;
}
.nav_inner {
height:100%;
margin:0 auto;
position:relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}

<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li><a href="index.html">Home</a></li>
<li><a href="#" style="cursor: default;">About us<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="our-values.html">Our Values</a></li>
<li><a href="technology-partners.html">Technology Partners</a></li>
</ul>
</li>
<li><a href="#" style="cursor: default;">IT Solutions<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="audio-visual.html">Audio Visual</a></li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li><a href="visitor-and-entry-management.html">Visitor & Entry Management</a></li>
</ul>
</li>
<li><a href="contact-us.html">Contact Us</a></li>
</ul>
</nav>
</div>
</div>
&#13;
答案 0 :(得分:3)
你可以简单地使用public class WindowedFileNames extends FilenamePolicy implements OrangeStreamConstants{
/**
*
*/
private static final long serialVersionUID = 1L;
private static Logger logger = LoggerFactory.getLogger(WindowedFileNames.class);
protected final String outputPath;
public WindowedFileNames(String outputPath) {
this.outputPath = outputPath;
}
@Override
public ResourceId windowedFilename(ResourceId outputDirectory, WindowedContext context, String extension) {
IntervalWindow intervalWindow = (IntervalWindow) context.getWindow();
DateTime date = intervalWindow.maxTimestamp().toDateTime(DateTimeZone.forID("America/New_York"));
String fileName = String.format(FOLDER_EXPR, outputPath, //"orangestreaming",
DAY_FORMAT.print(date), HOUR_MIN_FORMAT.print(date) + HYPHEN + context.getShardNumber());
logger.error(fileName+"::::: File name for the current minute");
return outputDirectory
.getCurrentDirectory()
.resolve(fileName, StandardResolveOptions.RESOLVE_FILE);
}
@Override
public ResourceId unwindowedFilename(ResourceId outputDirectory, Context context, String extension) {
return null;
}
}
并使text-align:center
内联阻止像这样:
li
这是完整的代码
.menu>ul {
text-align: center;
margin: 0;
padding: 0;
}
.menu>ul>li {
display: inline-block;
position: relative;
font-size: 16px;
color: #ffffff;
}
&#13;
.nav {
width: 100%;
height: 40px;
display: block;
background-color: #313131;
}
.nav_inner {
height: 100%;
margin: 0 auto;
position: relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color: #ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color: white;
}
.clearfix:after {
display: block;
clear: both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width: 100%;
background: #3e3436;
}
.menu {
margin: 0px auto;
}
.menu li {
margin: 0px;
list-style: none;
}
.menu a {
color: #ffffff;
text-decoration: none;
}
.menu li:hover>a,
.menu .current-item>a {
text-decoration: none;
color: #ffffff;
}
.menu .arrow {
font-size: 12px;
line-height: 0%;
color: #00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu>ul {
text-align: center;
margin: 0;
padding: 0;
}
.menu>ul>li {
display: inline-block;
position: relative;
font-size: 16px;
color: #ffffff;
}
.menu>ul>li>a {
padding: 9px 40px;
display: inline-block;
}
.menu>ul>li:hover>a,
.menu>ul>.current-item>a {
background: #191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index: 1;
opacity: 1;
}
.sub-menu {
width: 160%;
padding: 5px 0px;
position: absolute;
top: 95%;
left: 0px;
z-index: -1;
opacity: 0;
transition: opacity linear 0.15s;
background: #313131;
}
.sub-menu li {
display: block;
font-size: 16px;
}
.sub-menu li a {
padding: 10px 30px;
display: block;
}
.sub-menu li a:hover,
.sub-menu .current-item a {
background: #191919;
}
&#13;
答案 1 :(得分:1)
试试这个:
ul {
text-align: center;
}
.menu > ul > li {
float: none;
}
答案 2 :(得分:1)
为父级(text-align: center;
)设置.menu
,为子级display: inline-block;
设置.clearfix
。
.menu {
text-align: center;
}
.clearfix {
display: inline-block;
padding:0;
}
.menu li {
bottom: 12px;
//more code...
}
.nav { width:100%; height:40px; display:block; background-color:#313131;}
.nav_inner {height:100%; margin:0 auto; position:relative;}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
text-align: center;
}
.clearfix {
display: inline-block;
padding:0;
}
.menu li {
bottom: 12px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
&#13;
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li><a href="index.html">Home</a></li>
<li><a href="#" style="cursor: default;">About us<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="our-values.html">Our Values</a></li>
<li><a href="technology-partners.html">Technology Partners</a></li>
</ul>
</li>
<li><a href="#" style="cursor: default;">IT Solutions<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="audio-visual.html">Audio Visual</a></li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li><a href="visitor-and-entry-management.html">Visitor & Entry Management</a></li>
</ul>
</li>
<li><a href="contact-us.html">Contact Us</a></li>
</ul>
</nav>
</div>
</div>
&#13;
答案 3 :(得分:0)
要使菜单居中,您只需将此CSS添加到菜单中即可。我非常确定它对你有帮助。
.menu ul {
margin: 0 auto;
display: table;
}
.nav {
width:100%;
height:40px;
display:block;
background-color:#313131;
}
.nav_inner {
height:100%;
margin:0 auto;
position:relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li><a href="index.html">Home</a></li>
<li><a href="#" style="cursor: default;">About us<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="our-values.html">Our Values</a></li>
<li><a href="technology-partners.html">Technology Partners</a></li>
</ul>
</li>
<li><a href="#" style="cursor: default;">IT Solutions<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="audio-visual.html">Audio Visual</a></li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li><a href="visitor-and-entry-management.html">Visitor & Entry Management</a></li>
</ul>
</li>
<li><a href="contact-us.html">Contact Us</a></li>
</ul>
</nav>
</div>
</div>
答案 4 :(得分:0)
text-align: center
水平居中嵌套元素如果您在包含的父元素(text-align: center
)上声明.menu > ul
,请移除可能偏移水平对齐的任意margin
或padding
,并移除{{1在列表项(float
)上声明的规则 - 您应该达到预期的结果。
注意:进行水平对齐,使用li
按预期工作,应满足一些要求:
text-align: center
)display: block
)display: inline-block
规则
为了水平对齐,float
规则将否定任何努力
以这种方式对齐元素
float
.nav {
width:100%;
height:40px;
display:block;
background-color:#313131;
}
.nav_inner {
height:100%;
margin:0 auto;
position:relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
/* Additional */
.menu > ul {
margin: auto;
padding: 0px; /* remove arbitrary padding */
text-align: center;
}
/* end Additional */
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:none; /* remove float */
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
text-align: left; /* retain left text-alignment on submenu list items */
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
或者......你可以只使用Flex ...
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li><a href="index.html">Home</a></li>
<li><a href="#" style="cursor: default;">About us<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="our-values.html">Our Values</a></li>
<li><a href="technology-partners.html">Technology Partners</a></li>
</ul>
</li>
<li><a href="#" style="cursor: default;">IT Solutions<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="audio-visual.html">Audio Visual</a></li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li><a href="visitor-and-entry-management.html">Visitor & Entry Management</a></li>
</ul>
</li>
<li><a href="contact-us.html">Contact Us</a></li>
</ul>
</nav>
</div>
</div>
水平居中嵌套元素通过在父元素和flex-box
上声明display: flex
,您将能够水平居中元素。 justify-content: center
实际上非常适合列表项,因为它通常需要特定的嵌套子项,例如: ordered (flex-box
)或 unordered < / em>(ol
)仅列出接受ul
元素作为有效标记的直接嵌套子元素,li
通常具有父对直子“依赖关系”(所以在其他单词,flex-box
规则对于直接嵌套的子项非常有用,但可能会对您在DOM树中更深层次嵌套的其他元素产生负面影响,而这些元素是您想要或不想要的。)
flex-box
请参阅以下展开/* Additional */
.menu > ul {
display: flex;
padding: 0px;
margin: auto;
justify-content: center;
}
解决方案
flex-box
.nav {
width:100%;
height:40px;
display:block;
background-color:#313131;
}
.nav_inner {
height:100%;
margin:0 auto;
position:relative;
}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
height: 40px;
line-height: 15px;
}
/* Additional */
.menu > ul {
display: flex;
padding: 0px;
margin: auto;
justify-content: center;
}
/* end Additional */
.nav_menu li {
float: left;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
/*----- Top Level -----*/
.menu > ul > li {
float:left;
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
text-align: left; /* retain left text-alignment on submenu list items */
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}
抬头! <div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="clearfix">
<li><a href="index.html">Home</a></li>
<li><a href="#" style="cursor: default;">About us<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="our-values.html">Our Values</a></li>
<li><a href="technology-partners.html">Technology Partners</a></li>
</ul>
</li>
<li><a href="#" style="cursor: default;">IT Solutions<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="audio-visual.html">Audio Visual</a></li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li><a href="visitor-and-entry-management.html">Visitor & Entry Management</a></li>
</ul>
</li>
<li><a href="contact-us.html">Contact Us</a></li>
</ul>
</nav>
</div>
</div>
对旧版浏览器的支持很少或有限,所以如果这对您来说是个问题,那么最好不要在生产中使用它。 / p>
IE&lt; = 9 - 不支持
IE 10,11 - 部分支持
查看更多内容: https://caniuse.com/#feat=flexbox
答案 5 :(得分:0)
/ HTML /
<div class="nav">
<div class="nav_inner">
<nav class="hide-mobile menu">
<ul class="navs">
<li><a href="index.html">Home</a></li>
<li><a href="#" style="cursor: default;">About us<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="our-values.html">Our Values</a></li>
<li><a href="technology-partners.html">Technology Partners</a></li>
</ul>
</li>
<li><a href="#" style="cursor: default;">IT Solutions<span class="arrow">▼</span></a>
<ul class="sub-menu">
<li><a href="audio-visual.html">Audio Visual</a></li>
<li><a href="backup-replication-business-continuity.html">Backup, Replication and
<li><a href="visitor-and-entry-management.html">Visitor & Entry Management</a></li>
</ul>
</li>
<li><a href="contact-us.html">Contact Us</a></li>
</ul>
</nav>
</div>
</div>
.nav {width:100%; display:block;文本对齐:中心;背景色:#313131;}
.nav_inner {height:100%; margin:0 auto; position:relative;text-align:center}
.nav_menu {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
line-height: 15px;
}
.nav_menu li {
display:inline-block;
}
.nav_menu li a {
display: block;
color:#ffffff;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.nav_menu a:hover {
background-color: red;
color:white;
}
.clearfix:after {
display:block;
clear:both;
}
/*----- Menu Outline -----*/
.menu-wrap {
width:100%;
background:#3e3436;
}
.menu {
margin:0px auto;
}
.menu li {
margin:0px;
list-style:none;
}
.menu a {
color:#ffffff;
text-decoration:none;
}
.menu li:hover > a, .menu .current-item > a {
text-decoration:none;
color:#ffffff;
}
.menu .arrow {
font-size:12px;
line-height:0%;
color:#00AAFF;
padding-left: 5px;
}
.navs {
float: left;
width: 100%;
}
/*----- Top Level -----*/
.menu > ul > li {
display:inline-block;
position:relative;
font-size:16px;
color: #ffffff;
}
.menu > ul > li > a {
padding:9px 40px;
display:inline-block;
}
.menu > ul > li:hover > a, .menu > ul > .current-item > a {
background:#191919;
}
/*----- Bottom Level -----*/
.menu li:hover .sub-menu {
z-index:1;
opacity:1;
}
.sub-menu {
width:160%;
padding:5px 0px;
position:absolute;
top:95%;
left:0px;
z-index:-1;
opacity:0;
transition:opacity linear 0.15s;
background:#313131;
}
.sub-menu li {
display:block;
font-size:16px;
}
.sub-menu li a {
padding:10px 30px;
display:block;
}
.sub-menu li a:hover, .sub-menu .current-item a {
background:#191919;
}