Tips on eliminating horizontal scrolling in HTML and CSS

I am working on a simple web page template and encountering an issue with a horizontal scroll appearing on the page. I would like to remove it. Below is the code I am using:

 <html lang="FA">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body dir="rtl">
    <section class="bg-blue">
        <div class="container">
            <div class="text-center">
                <img src="logo.png" alt="">
                <h2 class="logo-text d-inline-block p-4 ps-0">My logo text</h2>
            </div>
        </div>
        <div class="row">
            <div class="col-12">
                <img src="" alt="">
            </div>
        </div>
    </section>
    <section class="bg-secondary">
        <div class="container">
            <div class="text-center" style="height: 800px;">
                <div class="search-container">
                    <div class="search-form">
                        <input type="text" class="form-control search-field w-50" placeholder="search">
                    </div>
                    
                </div>
            </div>
        </div>
    </section>

    <footer class="bg-yellow">
        <div class="container">
          
        </div>
    </footer>
</body>
</html>

Here is a screenshot of the result: https://i.sstatic.net/RKAQp.png

Do you have any solutions?

Answer №1

To create horizontal scrollbars, consider adjusting the body's CSS by utilizing the overflow-x property:

.body{
overflow-x:scroll;
}

Answer №2

overflow: hidden; is a recommended practice. However, it is important to review your markup as well. Bootstrap automatically adds a margin-left and margin-right to the row class, with margin-right causing the issue in this scenario.

https://i.sstatic.net/7jJ4M.png

Here is a suggested rearrangement of the markup:

Rearranged Markup:

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="46242929323532342736067368766874">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" />
<section class="bg-blue">
  <div class="container">
    <div class="row">
      <div class="text-center">
        <img src="logo.png" alt="">
        <h2 class="logo-text d-inline-block p-4 ps-0">My logo text</h2>
      </div>
    </div>
    <div class="col-12">
      <img src="" alt="">
    </div>
  </div>
</section>
<section class="bg-secondary">
  <div class="container">
    <div class="text-center" style="height: 800px;">
      <div class="search-container">
        <div class="search-form">
          <input type="text" class="form-control search-field w-50" placeholder="search">
        </div>
      </div>
    </div>
  </div>
</section>

<footer class="bg-yellow">
  <div class="container">

  </div>
</footer>

Original Markup:

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="44262b2b30373036253404716a746a76">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" />
<section class="bg-blue">
  <div class="container">
    <div class="text-center">
      <img src="logo.png" alt="">
      <h2 class="logo-text d-inline-block p-4 ps-0">My logo text</h2>
    </div>
  </div>
  <div class="row">
    <div class="col-12">
      <img src="" alt="">
    </div>
  </div>
</section>
<section class="bg-secondary">
  <div class="container">
    <div class="text-center" style="height: 800px;">
      <div class="search-container">
        <div class="search-form">
          <input type="text" class="form-control search-field w-50" placeholder="search">
        </div>

      </div>
    </div>
  </div>
</section>

<footer class="bg-yellow">
  <div class="container">

  </div>
</footer>

Answer №3

move the div with the class="row" inside the container div

<div class="container">
        <div class="text-center">
            <img src="logo.png" alt="">
            <h2 class="logo-text d-inline-block p-4 ps-0">My logo text</h2>
        </div>
    
    <div class="row">
        <div class="col-12">
            <img src="" alt="">
        </div>
    </div>
</div>

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

Prevent users from selecting an option depending on a specific criteria

I need help with disabling select options based on specific time instances. For example, I want the user to provide specifications by 6:00 am in order to use the system at 10:00 am, ensuring there is a 4-hour gap between the two times. So, after 6:00 am, t ...

Three-handled slider

Just acquired a new slider component <input id="slider_price" type="text" class="span2" value="" data-slider-min="1000" data-slider-max="80000" data-slider-step="5" data-slider-value="[60000, 80000]"/> _ $('#slider_price').slider({ t ...

HTML elements not displaying in Ajax form

I am encountering an issue with my ajax based feedback form where the form is displaying the html from the response instead of processing it correctly. Here is the JQuery code: $(document).ready(function() { var form_holder = $('#form-holder'); ...

Selector matching a descendant element in React styling

I am facing a challenge with using the direct descendant CSS selector within a React inline style element: <style>{` .something>div{ color: blue; } `}</style> While this works fine in development, in production React replaces > ...

Dealing with network issues when submitting a form

Is there a smooth way to handle network errors that may arise during the submission of an HTML form? It is important for me not to have the browser cache any information related to the form, but I also want to ensure that the user's data is not lost i ...

The media query in Css3 is not functioning as expected when using max-width

Struggling to hide a specific element when the screen width reaches 980px or less using media queries. Despite my attempts, the element continues to display. Oddly enough, if I use a media query with min-width instead of max-width, the element disappears ...

Reset the child JSP page to its original appearance

Displayed below is a JSP page: <div id="tabs-7" style="width: 100%;"> <form:form id="deviceForm" name="" modelAttribute="" enctype="multipart/form-data"> <div class="inputWidgetContainer"> <div class="inputWidget"> <table> ...

Properly aligning text with checkboxes using HTML/CSS and tags like <span> or <div>

My goal is to have the text displayed as a block in alignment with the checkbox, adjusting based on the sidebar's width. For reference: Current Layout Preferred Layout I have shared the code on CodePen (taking into account screen resolution and wi ...

Struggling with accurately configuring the input field in AngularJS?

Struggling with clearing the input field I have been attempting to clear the input box with ng-model="newInstruction.instructionText" after a new instruction text is added. However, the input field does not clear even after trying to reset it to an empty ...

Keep the division visible once the form has been successfully submitted

Initially, I have created 3 divs that are controlled using input type buttons. These buttons serve the purpose of displaying and hiding the hidden divs. Within these divs, there are forms to store data. Currently, my goal is to ensure that the div that was ...

Difficulty arises in designing a tableless layout due to the issue of auto

Wondering why my page is not expanding with its content? Check out my demo on Fiddle http://jsfiddle.net/msas3/. The light blue area should determine the overall height of the page. ...

Hover over the text to reveal its content

I am currently in the process of developing a website that features interactive images with text appearing when hovered over. This concept is inspired by the functionality on the nowthisnews.com site. Despite my efforts, I have been unable to get this fea ...

I'm noticing that my Tailwind styles don't take effect until I redefine them. What could be causing

My Tailwind classes are giving me trouble. I faced an issue when I created a new component in the directory and placed my Button component there. Whenever I restart the project in terminal, the styles do not apply to my button unless I manually define th ...

Generating an HTML table using data from a specified URL source

As a beginner, I am working on creating a dashboard for my smart home using OpenHab2.0. One of the key features I want to include is a widget that displays the next 5 tram departures from my local stop. The table structure for this information looks like: ...

Maintaining the footer and bottom section of the webpage

I am facing an issue with the footer on my website . I want the footer to always stay at the bottom of the page, even when I dynamically inject HTML code using JavaScript. The footer displays correctly on the main page , but it does not work as intended on ...

Buttons in Laravel are shifting unexpectedly

There are three buttons available with different functions. <div class="form-group row mb-0"> <div class="col-md-6 offset-md-4"> <button type="submit" class="btn btn-primary"> {{ __('update') ...

Tips for implementing a CSS loader exclusively on a particular section of your content

Is it possible to apply a loader image to a specific section of content on a webpage? All the tutorials I've come across for loader images focus on applying them to entire webpages. However, I am looking to implement a simple loader only to a specifi ...

The outline color cannot be removed from vue-carousel

I recently downloaded the Vue Carousel library and here is the version I am using: "vue": "^2.6.11", "vue-carousel": "^0.18.0", When I click on the pagination, a focus effect is added to the element with an outlin ...

Unable to show the same error message in multiple locations using identical code

I am facing an issue where error messages are not displaying for an empty input field, while they work perfectly fine for a textarea. The if statement for the inputName seems to be working, but the else statement is not being triggered. What could be causi ...

To trigger the opening of one offcanvas menu from another offcanvas menu

I am facing a small issue with opening an offcanvas from a previous canvas. Typically, I have a canvas set up like this using Bootstrap 5: <button class="btn btn-primary" type="button" data-bs-toggle="offcanvas" data-bs-tar ...