0

I am currently creating a company website, and I have the logo, but I am wanting to put it inside the Navigation Bar, align it so it is at the far right, but halfway down through the height of the navigation bar. I am wanting to do this using CSS.

Here is my index.html.

<!DOCTYPE html>
<html>
<head>
    <title>Responsive Navigation Bar</title>
    <link rel="stylesheet" type="text/css" href="main.css">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    <img src="images/logo.png" alt="Logo" id="logo" onclick="location.replace('index.html', '_top')">
    <div class="nav">
        <label for="toggle">&#9776;</label>
        <input type="checkbox" id="toggle"/>
        <div class="menu">
            <a href="index.html">Home</a>
            <a href="#Business">Business</a>
            <a href="#Services">Services</a>
            <a href="#LearnMore">Learn More</a>
            <a href="#FreeTrial"><span id="freetrial">Free Trial</span></a>
        </div>
    </div>
</body>
</html>

And here is my main.css

html, body {
width: 100%;
height: 100%;
margin: 0;
}
html {
font-family: "helvetica neue", sans-serif;
}

/* Navigation Bar */

#logo {
text-align: right;
float: right;
}

.nav {
border-bottom: 1px solid #EAEAEB;
text-align: right;
height: 70px;
line-height: 70px;
}
.menu {
margin: 0 30px 0 0;
}
.menu a {
clear: right;
text-decoration: none;
color: grey;
margin: 0 10px;
line-height: 70px;
}

#freetrial {
color: #54D17A;
}

label {
margin: 0 40px 0 0;
font-size: 26px;
line-height: 70px;
display: none;
width: 26 px;
float: right;
}
#toggle {
display: none;
}


@media only screen and (max-width: 500px) {
label {
    display: block;
    cursor: pointer;
}
.menu {
    text-align: center;
    width: 100%;
    display: none;
}
.menu a {
    display: block;
    border-bottom: 1px solid #EAEAEB;
    margin: 0;

}
#toggle:checked + .menu {
    display: block;
    background-color: white;
  }   
}

If you require any more explaining or anything at all in aiding you to answer my question, I will be more than happy to help you, providing it is something that I can actually answer haha.

1 Answers1

0

If I was coding this, I would first put the logo inside the nav div with its own div around it. Then I would use flexbox (it is supported everywhere but IE, btw).

https://css-tricks.com/snippets/css/a-guide-to-flexbox/

Make sure to apply "display: flex;" to the parent div (the nav div, presumably). Then I would apply "align-items: center;" to the nav div. This will align all of the menu items to the middle vertically as well (not sure if you want that).

I would then use "justify-content" to the nav items. Depending on what you want done with the other items in the nav bar, you might use "flex-end" or "space-between".


If you do not want to use flexbox, you should refer to this stack overflow question after moving your image to inside the nav div: How to vertically align an image inside a div?

Then you would set "right: 0;" on the image or image div.


Also, I think you may be using floats incorrectly...

https://css-tricks.com/all-about-floats/

You seem to be using them the way it "seems" like they should work, but they can be confusing... I would get rid of your floats, it might be messing things up. Sorry, I can take a harder look if you want at a later time. Feel free to ask any questions you have!