Issues with the alignment of columns using Bootstrap framework

I've created a design in Photoshop using the Bootstrap 12-column guide, but when I try to implement it using Bootstrap, the results are completely off.

https://i.stack.imgur.com/vQwOt.png

Here's my HTML code:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <style>
    body {
    background-color: #cacaca;

    }
    .container{

    }
    /* Remove the navbar's default margin-bottom and rounded borders */
    .navbar {
      margin-bottom: 0;
      border: 0px solid black;
      border-radius: 0;
b     ackground-color: #2a2b2d;
    }

    .bottom-nav {
      background-color: #1d1e20;
      border: 0px solid black;
      margin-top: 0;
    }
    /* Set height of the grid so .sidenav can be 100% (adjust as needed) */
    .row.content {
      height: 100px
    }

    /* Set gray background color and 100% height */
    .sidenav {
      padding-top: 20px;
      background-color: #f1f1f1;
      height: 100%;
    }

    /* Set black background color, white text and some padding */
    footer {
      background-color: #555;
      color: white;
      padding: 15px;
    }
    .text-left{
      margin-top: 105px;
        border:1px solid black;
        background-color:white;
      }
    .blog{
        border:1px solid black;
        background-color:white;
        margin-right: 10px;
}
  .sidebar{
    margin-left: 10px;
        border:1px solid black;
        background-color:white;
}

    /* On small screens, set height to 'auto' for sidenav and grid */
    @media screen and (max-width: 767px) {
      .sidenav {
        height: 280;
        width:280;
        margin:20px;

      }
      .row.content {height:auto;}
    }
  </style>
</head>
<body>

<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">Logo</a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav">

      </ul>
      <ul class="nav navbar-nav navbar-right">
         <li class="active"><a href="#">Home</a></li>
        <li><a href="#">About</a></li>
        <li><a href="#">Projects</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </div>
  </div>
</nav>
 <nav class="bottom-nav">
 &nbsp;
</nav>
<div class="container text-center">
  <div class="row content">
    <div class="col-md-3 text-left">.col-md-3</div>
    <div class="col-md-3 text-left">.col-md-3</div>
    <div class="col-md-3 text-left">.col-md-3</div>
    <div class="col-md-3"></div>
  </div>
  <div class="row">
    <div class="col-md-9 blog">.col-md-9</div>
    <div class="col-md-3 sidebar">.col-md-3</div>
  </div>
</div>

<footer class="container-fluid text-center">
  <p>Footer Text</p>
</footer>

</body>
</html>

The issue is that in my mockup, there should be 10px of "gutter" between each column, but adding this with margin CSS disrupts the layout.

Additionally, the main blog block (the large white one) should occupy 9 columns, while the sidebar (black element next to it) should take up 3 columns. However, applying the respective columns with margins causes them to shift to a new lineas shown here:

https://i.stack.imgur.com/TepGa.png

I'm fairly new to Bootstrap and struggling to make sense of it! Any guidance would be greatly appreciated, as I'm eager to master this.

Also, is there a way to center the columns like I have in my mockup?

Answer №1

Initially, eliminate the margin-right and margin-left properties from both .blog and .sidebar classes. Next, you can add a div inside div.col-md-3 with a width of 100% and a white background color. Also, remove the background-color:white property from the div.sidebar.

.blog{
    border:1px solid black;
    background-color:white;
}
.sidebar{
    border:1px solid black;
}
.with-space {
    width: 100%;
    background-color:white;
}
/*-------------------*/
<div class="row">
<div class="col-md-9 blog">col-md-9</div>
<div class="col-md-3 sidebar">
  <div class="with-space">col-md-3</div>
</div>

https://i.stack.imgur.com/ehC5P.png

I trust this solution will be beneficial to you...

Answer №2

One suggestion is to close the container div after the first row and then open a new container for the second row. This can help resolve issues with Bootstrap's wrap-around behavior when exceeding 12 columns within a container.

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

"Utilizing ng class with an array of objects: A step-by-step guide

I am facing a scenario in which my response appears as follows: "currency" : [ { "_id" : ObjectId("584aad5d3e2537613e5f4c39"), "name" : "USD" } ], I need to enable my checkbox based on the currency name. I attempted the followi ...

The CSS file is not displaying the background image on the PHP file

I am facing an issue with using CSS to include a background image for the layer, but it doesn't seem to be working correctly... The CSS code snippet is as follows: header { background-image: url("boisko.jpg"); background-repeat: no-repeat; background ...

