I have this weird situation where the text VanillaJs Cookbook
is forcing the Booking Calendar
text to horizontally align with the text cookbook
. Is there any way to fix this? You can see the black gap that exists above Booking Calendar.

- 7,295
- 7
- 52
- 88
-
have you checked the padding on the parent element? – Jhecht May 04 '16 at 20:56
-
2Please post a [mcve] in your question, not a picture of code. – j08691 May 04 '16 at 20:58
-
@j08691 I have added link to example. – Nikos May 04 '16 at 21:45
-
@Jhecht don't know why this is closed the other question doesn't help. The parent has no padding. – Nikos May 05 '16 at 07:44
2 Answers
The child elements of your <nav>
seem to be positioned "inline" (which can happen by css properties like display: inline
, display: inline-block
but also float: left
, float: right
(in a slightly different way).
But there could also be many more reasons for the result your screenshot shows. I am pretty sure that the <a>
with booking calendar isn't aligned directly to the <span>
with cookbook! in it. It only accidently looks as if it was.
For a first shot you could try to apply the following rule on the <nav>
-element and/or the <ul>
and their child <li>
and their child <a>
, just try and see how the elements alignment changes:
nav {
vertical-align: top;
}
ul,
ul li,
ul li a {
vertical-align-top:
}
Also check the padding of the <li>
and its inner <a>
by giving it a specifig padding-top, e.g. padding-top: 0px;
Please give some more info about the css that applies to the elements for further help.

- 228
- 1
- 7
-
If I change the font size of the VanillaJs Cookbook the booking cal one is still shifted down to the second line of text – Nikos May 04 '16 at 21:24
-
then it's a vertical-align - thing. set the vertical-align to top or let the article and the ul both float: left – user6292372 May 04 '16 at 21:27
-
btw: vertical-align: middle is also worth a try, dont know what result you actually expect – user6292372 May 04 '16 at 21:32
-
This is happening because these elements automatically align to the bottom of their parent.
What I recommend if you're not wanting this behavior is to float both the "article" and the "ul" elements.
This will allow you to move these elements more freely.
However, you will then need to specify a width and height for the entire nav.
Here's an example: https://jsfiddle.net/sL1w49h1/
The styles:
nav {
width: 100%;
height: 150px;
}
article,
ul {
float: left;
}
ul li {
list-style-type: none;
}
.calendar {
margin-top: 24px;
}

- 333
- 2
- 11