Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

html - trying to align items inside a container whose parent container is header

I have a header container and inside it I have 3 containers for header components header__left , header__middle and header__right ,I have given each of these components a parent container that I want to later use to align child items with , I basically want to align items inside header__left container but whenever I try to add margin-left to make h1 go to the right side of the header__left container it doesn't work

*{
    margin: 0px;
    padding: 0px;
}

header{
    background-color: gray;
    border-bottom: 3px solid red;
}

#logo img{
 
    height: 100px;
    width: 100px;
}

.container{
    width: 80%;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#brand{

    width: 200px;
    
}

#brand h1{

    margin-left: 0 auto;
}
<body>

    <header>
        <div class="container">

            <div class="header__left">
                <div id="brand">
                    <h1>Brand</h1>
                </div>
            </div>



            <div class="header__middle">

                <div id="logo">
                    <img src="phonix.png" alt="">
                </div>

            </div>

            <div class="header__right">

                <ul>

                    <li><a href="#">hOME</a></li>
                    <li><a href="#">About</a></li>
                    <li><a href="#">stuff</a></li>
                </ul>

            </div>


        </div>
    </header>

</body>
question from:https://stackoverflow.com/questions/66059770/trying-to-align-items-inside-a-container-whose-parent-container-is-header

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

as i see you are using two factors on the margin-left property. lets take a look at this part of your code :

#brand h1{

margin-left: 0 auto;}

the margin-left property cant get two factors. its just use on of this items (number, percentage or auto)

so you can use something like margin-left: 10px; to move your Brand html to right.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...