Adjusting image size to accommodate responsive column cell using CSS

I've been working on optimizing my mobile website using a responsive column layout. The challenge I'm facing is getting the images within each column to stretch to 100% width while automatically adjusting their height. I experimented with settin ...

Angular routing template failing to execute inline JavaScript code

I'm facing an issue with my Angular.js routing implementation. I have successfully displayed the HTML code in templates using angular.js, but now I am encountering a problem with my template structure: <div id="map_canvas" style="width:95%; heigh ...

Transforming the DOM using jQuery

I am looking to manipulate the DOM using jQuery. This is the initial source code: <td class="name"><a href="position_details.php?x=-109&amp;y=95">21</a> </td> <td class="name"><a href="position_details.php?x=-109& ...

Adding external JSON data to a plain HTML document can be achieved through the process of

I have been experimenting with extracting data from an API in JSON format, but I am struggling to figure out how to convert the JSON tags into HTML elements. You can view a sample of the JSON data here. Does anyone know how to transform this JSON into DI ...

I have decided to integrate Laravel with Vite for building CSS and JS. However, when I attempted to run `npm run dev`, it appeared to execute but was accompanied by an error in the background that

Hi there, I'm new to Laravel and I've created a small app that primarily uses CSS and JS scripts. Everything was working fine in my development environment, so I decided to push it to a production server. However, after installation, my code does ...

The functionality of the Ionic menu button becomes disabled once the user has successfully logged in

Having trouble clicking the button after taking a test. Situation: Once logged in -> user takes a test and submits -> redirected to home page. However, unable to click on "Menu button" on the home page. In my Login.ts file: if (this.checker == " ...

Top ways to avoid default on anchor tags: best practices for preventing this issue

Previously, excluding the criticism for not using unobtrusive JS, I typically employed anchors with inline onclick attributes for AJAX loading in the following format: <a href="http://example.com/some/specific/link.php?hello=mum" class="menu" id="m ...

Is there a way to prevent my smartchatbox from covering my fixed top navbar?

Click here for more information I am seeking assistance. Your help is greatly appreciated. The question's heading reveals all you need to know. All you have to do is resize your browser, scroll down, and the answer will become apparent. ...

How come the text is not centered when I use text-align:center; on my class "text5"?

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Homepage</title> ...

CSS guidelines for layering shapes and divs

Currently, I am in the process of developing a screenshot application to enhance my understanding of HTML, CSS, and Electron. One of the key features I have implemented is a toggleable overlay consisting of a 0.25 opacity transparent box that covers the en ...

"Move a div towards the mouse's location by animating it with JavaScript when

I've been working on making the ball element move and shrink towards the goals upon mouse click. I successfully created a function that captures the mouse click coordinates in the goals, but I'm facing challenges with the ball animation. I consi ...

Can CSS be used to generate these shadows?

Check out this image I made showcasing a board with an elongated shadow cast behind it. The intention is to emulate the look of the board leaning against a wall, resulting in a triangular shadow on either side. I'm curious if it's achievable to ...

I am interested in altering the font color

Hey there, I'm new to HTML and CSS and need some help changing the font color and size of my navbar. I've included my code below: HTML code: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <me ...

Using HTML and CSS to Dynamically Alter Cell Text Color Based on Value

Unfortunately, I am unable to find a straightforward solution. My goal is to adjust the text color inside my cell based on its value. Here is a basic table: <table> <tbody> <tr> <td>Quantity</td> <td> ...

What is the process for transferring data (BLOB datatype) to a different table?

I need assistance with transferring data from one blob to another table in the same data type blob. However, I encountered an error message regarding SQL syntax: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB serv ...

Unconventional arrangement of gaps for radio buttons

Hey there, I've been searching for solutions on various platforms but haven't found any luck so far. These are the questions I've looked into: Radio buttons and label to display in same line Documentation on <FIELDSE ...

CSS: Centralize content and use a div to hide images that overflow the container

I successfully centered my divs and images both horizontally and vertically using CSS: .center { height: 100% } .center-center { position: absolute; top: 50%; left: 50%; width: 100%; transform: translate(-50%, -50%); text-align: center; ...

What is the best way to position three DIVs next to each other within another DIV while aligning the last DIV to the right?

I need help formatting a simple list item with three DIVs. The first DIV should be left justified, the second should be able to grow as needed, and the third should be right justified. I currently have them stacked side by side, but can't get the last ...