float text beside navbar

Viewed 163

I used bootstrap to create a full screen vertically aligned navbar. The problem is the remaining html code doesn't show up beside the navbar, it doesn't show up at all, i tried using floats but it doesn't seem to fix the problem. Please what is wrong with my code

UPDATE: fiddle of the code

.nav a {
    color: white;
}

.nav {
    background-color: #221e47;
}

.nav a:hover,
.nav a:focus {
    color: #6f7589;
}

.container-width {
    width: 300px;
    position: absolute;
    float: left;
}

.content {
    z-index: -1;
    float: left;
}

.name-tag {
    font-family: serif;
    font-size: 20px;
    color: black;
}
<!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Admin</title>

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">


    <script src="https://kit.fontawesome.com/2299250aec.js" crossorigin="anonymous"></script>

    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script>
</head>

<body>
    <div class="container-width h-100">
        <nav class="nav flex-column h-100">
            <a class="nav-item nav-link active mt-5 p-2" href="#"><i class="mr-2 fas fa-home"></i>Dashboard</a>
            <a class="nav-item nav-link mt-5 p-2" href="#"><i class="mr-2 fas fa-user"></i>Users</a>
            <a class="nav-item nav-link mt-5 p-2" href="#"><i class="mr-2 fas fa-dollar-sign"></i>Coupons</a>
            <a class="nav-item nav-link mt-5 p-2" href="#"><i class="mr-2 fas fa-cog"></i>Settings</a>
            <a class="nav-item nav-link mt-5 p-2" href="#"><i class="mr-2 fas fa-sign-out-alt"></i>Logout</a>
        </nav>
    </div>

    <div class="content">
        <h3 class="name-tag">user name</h3>
        <hr style="height:2px;border:none;color:#eee;background-color:#eee;">
        <!-- some other tags -->
    </div>
</body>

</html>

2 Answers

The navbar have width 300px and position absolute. If you want the content area not to stand under the navigation must be applied to this area margin-left. They are not needed z-index or float.

In order not to be stuck in the navigation, I added 20px and result is 320px from left side. For symmetry I added 20px from the right side

Replace class .content with this one:

.content {
    margin-left: 320px;
    margin-right: 20px;
}

Make z-index: -1; of code you want to display beside simple

Related