Reputation: 841
This seems like it should be a lot simpler, however I've tried a looking at a few other answers to previous similar questions and haven't managed to get anywhere.
I've been trying to use CSS to get my logo and an inline-block unordered list to float vertically in my header.
On the logo I tried
vertical-align: middle;
which didn't do anything, and I also tried:
top: 50%;
transform: translateY(-50%);
-webkit-transform: translateX(-50%);
which sent both of the items to the very top of the header, halfway off the screen.
I tried the second rule on the unordered list as well and that made both items move to the left of the screen.
Really not sure what's going on, but I was hoping to find a solution that means they remain vertically centred if I adjust the height of the header, as I'll be using this template / wordpress theme in the future for other sites and it will make my life easier in the future.
My CSS is:
.header {
width: 75%;
height: 100px;
margin: 0 auto;
}
img.standard.logo {
position: relative;
float: left;
height: 40px;
width: 360px;
}
.header nav ul{
display:block;
float:right;
padding:0;
margin-top:12px;
margin-bottom:0px;
list-style:none;
}
Upvotes: 0
Views: 70
Reputation: 9334
The simple solution would be to push it by margin-top:
img.standard.logo {
margin-top: 30px;
}
Upvotes: 1
Reputation: 406
There are many ways to do this:
If your logo image and header will continue to have fix heights you can just add a margin-top to hard-center it.
I like to use this when I need to vertically center something:
.parent {
position: relative;
}
.child {
position: absolute;
top: 50%;
transform: translateY(-50%);
}
Flexbox
There are a lot of different solutions. Use the one that works best for you and you co-workers.
Upvotes: 0