issues with buttons resizing when the page is reduced

I am struggling with the navigation bar design as it looks awful when the page is resized.

Everything looks fine in desktop mode, but shrinking the page causes issues. The buttons become oversized due to long text exceeding the container:

<section class="main_buttons">
    <div class="container d-none d-sm-none d-md-block">
      <div class="row">
          <div class="col-xl-3 col-lg-3 col-md-3">
              <div class="button">
                  <div class="nav_btn btn btn-primary">
                      <div class="contenitore">
                          <a href="#customise-template">three long words</a>
                          <img src="assets/img/.." alt="">
                      </div>
                  </div>
              </div>
          </div>
          <div class="col-xl-3 col-lg-3 col-md-3">
              <div class="button">
                  <div class="nav_btn btn btn-primary">
                      <div class="contenitore">
                          <a href="#customise-template">testtest</a>
                          <img src="assets/img/.." alt="">
                      </div>
                  </div>
              </div>
          </div>
          <div class="col-xl-3 col-lg-3 col-md-3">
              <div class="button">
                  <div class="nav_btn btn btn-primary">
                      <div class="contenitore">
                          <a href="#customise-template">testtesttest</a>
                          <img src="assets/img/.." alt="">
                      </div>
                  </div>
              </div>
          </div>
          <div class="col-xl-3 col-lg-3 col-md-3">
              <div class="button">
                  <div class="nav_btn btn btn-primary">
                      <div class="contenitore">
                          <a href="#customise-template">test test test test</a>
                          <img src="assets/img/..." alt="">
                      </div>
                  </div>
              </div>
          </div>
      </div>

      <div class="row">
          <div class="col-xl-3 col-lg-3 col-md-3">
              <div class="button">
                  <div class="nav_btn btn btn-primary">
                      <div class="contenitore">
                          <a href="#customise-template">testtest test testtest</a>
                          <img src="assets/img/.." alt="">
                      </div>
                  </div>
              </div>
          </div>
          <div class="col-xl-3 col-lg-3 col-md-3">
            <div
            class="button">
                <div class="nav_btn btn btn-primary sos-button">
                    <div class="contenitore">
                        <a href="#customise-template">test test test</a>
                    </div>
                </div>
            </div>
        </div>
          <div class="col-xl-3 col-lg-3 col-md-3">
              <div
              class="button">
                  <div class="nav_btn btn btn-primary sos-button">
                      <div class="contenitore">
                          <a href="#customise-template">testtest test</a>
                      </div>
                  </div>
              </div>
          </div>
      </div>
  </div>

STYLING DETAILS BELOW

.nav_btn  {
    text-align: left !important;
    margin: 2px 0;
    width: 100%;
    background-color: white !important;
    border:2px solid #0062CC;
    padding-left: 10px;
    font-size: 16px;
    &:hover {
      background-color:  #0062CC !important;
    }
    &:hover a {
      color:white !important;
    }
    .contenitore {
      width:100%;
      display: flex;
      justify-content: space-between;
      i {
       line-height:20px;
      }
      img {
       width: 20px;
      }
      a {
       text-decoration: none;
       color:#0062CC;
       font-weight: bold;
      }
    }
  }
}

.button .sos-button {
  border: 2px solid #ff4081;
  &:hover {
    background-color:  #ff4081 !important;
  }
  &:hover a {
    color: white;
  }
  a {
    color: #ff4081 !important;
  }
}

Answer №1

When using width with borders, be cautious as it can sometimes cause elements to appear larger than expected. To control the button width outside of the .nav_btn class, consider the following solutions that have been tested and proven effective.

.button {
    width: 200px;  //You can try this approach
}
.nav_btn  {
    text-align: left ;

    margin: 2px;
    background-color: white ;
    border:2px solid #0062CC;
    padding-left: 10px;
    font-size: 16px;
}
.nav_btn:hover {
    background-color:  #0062CC ;
}
.nav_btn a:hover {
    color:white ;
}
.contenitore {  
    display: flex;
    justify-content: space-between;
}
i {
    line-height:20px;
}
img {
    width: 20px;
}
a {
    text-decoration: none;
    color:#0062CC;
    font-weight: bold;
}
.button .sos-button {
    border: 2px solid #ff4081; 
}
.button .sos-button:hover {
    background-color:  #ff4081;
}
.button .sos-button:hover a {
    color: white;
}  
a {
    color: #ff4081;  
}

You may also want to experiment with this alternative:

