1

I have looked at various other questions on this & haven't been able to find an answer that works for this example.

I'm trying to center the 'about' text to the right (both vertically and horizontally) within its 10% container. As well as the logo being centered within the whole 100% of the header.

HTML

<header>
    <div class="headerContainer">
        <div class="logo">
            <img src="images/App Header.png"/>
        </div>
        <div class="aboutHeader">
            <a href="aboutPage.html"><p>About</p></a>
        </div>
    </div>
</header>

CSS

header{
    display: inline;
}

.headerContainer{
    border-bottom: /* was #979797 or #575757 */ rgba(0,0,0,0.8) 2px solid;
    height: 5rem;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    background-color: #e5e5e5;
    background-size: cover;
    margin: 0;
    padding: 0;
    position: fixed;
    top: 0;
    overflow: hidden;
    text-align: center;
}

.logo{
    width: 80%;
    margin-left: 10%;
}

.aboutHeader{
    width: 10%;
    float: right;
}

.aboutHeader p{
    color: #000;
}

.aboutHeader p:hover{
    color: #3bb7bd;
}

.aboutHeader a{
    color: #000;
    font-style: none;
    text-decoration: none;
}
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
Tucky
  • 29
  • 4
  • Neither answers worked, but I removed the

    tag along with the accompanying CSS & added a height and line-height of 5rem to .aboutHeader. I also changed the .aboutHeader p:hover to .aboutHeader a:hover to keep the hover effect.

    – Tucky May 23 '17 at 09:12

2 Answers2

0

So if you place both of the items inline and then float the link to the right and set the margin-left of the logo 50% it will center.

.logo{
  display: inline;
  width: 100%;
}
.logo img{
  display: inline;
  margin-left: 50%;
}
a{
  display:inline;
  float:right;
}
<header>
    <div class="headerContainer">
        <div class="logo">
            <img src="images/App Header.png"/>
            <a href="aboutPage.html">About</a>
        </div>
    </div>
</header>
imBlue
  • 114
  • 1
  • 11
0

This should do the job. I've slightly edited your code just to highlight my changes (e.g.border and image), you can easily edit it then.

Basically the line-height == to your header height does the trick for the vertical alignment.

.headerContainer{
  background: url("https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.png?v=9c558ec15d8a") center center no-repeat;
  background-size: 150px;
  height: 150px;
  border:1px solid ;
}
.menu{
  height:100%;
  line-height:150px;
  width:11%;
  float:right;
  padding-right:10px;
}
.logo{
  display: inline;
  width: 100%;
}
.logo img{
  display: inline;
  margin-left: 50%;
  max-width:300px;
}
a{
  display:inline;
  float:right;
}
<header>
    <div class="headerContainer">
    <div class="menu">
      <a href="aboutPage.html">About</a>
    </div>
     </div>
</header>