Home > OS >  align right without overflowing the screen CSS
align right without overflowing the screen CSS

Time:12-17

Ok, I'm trying to make a menu. There is the side menu that is going to have certain elements and the top menu that is going to have other elements. I have a problem when I apply the positio:absolute and then a right:0px to align the icons and the name to the right it goes off screen because my body has a margin-left: 280px

let menuToggleButton = document.getElementById('menu_toggle_button');
let side_menu = document.getElementById('side_menu');
let body = document.getElementById('body');

menuToggleButton.addEventListener('click', function() {
    side_menu.classList.toggle('resize-side-menu');
    body.classList.toggle('resize-body');
});
*{
    margin: 0px;
    padding: 0px;
}
body{
    display: flex;
}
.side-menu{
    position: fixed;
    display: inline-flex;
    background: #ff000061;
    width: 280px;
    height: 100vh;
    transition: .5s;
}
.resize-side-menu{
    width: 50px;
    transition: .5s;
}
.body{
    display: inline-flex;
    width: 100%;
    height: 60px;
    margin-left: 280px;
    background: blue;
    height: 2000px;
    transition: .5s;
}
.resize-body{
    margin-left: 50px;
    transition: .5s;
}
.body .content-body{
    display: block;
    width: 100%;
    height: 100%;   
}
.body .content-body .header{
    width: 100%;
    height: 50px;
    display: block;
    position: fixed;
}
.content-items-header{
    display: flex;
    align-items: center;
    background: brown;
    position: relative;
    height: 50px;
}
.body .content-body .header .content-items-header .content-search-input{
    background: white;
    color: rgb(0, 0, 0);
    border: 2px solid blue;
}
.body .content-body .header .content-items-header .icons-content{
    position:absolute;
    right:0px;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.0/css/all.min.css">
</head>
<body>
    <div  id="side_menu">
        
    </div>
    <div  id="body">
        <div >
            <div >
                <div >
                    <button  id="menu_toggle_button">open</button>
                    <div >
                        <input type="text"  id="search">
                        <i ></i>
                    </div>
                    <div >
                        <i ></i>
                        <i ></i>
                        <i ></i>
                    <img src="brain.jpg" alt="" height="35px" width="35px">
                    <span>Aldahir Ruiz Valdez</span>
                    </div>

                </div>
            </div>
            <div >
    
            </div>
        </div>
    </div>
    <script src="main.js"></script>
</body>
</html>


I need them to always be aligned to the right but without leaving the screen

CodePudding user response:

Try removing position: fixed; from .header

CodePudding user response:

try overflow: hidden; or overflow: auto depending on what you want to achieve. overflow: hidden; will hide all the overflow, and overflow: auto will add a scroll bar if it is needed.

  • Related