简体   繁体   English

如何将徽标右侧的Wordpress导航栏对齐?

[英]How to align a Wordpress navigation bar to the right of a logo?

I'm trying to get my navigation bar to the right of the logo in my Wordpress theme. 我正在尝试使我的导航栏位于Wordpress主题中徽标的右侧。 It's being built with Underscores. 它是使用Underscores构建的。 I've managed to line up the primary navigation and the logo the way I want it, basically, with this CSS: 基本上,我已经使用此CSS按照我想要的方式将主要导航和徽标对齐:

.main-navigation {
    position: relative;
    float: right;
    top: -4em;
    width: 55%;
    display: block;
    clear: both;
    font-family: 'Lato', sans-serif;
    text-transform: uppercase;
}

.main-navigation ul {
    list-style: none;
    margin: 0;
    padding-left: 0;
    float: right;
}

and here's a picture of how I want it to look: 这是我希望它看起来的图片: 网站徽标,右侧导航

I understand that negative margins (assuming top: -4em; is considered with negative margins) aren't elegant or the best way to handle these sorts of things. 我知道负边距(假设top: -4em;被认为是负边距)不是很好的方法,也不是处理这类事情的最佳方法。 Plus, I generally find these kinds of workarounds usually come back to bite me later on. 另外,我通常会发现这些变通办法通常会在以后引起我的注意。

I'm new to playing around with JSFiddle, so I hope I've done this correctly! 我是JSFiddle的新手,所以我希望我已经正确地做到了! Here's my code, now condensed!: http://jsfiddle.net/DMDesigns/d39ej96r/11/ 这是我的代码,现在已压缩!: http : //jsfiddle.net/DMDesigns/d39ej96r/11/

What's the best way to make this happen? 做到这一点的最佳方法是什么? I've been searching, seen a lot of people ask this question, but many of the answers have been too specific to their website to help me. 我一直在搜索,看到很多人问这个问题,但是许多答案对于他们的网站来说太具体了而无法帮助我。

This took me the better part of the day to figure out, yesterday, but disappointed with the lack of responses, here's what I figured out. 昨天,我花了一天的大部分时间来弄清楚,但是由于缺乏回应而感到失望,这就是我所想的。 I'm posting it here for anyone else having a similar problem. 我将其发布给其他有类似问题的人。

First, I took the logo (named .header-image) and added: 首先,我采用徽标(名为.header-image)并添加:

float: left;
position: relative;

Then I took the navigation I wanted to the left of (named .main-navigation) and removed my workaround, which was 然后我采取了想要的导航(命名为.main-navigation),并删除了我的解决方法,即

float: right; 
top: -4em; 
width: 55%;  

and changed clear:both; 并更改为: to clear:none; 清除:无;

I added a little personal CSS to my .main-navigation to make it match the logo which was 我在.main导航中添加了一些个人CSS,以使其与徽标相同

 height: 112px;
 background: #69d7f9;
 z-index: -1;
 padding: 28px 0;

and I removed any floats from .main navigation ul. 并且我从.main navigation ul中删除了所有浮动。

It's better to create a main div and insert both logo and navigation section in the same div with float:left; 最好创建一个主div并在同一div中使用float:left;插入徽标和导航部分。 for both of them. 为他们两个。 Let me know if you get this or I'll let you know by an example. 让我知道是否可以得到,否则我将举例说明。

Using the Underscores starter theme for WordPress, the navigation bar can be floated to the right of the logo (or site title) using the following method: 使用适用于WordPress的Underscores入门主题,可以使用以下方法将导航栏浮动到徽标(或网站标题)的右侧:

Add the following CSS to your style-sheet: 将以下CSS添加到样式表中:

.site-branding{
    float: left;
    display: inline-block;
}
.site-description{
    display: none;     
}
#site-navigation{
    float: right;
    clear: none;
    width: auto;
}

These instructions are based on the Underscores theme as is before customisation. 这些说明与自定义之前一样,都是基于Underscores主题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM