Reputation: 15
while making a footer for a school task I encountered this problem: both texts should be on the same line, but one goes higher and one goes lower
I tried to put a link in the left side of the footer and some text in the right side. For some reason when I split the divs into their positions they end up like this. Link goes in left top corner and text goes in bottom right corner. I'm trying to get them both VERTICALLY centered but nothing I do gets them both there. I've managed to get both in the center by themselves but never both at the same time. What is going on here?
Here's my html:
<footer>
<div class="link_class">
<a href="./" class="link_class">asd</a>
</div>
<div class="copy_class">
<p>© dsa</p>
</div>
</footer>
and here's the css:
footer{
width: 20%;
height: 5%;
background-color: gray;
display: flex;
justify-content: space-between;
}
Upvotes: 0
Views: 63
Reputation: 2282
Just add this, which aligns them next to each other using the magical powers of flexbox.
align-items: center;
footer{
width: 20%;
height: 5%;
background-color: gray;
display: flex;
align-items: center;
}
<footer>
<div class="link_class">
<a href="./" class="link_class">asd</a>
</div>
<div class="copy_class">
<p>© dsa</p>
</div>
</footer>
Upvotes: 0
Reputation: 116
In your example, the cause is not flex behaviour.
Native browsers styles apply margin to 'p' tags (margin-block-start: 1em;margin-block-end: 1em;) but not to 'a' tags. To solve it, you have some simple options:
Here is the reference of the default browsers styles: https://www.w3schools.com/cssref/css_default_values.asp
Upvotes: 1
Reputation: 402
if you want them to be on separate lines then
align-items: center;
flex-direction: column;
and leave out justify-content
Upvotes: 1