【问题标题】:Centering the Nav Menu: Wordpress Hemingway Theme导航菜单居中:Wordpress 海明威主题
【发布时间】:2020-05-08 02:41:27
【问题描述】:

我还在学习 CSS,不了解 PhP,所以我可能在这里遗漏了一些简单的东西。

试图使导航菜单 (ul.blog-menu) 居中,但似乎无法弄清楚。已经查看了有关此主题的其他主题,到目前为止,没有一个对我有用。

我正在使用Hemingway Theme by Anders Noren。菜单偏左

网站是http://www.fredwbaker.com/

Menu, offset to left, showing element in inspector

样式表中的相关代码部分如下。感谢您的见解!

/* -------------------------------------------------------------------------------- */
/*	5. Navigation
/* -------------------------------------------------------------------------------- */

.mobile-menu { 
	display: none; 
}

.blog-menu {
	display: flex;
	flex-wrap: wrap;
	list-style: none;
	margin: 0 0 0 -20px;
	}

.blog-menu ul {
	margin: 0;
}

.blog-menu li { 
	line-height: 1;
	margin: 0;
	position: relative;
}

.blog-menu > li + li:before {
	color: #444;
	content: "/";
	display: block;
	font-size: 16px;
	line-height: 1;
	margin: -9px 0 0 -3px;
	position: absolute;
		left: 0;
		top: 50%;
	z-index: 1000;
}

.blog-menu a {
	display: block;
	padding: 27px 20px;
	text-transform: uppercase;
	letter-spacing: 1px;
	color: rgba( 255, 255, 255, 0.5 );
	font-size: 13px;
}

.blog-menu a:hover,
.blog-menu .current-menu-item a { 
	color: #fff;
	text-decoration: none;
}

.blog-menu > .menu-item-has-children a,
.blog-menu > .page_item_has_children a { padding-right: 35px; }

.blog-menu > .menu-item-has-children::after,
.blog-menu > .page_item_has_children::after {
	content: "";
	display: block;
	border: 5px solid transparent;
	border-top-color: rgba( 255, 255, 255, 0.5 );
	position: absolute;
	z-index: 1001;
	right: 17px;
	top: 50%;
	margin-top: -2px;
	transition: border-color .2s ease-in-out;
}

.blog-menu > .menu-item-has-children:hover::after,
.blog-menu > .page_item_has_children:hover::after { border-top-color: #fff; }

.blog-menu li:hover a {
	background-color: #1d1d1d;
	cursor: pointer;
}

.blog-menu li:hover > a { color: #fff; }


/* Sub Menus --------------------------------- */

.blog-menu ul {
	position: inline-block;
	display: none;
	z-index: 999;
	text-align: center;
}

.blog-menu ul li {
    float: none;
    display: block;
}

.blog-menu ul > .menu-item-has-children::after,
.blog-menu ul > .page_item_has_children::after {
	content: "";
	display: block;
	border: 6px solid transparent;
	border-left-color: rgba(255,255,255,0.4);
	position: absolute;
	z-index: 1001;
	right: 10px;
	top: 50%;
	margin-top: -5px;
}

.blog-menu ul > .menu-item-has-children:hover::after,
.blog-menu ul > .page_item_has_children:hover::after { border-left-color: #fff; }

.blog-menu ul li { 	
	width: 240px; 
	background: #1d1d1d;
}

.blog-menu ul a {
	padding: 20px 0px;
	margin: 0 20px;
	line-height: 130%;
	border-bottom: 1px solid rgba(255,255,255,0.1);
}

.blog-menu ul > li:last-child a { border-bottom-width: 0; }

.blog-menu li:hover > ul {
	opacity: 1;
	left: 0;
	display: block;
}


/* Deep down --------------------------------------- */


.blog-menu ul li:hover > ul {
	top: 0;
	left: 240px;
	margin-left: 0;
}

【问题讨论】:

    标签: css wordpress


    【解决方案1】:

    如果您不发送 url 进行检查,我不能肯定这会起作用,但由于博客菜单使用 flex,请尝试添加 justify-content:center。所以:

    .blog-menu {
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        list-style: none;
        margin: 0 0 0 -20px;
    }
    

    【讨论】:

    • 谢谢!这是链接:fredwbaker.com。很抱歉我忘了添加它! justify-content: center;不幸的是没有工作。
    • 您好,没问题,我刚刚在您发送的链接上试了一下,没有问题?您在哪里添加自定义 CSS?
    • 好吧,你摇滚!我将它添加到错误的位置(在样式表本身中)。当我将它添加到附加的 css 部分时。非常感谢!
    • 没问题,很高兴它成功了!你能支持这个答案,让每个人都知道它已经解决了吗?谢谢
    • 完成。它说投票会被记录下来,但不要改变低于 15 名代表的人的公共地位。我确实打了勾。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 2014-06-19
    • 1970-01-01
    • 2015-03-11
    • 1970-01-01
    • 1970-01-01
    • 2014-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多