简体   繁体   English

如何将右侧的图标对齐到导航栏的中心?

[英]How to align the icons on the right to the center of the navigation bar?

I want to align the social media icon on the right in the center of the navigation bar along with the navigation link and logo.我想将导航栏中央右侧的社交媒体图标与导航链接和徽标对齐。 I'm trying to do something like this navigation bar我正在尝试做类似这个导航栏的事情

Link to code链接到代码

You can create a wide div that is centered, create a div containing the icons, put it in the centerd div and then use in css float: right;您可以创建一个居中的宽 div,创建一个包含图标的 div,将其放在居中的 div 中,然后使用 in css float: right;

you can use something like that:你可以使用类似的东西:

<style>
    * {
        padding: 0;
        margin: 0;
    }
    .header {
        width: 100%;
        height: 60px;
        background-color: black;
        display: flex;
        justify-content: center;
    }
    .centered {
        width: 900px;
        height: 60px;
        background-color: red;
        display: flex;
        justify-content: center;
    }
    .text {
        width: 300px;
        height: 60px;
        background-color: yellow;
    }
    .logo {
        width: 200px;
        height: 60px;
        display: flex;
        flex-direction: row;
        position: absolute;
        left: calc(50% + 260px);
    }
    .logo div {
        height: 45px;
        width: 45px;
        border-radius: 7px;
        background-color: yellow;
        position: relative;
        margin-top: 7px;
        margin-left: 14px;
    }
</style>

<div class="header">
    <div class="centered">
        <div class="text">
        </div>
        <div class="logo">
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
</div>

What you're trying to do is probably aligning your content to the vertical center.您要做的可能是将您的内容与垂直中心对齐。 To do that set your navbar display to grid and set grid-template-column according to the structure of the content within your navbar and also place all your social icons within a div that's a direct child of the navbar.为此,请根据导航栏中的内容结构将导航栏显示设置为网格并设置 grid-template-column,并将所有社交图标放置在作为导航栏直接子项的 div 中。

And lastly on the div containing your social-icons, set the properties;最后在包含社交图标的 div 上,设置属性;

 .social_box{ display: flex; justify-self: center; align-content: space-around; justify-content: center; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM