[英]Two-items footer centered with Flexbox
I'm trying to create a footer with 2 elements (logo and copyright) using flexbox.我正在尝试使用 flexbox 创建一个包含 2 个元素(徽标和版权)的页脚。 This is the code:
这是代码:
footer { display: flex; flex-direction: row; flex-wrap: nowrap; margin: 45px; } footer div { flex: 1; } footer img { width: 5%; height: auto; } footer p { font-size: 0.7rem; }
<footer> <div> <img src="https://picsum.photos/200/300" alt="logo"> </div> <div> <p>Copyright Hair Day Salon 2022</p> </div> </footer>
I want to center each element on its side of the flex, but justify-content doesn't work.我想将每个元素放在 flex 的一侧居中,但 justify-content 不起作用。 I also tried to remove flex: 1 from the article and do it afterward, but then the text will wrap into 2 lines and the logo will get bigger (things that I don't want).
我还尝试从文章中删除 flex: 1 并在之后执行此操作,但随后文本将换行成 2 行并且徽标会变大(我不想要的东西)。
What do you think is the issue and how could I center the div elements on the footer?您认为问题是什么?我如何将 div 元素置于页脚的中心? Thanks.
谢谢。
you can use justify-content: center
.你可以使用
justify-content: center
。 just remove your只需删除您的
footer div {
flex: 1
}
to adjust your image调整你的形象
footer { display: flex; margin: 45px; flex-direction: row; flex-wrap: nowrap; justify-content: center; } footer div { } footer.image-inside { width: 25px; height: 25px; } footer img { width: 100%; height: 100%; object-fit: cover; } footer p { font-size: 0.7rem; }
<footer> <div class="image-inside"> <img src="https://picsum.photos/200/300" alt="logo"> </div> <div> <p>Copyright Hair Day Salon 2022</p> </div> </footer>
Added some styling and resolved the issue using text-align:添加了一些样式并使用文本对齐解决了问题:
<footer>
<div class="left">
<img src="./img/logo2.png" alt="logo">
</div>
<div class="right">
<p>Copyright Hair Day Salon 2022</p>
</div>
</footer>
footer {
border: 1px #CF5F4B solid;
margin: 45px auto;
}
footer img {
width: 30px;
height: auto;
padding: 15px;
}
footer .left {
width: 49%;
float: left;
display: inline;
}
footer .right {
width: 49%;
float: right;
display: inline;
}
footer p {
font-size: 0.85rem;
text-align: right;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.