Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is float not moving my log in and signup to the right side of the screen?

I’m trying to get my log in and sign-up buttons to move to the right side of the screen and can’t seem to get them there. I first tried adjusting their left-padding to move them and while it gets them there when full screen as soon as the screen is adjusted their size becomes inconsistent. I saw some examples of how to get them there by using float: right but when I do that it doesn’t move them the entire way.

Here is my html: https://pastebin.com/7kAS3Ln5

and my CSS: https://pastebin.com/ffDLJd7j

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    width: 100%;
    height: 70px;
    padding: 0 20px;
    background-color: white;
    top: 0;
    left: 0;
}
.topnav{
    width: 100%;
    height: calc(100vh / 10);
    background-color: #2B78E4;
    display: flex;
    align-items: center;
    /*justify-content: space-between;*/
}
.topnav a{
    text-decoration: none;
    color: black;
    font-family: "Helvetica", sans-serif;
}
.helmet-logo {
    width: 70px;
    height: 70px;


}
/* Dropdown Button */
.dropbtn {
    background-color: #fff1f1;
    color: Black;
    padding: 8px 16px;


}

/* The container <div> - needed to position the dropdown content */
.dropdown {
    position: relative;
    display: inline-block;
    padding: 8px 16px;
    font-style: inherit;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f1f1f1;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

/* Links inside the dropdown */
.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
}

/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd;}

/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
    display: block;
}

/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
    background-color: #f6f6f6;
}
.nav-btn{
    background-color: #fff1f1;
    color: Black;
    padding: 8px 16px;
}
#login-btn{
    position: relative;
    display: inline-block;
    float: right;
}
#signUp-btn{
    position: relative;
    display: inline-block;
    float: right;;
    padding-left: 20px;
}

#login-btn, #signUp-btn {
    float: right;
}

#teams-btn{
    position: relative;
    padding-left: 20px;
}
<header>
    <div class="topnav" id="myTopnav">
        <img src="fb-helmet.png" alt="Logo" class = "helmet-logo">
        <div id ="teams-btn">

           <button class = "nav-btn" ><a href="#Teams">Teams</a></button>

        </div>
        <div class="dropdown">
            <button class="dropbtn">Seasons
                <i class="fa fa-caret-down"></i>
            </button>
            <div class="dropdown-content">
                <a href="www.collegefbarchive.com/seasons/2022">2022</a>
                <a href="www.collegefbarchive.com/seasons/2021">2021</a>
                <a href="www.collegefbarchive.com/seasons/2020">2020</a>
            </div>
        </div>

        <div id ="login-btn">
            <button class = "nav-btn" ><a href="#Login">Log In</a></button>
        </div>

        <div id ="signUp-btn">
        <button class = "nav-btn" ><a href ="#signup">Sign Up</a></button>
        </div>
    </div>
</header>

>Solution :

You don’t need float. Those items have a flex container so you can simply use margin-left and it will give you the expected result. Here is the changes:

#login-btn{
    margin-left: auto;
}

#signUp-btn{
    margin-right: 20px;
}
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    width: 100%;
    height: 70px;
    padding: 0 20px;
    background-color: white;
    top: 0;
    left: 0;
}
.topnav{
    width: 100%;
    height: calc(100vh / 10);
    background-color: #2B78E4;
    display: flex;
    align-items: center;
    /*justify-content: space-between;*/
}
.topnav a{
    text-decoration: none;
    color: black;
    font-family: "Helvetica", sans-serif;
}
.helmet-logo {
    width: 70px;
    height: 70px;


}
/* Dropdown Button */
.dropbtn {
    background-color: #fff1f1;
    color: Black;
    padding: 8px 16px;


}

/* The container <div> - needed to position the dropdown content */
.dropdown {
    position: relative;
    display: inline-block;
    padding: 8px 16px;
    font-style: inherit;
}

/* Dropdown Content (Hidden by Default) */
.dropdown-content {
    display: none;
    position: absolute;
    background-color: #f1f1f1;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
}

/* Links inside the dropdown */
.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
}

/* Change color of dropdown links on hover */
.dropdown-content a:hover {background-color: #ddd;}

/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
    display: block;
}

/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
    background-color: #f6f6f6;
}
.nav-btn{
    background-color: #fff1f1;
    color: Black;
    padding: 8px 16px;
}
#login-btn{
    position: relative;
    display: inline-block;
    float: right;
}
#signUp-btn{
    position: relative;
    display: inline-block;
    float: right;;
    padding-left: 20px;
}

#login-btn, #signUp-btn {
    /* float: right; */
}

#login-btn{
    margin-left: auto;
}

#signUp-btn{
    margin-right: 20px;
}

#teams-btn{
    position: relative;
    padding-left: 20px;
}
<header>
    <div class="topnav" id="myTopnav">
        <img src="fb-helmet.png" alt="Logo" class = "helmet-logo">
        <div id ="teams-btn">

           <button class = "nav-btn" ><a href="#Teams">Teams</a></button>

        </div>
        <div class="dropdown">
            <button class="dropbtn">Seasons
                <i class="fa fa-caret-down"></i>
            </button>
            <div class="dropdown-content">
                <a href="www.collegefbarchive.com/seasons/2022">2022</a>
                <a href="www.collegefbarchive.com/seasons/2021">2021</a>
                <a href="www.collegefbarchive.com/seasons/2020">2020</a>
            </div>
        </div>

        <div id ="login-btn">
            <button class = "nav-btn" ><a href="#Login">Log In</a></button>
        </div>

        <div id ="signUp-btn">
        <button class = "nav-btn" ><a href ="#signup">Sign Up</a></button>
        </div>
    </div>
</header>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading