【发布时间】:2021-10-17 20:57:51
【问题描述】:
我是 CSS 的新手。我通过玩 WordPress 主题的代码来学习。 上次我发布了这个问题,但我感染了新冠病毒并住院了两个多星期。我删除了旧问题并将最初的问题分成两部分。这是第一部分。
删除左侧的站点名称。我使用了 display: none。
<div id="header-left">
<div id="hgroup" class="logo-disable">
<h1 id="site-title">
<a href="https://wp-themes.com/catch-kathmandu/" title="Catch Kathmandu" rel="home">Catch Kathmandu</a>
</h1>
<h2 id="site-description"> Catch Kathmandu Theme is a fully responsive WordPress theme that looks elegant on any devices.</h2>
</div><!-- #hgroup -->
</div>
#header-left {
-webkit-text-size-adjust: 100%;
color: #404040;
line-height: 1.8;
text-rendering: optimizeLegibility;
word-wrap: break-word;
border: 0;
font-family: inherit;
font-size: 100%;
font-style: inherit;
font-weight: inherit;
margin: 0;
outline: 0;
padding: 0;
vertical-align: baseline;
float: left;
max-width: 100%;
display: none;
}
将右侧的菜单居中对齐。
<div id="header-right" class="header-sidebar widget-area">
<aside class="widget widget_nav_menu">
<div id="primary-menu-wrapper" class="menu-wrapper">
<div class="menu-toggle-wrapper">
<button id="menu-toggle" class="menu-toggle" aria-controls="main-menu" aria-expanded="false"><span class="menu-label">Menu</span></button>
</div><!-- .menu-toggle-wrapper -->
<div class="menu-inside-wrapper">
<nav id="site-navigation" class="main-navigation" role="navigation" aria-label="Primary Menu" aria-expanded="false">
<ul id="menu-primary-items" class="menu nav-menu"><li class="current-menu-item"><a href="https://wp-themes.com/catch-kathmandu/">Home</a></li><li class="page_item page-item-2"><a href="https://wp-themes.com/catch-kathmandu/?page_id=2">About</a></li><li class="page_item page-item-182"><a href="https://wp-themes.com/catch-kathmandu/?page_id=182">Home</a></li><li class="page_item page-item-46 page_item_has_children" aria-haspopup="true"><a href="https://wp-themes.com/catch-kathmandu/?page_id=46">Parent Page</a><button class="dropdown-toggle" aria-expanded="false"><span class="screen-reader-text">expand child menu</span></button><ul class="children"><li class="page_item page-item-49"><a href="https://wp-themes.com/catch-kathmandu/?page_id=49">Sub-page</a></li></ul></li></ul> </nav><!-- .main-navigation -->
</div>
#header-right {
-webkit-text-size-adjust: 100%;
color: #404040;
line-height: 1.8;
text-rendering: optimizeLegibility;
word-wrap: break-word;
border: 0;
font-family: inherit;
font-size: 100%;
font-style: inherit;
font-weight: inherit;
margin: 0;
outline: 0;
padding: 0;
vertical-align: baseline;
padding-top: 50px;
float: right;
margin-right: 33%;
}
我通过将右边距从 50% 减少到 33% 来达到我的中心对齐。虽然甜蜜点在 32% 到 33% 之间。
我还尝试将菜单与像素居中对齐(margin-right :400px)。
当我减小屏幕尺寸时,两种方法之间的差异是显而易见的。 33% 大部分保持居中对齐,但 px 会随着屏幕的变化而改变菜单的位置。
还有其他方法可以使菜单居中吗?
【问题讨论】:
-
请把 HTML 和 CSS 的组合一起贴出来。
-
你能分享一下 HTML 让我们看看有什么问题吗?还请考虑在您的问题中将 HTML 和 CSS 放在 Snippet 中。
-
弹性盒还是网格?
-
我投票结束这个问题,因为您需要在此处发布minimal reproducible example,在您的问题中 How to Ask
-
@Nitheesh 我已经用所需的 HTML 和 CSS 更新了问题。感谢您指出我的错误。