Home > database >  How to stop text from overlapping when resizing page
How to stop text from overlapping when resizing page

Time:08-15

When I resize the browser to smaller, the words in my navbar gets overlapped, I want it to stop getting overlapped and stop the text from going closer at a certain point. I tried using margin and space-between but it didnt work. How do I fix this issue. Im using flexbox for my navbar btw.

HTML Code

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="landingpage.css">
        <title>Landing Page</title>
    </head>

    <body>
       <div class='navbar'>
            <div class='left-section'>
                <p class='name'>SugomaBalls</p>
            </div>
            <div class='middle-section'>
                <a href="#"><p>WHY SUGOMABALLS</p></a>
                <a href="#"><p>REVEIWS</p></a>
                <a href="#"><p>ABOUT</p></a>
                
            </div>
            <div class='right-section'>
                <p>LOG IN</p>
                <button class='free-trial'>FREE TRIAL</button> 
            </div>
            
        </div> 
        
    </body>
</html>

CSS Code

body {
                margin: 0px;  
                margin-bottom: 1000px   
            }

            p {
                font-family: Arial;
                white-space: nowrap;
            }

            a {
                font-size: 11px;
                margin-right: 20px;
                color: black;
                font-family: Arial, Helvetica, sans-serif;
                text-decoration: none;
                white-space: nowrap;
            }

            .middle-section {
                display: flex;
                align-items: center;
                justify-content: space-evenly;
                flex:1;
                width: 100px;
                margin-left: 10px
                
            }

            .navbar {
               display:flex;
               align-items: center;
               position: sticky;
               width: 100%;
               top: 10px;
               justify-content: space-between
            }

            .right-section {
                display: flex;
                justify-content: space-evenly;
                width: 200px;
                
            }

            .left-section {
                white-space: nowrap;
            }

            .name {
                font-weight: 600;
                margin-left: 20px;
                font-size:20px;
            }

            .free-trial {
                background-color: white;
                border-style: solid;
                border-width: 1px;
                border-color: black;
                width: 200px;
                height: 40px;
                vertical-align:middle;
                border-radius: 5px;
                margin-left: 30px;
                margin-top: 3px;
            }

            

  body {
                margin: 0px;  
                margin-bottom: 1000px   
            }

            p {
                font-family: Arial;
                white-space: nowrap;
            }

            a {
                font-size: 11px;
                margin-right: 20px;
                color: black;
                font-family: Arial, Helvetica, sans-serif;
                text-decoration: none;
                white-space: nowrap;
            }

            .middle-section {
                display: flex;
                align-items: center;
                justify-content: space-evenly;
                flex:1;
                width: 100px;
                margin-left: 10px
                
            }

            .navbar {
               display:flex;
               align-items: center;
               position: sticky;
               width: 100%;
               top: 10px;
               justify-content: space-between
            }

            .right-section {
                display: flex;
                justify-content: space-evenly;
                width: 200px;
                
            }

            .left-section {
                white-space: nowrap;
            }

            .name {
                font-weight: 600;
                margin-left: 20px;
                font-size:20px;
            }

            .free-trial {
                background-color: white;
                border-style: solid;
                border-width: 1px;
                border-color: black;
                width: 200px;
                height: 40px;
                vertical-align:middle;
                border-radius: 5px;
                margin-left: 30px;
                margin-top: 3px;
            }

            
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="landingpage.css">
        <title>Landing Page</title>
    </head>

    <body>
       <div class='navbar'>
            <div class='left-section'>
                <p class='name'>Balls</p>
            </div>
            <div class='middle-section'>
                <a href="#"><p>WHY BALLS</p></a>
                <a href="#"><p>REVEIWS</p></a>
                <a href="#"><p>ABOUT</p></a>
                
            </div>
            <div class='right-section'>
                <p>LOG IN</p>
                <button class='free-trial'>FREE TRIAL</button> 
            </div>
            
        </div> 
        
    </body>
</html>

CodePudding user response:

You can achieve what you need with a CSS media query.

@media only screen and (max-width: 600px) {
  .middle-section a {
    display: none;
  }
}

This will conditionally apply the given CSS when the screen goes below 600px.

  • Related