Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • 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.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • 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
Staff Team
Code Plus
Company Plus
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.


[CODE lang="html" title="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>[/CODE]
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;
}
 
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.

[CODE lang="html" title="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>
</[/CODE]
CSS:
.pageHeader {
    background-color:black;
}
.pageHeader img {
    width: 50px;
    height: 55px;
    float: left;

}
.navBarLogo {

}
.navbarTOP {


}
.navBarItem {
    display: inline-block;
    margin:18px;
}
 
Try this:
CSS:
.pageHeader {
    background-color:black;
    display: flex;
    flex-direction: row;
}

.navBarLogo,
.navBarLogo img {
    width: 50px;
    height: 50px;
}

.navBarItem {
    display: inline-block;
    margin: 0;
}

More info about flex: https://www.w3schools.com/csS/css3_flexbox.asp

PS: Never use "!Important"
I'll try this, may I ask why to never use !important?
 
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.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom