I just noticed that my website inexplicably has horizontal scrolling enabled

When creating a website with a forum, I encountered an issue where the page can be scrolled horizontally only on the forum page. I am using minimal CSS and primarily Bootstrap for styling. Upon removing the <div class="container col-md-6" style="margin-top: 1rem" container, the horizontal scrolling disappears. This leads me to believe that the issue is related to this particular element, but I am unsure of the exact cause. Here is the code snippet:

<html lang="nl">
    <head>
        <title>name</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="assets/css/style.css">
        <link href='https://fonts.googleapis.com/css?family=Quicksand' rel='stylesheet'>
        <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94f6fbfbe0e7e0e6f5e4d4a1baa4baa6">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
        <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d4f4242595e595f4c5d6d18031d031f">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
    </head>
    <body>
        <?php 
        include 'assets/header.php';
        require_once('assets/getInfo.php');
        ?>
        <div class="row">
            <div class="container col-md-6" style="margin-top: 1rem">
                <?php
                foreach (getPost()['posts'] as $item) {
                    echo "  <div class='list-group' style='font-family: Quicksand; margin-top: .5rem'>
                                <a href='#' class='list-group-item list-group-item-action' aria-current='true'>
                                    <div class='d-flex w-100 justify-content-between'>
                                        <h5 class='mb-1'> " . $item['titel'] . " </h5>
                                        <small>" . $item['bericht_create_date'] . "</small>
                                    </div>
                                    <p class='mb-1'>" . $item['bericht'] . "</p>
                                    <small>Posted by " . $item['username'] . "</small>
                                </a>
                            </div>";
                }
                echo "
                <div class='container col-md-8 text-center justify-content-center' style='margin-top: .5rem;'>
                    <a class='btn btn-primary' role='button' href='forum?page=1'><<</a>
                    <a class='btn btn-primary' role='button' href='" . prevpage() . "'><</a>
                    <a class='btn btn-primary' role='button' href='" . nextpage() . "'>></a>
                    <a class='btn btn-primary' role='button' href='" . lastpage() . "'>>></a>
                </div>
                ";
                ?>
            </div>
            <?php
            if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
                echo 
                "<div class='container col-md-3' style='margin-top: 1rem'>
                <form method='post' action='assets/postAddHandler'>
                    <div class='form-group'>
                        <label for='formGroupExampleInput'>Title</label>
                        <input type='text' name='titel' class='form-control' id='formGroupExampleInput' placeholder='Example input'>
                    </div>
                    <div class='form-group'>
                        <label for='exampleFormControlTextarea1'>Message</label>
                        <textarea class='form-control' name='bericht' id='exampleFormControlTextarea1' rows='3'></textarea>
                    </div>
                    <div class='form-group'>
                        <label for='exampleFormControlFile1'>Photo</label>
                        <input type='file' name='foto' class='form-control-file' id='exampleFormControlFile1'>
                    </div>
                    <div class='form-group' style='margin-top: .5rem'>
                        <button type='submit' name='addPost' class='btn btn-success'>Add post</button>
                    </div>
                </form>
                </div>
                ";
            }
            ?>
        </div>  
    </body>
</html>

Answer №1

To enhance the layout, include a new element with the class ".container" enclosing the existing ".row" class element within this basic structure:

<div class="container">
    <div class="row">
        <div class="col">
            <h3>Column 1</h3>
            <p>text</p>
        </div>
        <div class="col">
            <h3>Column 2</h3>
            <p>text</p>
        </div>
    </div>
</div>

Answer №2

I have made some updates to your code in the hopes that it will work for you. The revised version should look like this:

<html lang="nl">

<head>
    <title>name</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="assets/css/style.css">
    <link href='https://fonts.googleapis.com/css?family=Quicksand' rel='stylesheet'>
    <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bbd9d4d4cfc8cfc9dacbfb8e958b9589">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2a4845455e595e584b5a6a1f041a0418">[email protected]</a>/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
        crossorigin="anonymous"gt;</script>
</head>

<body>

<div class="container">
   
    <div class="page" style="margin-top: 1rem">
        <div class="row">
            <div class="col-6 mx-auto">
                <div class='list-group' style='font-family: Quicksand; margin-top: .5rem'>
                                <a href='#' class='list-group-item list-group-item-action' aria-current='true'>
                                    <div class='d-flex w-100 justify-content-between'>
                                        <h5 class='mb-1'> " . $item['titel'] . " </h5>
                                        <small>" . $item['bericht_create_date'] . "</small>
                                    </div>
                                    <p class='mb-1'>" . $item['bericht'] . "</p>
                                    <small>Posted by " . $item['username'] . "</small>
                                </a>
                            </div>
            </div>
                
                <div class="col-12 mx-auto mt-3">
                <div class='text-center justify-content-center' style='margin-top: .5rem;'>
                       
                    <a class='btn btn-primary' role='button' href='forum?page=1'><<</a>
                    <a class='btn btn-primary' role='button' href='" . prevpage() . "'><</a>
                    <a class='btn btn-primary' role='button' href='" . nextpage() . "'>></a>
                    <a class='btn btn-primary' role='button' href='" . lastpage() . "'>>></a>
                </div>
                </div>
            </div>

                <div class="container">
                    <div class="row">
                        <div class="col-12">
                <form method='post' action='assets/postAddHandler'>
                    <div class='form-group'>
                        <label for='formGroupExampleInput'>Titel</label>
                        <input type='text' name='titel' class='form-control' id='formGroupExampleInput' placeholder='Example input'>
                    </div>
                    <div class='form-group'>
                        <label for='exampleFormControlTextarea1'>Bericht</label>
                        <textarea class='form-control' name='bericht' id='exampleFormControlTextarea1' rows='3'></textarea>
                    </div>
                    <div class='form-group mt-2'>
                        <label for='exampleFormControlFile1'>Foto</label>
                        <input type='file' name='foto' class='form-control-file' id='exampleFormControlFile1'>
                    </div>
                    <div class='form-group' style='margin-top: .5rem'>
                        <button type='submit' name='addPost' class='btn btn-success'>Add post</button>
                    </div>
                </form>
                        </div>
                    </div>
                </div>
         
    </div>
</div>
</body>

</html>

In addition to these code changes, you can add the following properties to your CSS stylesheet:

html, body {
  max-width: 100%;
  overflow-x: hidden;
  padding:15px;
}

This will help make the appearance of your website more consistent and user-friendly.

Lastly, the updated Bootstrap codes should resemble the image found at this link: https://i.sstatic.net/1YA4N.png

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

Conceal the Material UI Grid element and allow the following Grid Item to smoothly transition into its place

I need to create a form where certain Textfields must be hidden. However, when I attempt to hide a Grid item within a Grid container using display: none, the next grid item does not move to take its place. Instead, it creates whitespace. Is there a soluti ...

Various lists do not appear directly under each other

Hello everyone, I recently created a webpage displaying different lists of football players. My goal is to keep the lists stacked vertically without any floats that would make them appear side by side. The separate lists are essential for properly categori ...

CSS styles do not apply to PDF files when downloading

My table headers are styled with writing-mode: vertical-lr, and they look perfect on the screen. https://i.sstatic.net/cQ6Vm.jpg However, when I used the same CSS to style the PDF file, the headers did not display vertically. It seems like the PDF file d ...

Changing the Size of X-Axis Labels Font in a Line Chart Using ChartJS

Struggling with adjusting the font size of x-axis labels in my line chart design using ChartJS. I've attempted to set the x-axis ticks to my desired size, but the font size remains unchanged: options:{ scales:{ xAxis: [{ ...

What is the reasoning behind utilizing the "&" selector in CSS?

.navigation { position: fixed; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: translation: all ease 0.25s; &.expand { transform: translateX(0); } } JavaScript file: $(document).ready(func ...

Only displaying sub items upon clicking the parent item in VueJS

I'm in the process of designing a navigation sidebar with main items and corresponding sub-items. I want the sub-item to be visible only when its parent item is clicked, and when a sub-item is clicked, I aim for it to stand out with a different color. ...

Tips for creating responsive designs with specific media queries for various device sizes

I am looking to create a responsive website using media queries and have already created different media queries for mobile, tablets, and desktops. However, I am unsure if I should be writing the same CSS code multiple times for various device sizes, such ...

What causes the variance in style between the two div elements?

As I delve into the world of styled-components, I decided to create this component: import React from 'react' import styled from 'styled-components' const Row = styled.div` ` const Column = styled.div` flex: 0 0 50%; max-widt ...

Vue's reactivity fails to activate when utilizing Bootstrap 5's alert container

Why Vue's reactivity is not triggered when using Bootstrap 5's alert div? Take a look at my code: <template> <div> <div v-if="alertICDMsg!==''" id="alertICDCode" cl ...

Rotate CSS elements dynamically using jQuery

I'm trying to figure out how to change the rotation value of an image element in my code. Currently, the rotation is set to 315 degrees, but I want to change it to 0 when a click event occurs. Can anyone help me with this? ...

Can the footer be adjusted to be full width only?

Is there a way to stretch only the footer on a blogger simple template to full width without altering other elements? I have looked into similar topics, but they mainly focus on WordPress or involve changing multiple elements, which is not suitable for my ...

How to properly align a form with a multi-lined label in HTML and CSS?

I'm looking to create a form label that spans multiple lines and align the inputs with the labels. The goal is for the "Releasse Date" label to display as: Release Date (YYYY-MM-DD): [input box] Here's how it currently looks: https://i.sstatic ...

Creating an opaque effect on a Material UI Drop down menu: Step-by-step guide

For the last half hour, I've been experimenting with my Select dropdown menu in an attempt to make it semi-transparent, but without success. I've tried adjusting the properties of the Paper, then the Menu, and then the MenuList, yet it appears th ...

"Troubleshooting: Issue with CSS code on Codepen when trying to create

I am attempting to replicate the Google logo using HTML and CSS. While the code functions properly in browsers, there seems to be an issue with Codepen not positioning the horizontal blue line correctly. How can this be resolved? What adjustments should ...

When clicking on HTML input fields, they do not receive focus

I am facing a puzzling issue where I am unable to access the input fields and textareas on my HTML form. The JS, HTML, and CSS files are too large for me to share here. Could someone provide guidance on what steps to take when troubleshooting this unusual ...

Tips for toggling Bootstrap 5 tabs using JavaScript instead of the button version

I am looking to switch tabs programmatically using bootstrap 5. The Bootstrap documentation recommends using buttons for tabs instead of links for a dynamic change. Here is the code I have: $("#mybut").click(function() { var sel = document.querySelector( ...

Minifying HTML, CSS, and JS files

Are there any tools or suites that can minify HTML, JavaScript, and CSS all at once? Ideally, these tools should be able to: Identify links from the HTML document and minify the associated JavaScript and CSS. Remove any unused JavaScript functions and CS ...

Problematic Scenario with Bootstrap 5 Bundle and Jquery Spinner

I'm encountering an issue while trying to implement the Bootstrap 5.3.3 (BS5) bundle with a JQuery spinner for inputs with quantity control - everything seems to be functioning correctly, except that the up and down arrows are not visible on the spinn ...

Struggling with implementing Mobile Navigation menu

I'm struggling to implement a mobile menu for my website. After adding the necessary code, when I view the page in a mobile viewport, all I see are two sets of periods ("..."). However, unlike in the code snippet provided, the list does appear on the ...

How can you ensure a div stays at the top or bottom of a page based on the user's scrolling behavior?

Hello there! While I know there have been many questions regarding sticking a div to the top or bottom while scrolling, my particular issue is a bit more specific. My dilemma is that I am looking for the div to stick either to the top or the bottom based ...