.nav_btn  {
    text-align: left ;
    width: 200;         //or you can try this method
    margin: 2px;
    background-color: white ;
    border:2px solid #0062CC;
    padding-left: 10px;
    font-size: 16px;
}
.nav_btn:hover {
    background-color:  #0062CC ;
}
.nav_btn a:hover {
    color:white ;
}
.contenitore {  
    display: flex;
    justify-content: space-between;
}
i {
    line-height:20px;
}
img {
    width: 20px;
}
a {
    text-decoration: none;
    color:#0062CC;
    font-weight: bold;
}
.button .sos-button {
    border: 2px solid #ff4081; 
}
.button .sos-button:hover {
    background-color:  #ff4081;
}
.button .sos-button:hover a {
    color: white;
}  
a {
    color: #ff4081;  
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

customize ng-boostrap modal size

Struggling with an issue where my modal is constantly full-screen. Here's the button that calls the modal inside the template: <button type="button" class="btn btn-danger" (click)="openRejectModal(rejectTemplate)">Reject</b ...

Creating an arrow icon alongside a pseudo:hover::before element

This is my custom code snippet: .privacycheck1 { position: relative; top: 265px; background-color: #CF0000; width: 24px; height: 24px; left: 843px; border-radius: 50px; border: 5px #E60000; } .privacycheck1::before { position: relative ...

What is the best way to align text and an arrow on the same line, with the text centered and the arrow positioned on the

.down { transform: rotate(45deg); -webkit-transform: rotate(45deg); } .arrow { border: solid black; border-width: 0 3px 3px 0; display: inline-block; padding: 30px; } <p>Down arrow: <i class="arrow down"></i></p> Looking to ...

What could be causing the .remove() method to malfunction in my current environment?

I'm new to jQuery and struggling with the .remove() method. Despite finding similar questions, I'm still unable to solve my issue. Within an HTML file, there's a form alongside a div acting as an alert box, indicating whether the form was v ...

"Troubleshooting a Problem with Dynamically Creating Buttons on Android

I am currently working on dynamically creating buttons in my Android application based on the number of items stored in my SQLite database. The buttons are appearing as expected, but I am facing an issue with setting the onClick event for each button. My g ...

Having trouble applying overlays to list items with CSS

I'm currently working on a grid gallery where I've set the List items to be 20% wide so there can be 5 in one row using float:left. Now, I'm trying to add an overlay effect by using a div with the class "overlay" so that when someone hovers ...

The Kenburn zoom image effect fails to function

I want to implement a zoom effect on an image using the Ken Burns effect when it is clicked. However, the code I have written does not seem to be working as expected. Here is the code snippet: $(document).ready(function () { $('.kenburns').on( ...

Ways to extend div to fill the rest of the page's vertical space

Apologies, my search has yielded many results, but none that directly address my specific issue. It appears that there is a proliferation of div-height problems on this platform. :-( Here is the layout I am working with for testing purposes: <!DOCTYPE ...

Are there any jQuery plugins available that can automatically resize images to fit within a div in a collage-style layout?

I'm interested in creating a layout similar to what I see on for my portfolio project. My goal is to showcase images that span the full width, occupy 1/4 or 1/2 of the div, and fade in smoothly. I envision them arranging themselves in a dynamic news ...

Is there a way to have the logo effect return to its original state when the user scrolls back up to the top of the page?

Are there any new suggestions for my issue? The previous solutions I received didn't quite work, but I'm grateful for the effort. I am currently working on a project where logo 1 fades out in the header as logo 2 fades in while scrolling down. H ...

What is the most effective method for dimming or disabling a Material-UI div?

Within my application, there are instances where I need to dim and disable the mouse events for certain div elements based on the component's state - such as when it's loading. My initial approach involved creating a helper function that generate ...

What could be causing the Bootstrap 4.4.1 Media Query to not function properly?

Attempting to incorporate a responsive design into my web application utilizing media queries with Bootstrap 4.4.1. Conducting tests on the media queries using the following Shown below is the styles.css code @media only screen and (max-width: 575.98px) ...

What is the best way to eliminate the dotted border from clickable images?

The client has expressed their dislike for the dotted border, but I believe it is important to keep it for accessibility reasons. However, I suppose I will have to remove it since the client requested it. How should I proceed? ...

Tips for aligning an image within a div, using a specific aspect ratio, while maintaining the original height and width

Apologies for the confusing title, but I'm struggling to find the right words to explain my issue. How can I properly fit my image labeled as "carouselMap" within the div named "carouselItem" while maintaining an aspect ratio of 2 ...

Selectors that can be applied to multiple IDs with identical functions

I have a script for popups that I want to be able to use multiple instances of. For example, I would like to have 5 popups on one page without having to change the JavaScript code. While everything in the script works fine, I am struggling to make it work ...

CSS grid-box experiencing issues due to interference from bootstrap styling

When attempting to create a grid, I noticed that the first image element is not showing up in the first position as expected. Instead, it appears in the second position, leaving the first spot blank. After inspecting the issue, I realized that the styles f ...

Excessive padding issues arising from Bootstrap 4 columns and rows

Utilizing bootstrap to structure columns and rows for my images is causing excessive padding around them, deviating from the intended design: https://i.sstatic.net/8cQVg.png Here's the HTML structure I employed: <!-- header --> <header> ...

The concept of CSS "preload" animation

When working with CSS, I encountered an issue with lag while loading 24 different mask images for a transition effect. To address this, I tried using a div called "preload" to cache the images and prevent lag on playback: <div class='trans' s ...

Positioned in the middle is a collection of left-aligned divs

While many questions address similar issues, the focus is always on having all items centered (accomplished by using display:inline-block). However, my requirement is to have the last line of items floated neatly left and only center the container itself ( ...

Troubleshooting spacing and padding problems in Bootstrap 5.2.3's Scrollspy feature

Hello, I'm currently working on developing a new portfolio template that features a list on the left side to guide users through different sections of the page. Utilizing Scrollspy in Bootstrap 5.2.3 has been helpful so far, but I've noticed that ...