• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.
    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML & CSS Positioning two HTML elements neatly in my navBar - Help.

Malcolm

Administrator
Administrator
Verified
Hello!

I'm creating a website template from scratch and I'm trying to insert a logo onto a bar that I'm calling the navBar. However, for some reason I can't seem to figure out why the logo is near the top while my <ul> is near the bottom? I'm trying to center the text vertically (I will try doing vertical-align). Below are an image and the code.


HTML:
<div class="pageHeader">
        <div class="navBarLogo"><img src="./images/dasfdsafdsfdsa.png"></div>
        <div class="navbarTOP">
            <ul>
                <a href="#"><li class="navBarItem">Home</li></a>
                <a href="#"><li class="navBarItem">About</li></a>
                <a href="#"><li class="navBarItem">Contact Us</li></a>
            </ul>
        </div>
    </div>
CSS:
.pageHeader {
    background-color:black;
}
.pageHeader img {
    width: 50px;
    height: 50px;
    float: left;

}
.navBarLogo {
    display:inline-block;
}
.navbarTOP {
    display: inline-block;
}
.navBarItem {
    display: inline-block;
    margin: 0!important;
}
 

Malcolm

Administrator
Administrator
Verified
So I managed to get what I wanted..

I slightly edited the img width/height width: 50 and height: 55px I removed both .navBarLogo and .navbarTOP display:inline-block. And I had edited the margin of .navBarItem to 18px.

HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <link href="global.css" type="text/css" rel="stylesheet" />
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div class="pageHeader">
        <div class="navBarLogo"><img src="./images/dasfdsafdsfdsa.png"></div>
        <div class="navbarTOP">
            <ul>
                <a href="#"><li class="navBarItem">Home</li></a>
                <a href="#"><li class="navBarItem">About</li></a>
                <a href="#"><li class="navBarItem">Contact Us</li></a>
            </ul>
        </div>
    </div>
</body>
</
CSS:
.pageHeader {
    background-color:black;
}
.pageHeader img {
    width: 50px;
    height: 55px;
    float: left;

}
.navBarLogo {

}
.navbarTOP {


}
.navBarItem {
    display: inline-block;
    margin:18px;
}
 

Tealk

Active Coder
Verified
Because you can never overwrite it again.
Especially if you write it yourself, you can determine everything yourself when something is loaded. Important only makes sense if you really want to change something in a finished system.

PS: gives flex a chance, it makes writing so much easier.
 
Top Bottom