"Create a unique visual layout with CSS using a four-grid

When utilizing four div grids and increasing the content size of table 2, it causes table 3 to align with table 4, creating a large gap between tables 1 and 3. Is there a way to adjust the responsive content sizing for tables 1, 3, 5... and 2, 4, 6... in order to eliminate the gap between tables 3 and 4?

pg hf1 |
pg hf2

table1 |
table2

table1 |
table2

table1 |
table4

table3 |
table4

where pg hf represents one half of the page i.e col-xs-6.

<!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="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container container-fluid">
  <h1>Offsetting Columns</h1>
  <p>Resize the browser window to see the effect.</p>

    <div class="col-sm-6" style="background-color:lightgray; margin: 7px 0px 7px 0px; overflow-wrap:break-word ">table1fffff ffffff fffff fffff fffff </div>

    <div class="col-sm-6" style="background-color:lightcyan;margin: 7px 0px 7px 0px; overflow-wrap:break-word">table2  yyyyyyy fffffff ffffffy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy  yyyyyyy yyyyyyy yyyyyyy yyyyy</div>

    <div class="col-sm-6" style="background-color:lightgreen; margin: 7px 0px 7px 0px">table3</div>

    <div class="col-sm-6" style="background-color:lightblue; margin: 7px 0px 7px 0px">table4</div>

     <!--<div class="row" style="background-color:lavender;"></div>-->
</div>

</body>
</html>

https://jsfiddle.net/tdcL7o38/4/

Answer №1

Utilizing the CSS Grid Layout is recommended.

Below you can find the code snippets for two types of layouts:

Type 1: One on one

Runnable code available at: https://jsfiddle.net/s0qqhnu7/ https://i.stack.imgur.com/nez7F.png

<body>
       <div class="container container-fluid">
          <h1>Offsetting Columns</h1>
          <p>Resize the browser window to see the effect.</p>
          <div class="row">
             <div class="col-sm-6" style="background-color:lightgray; margin: 7px 0px 7px 0px; overflow-wrap:break-word ">table1fffff ffffff fffff fffff fffff </div>
          </div>
          <div class="row">
             <div class="col-sm-6" style="background-color:lightcyan;margin: 7px 0px 7px 0px; overflow-wrap:break-word">table2  yyyyyyy fffffff ffffffy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy  yyyyyyy yyyyyyy yyyyyyy yyyyy</div>
          </div>
          <div class="row">
             <div class="col-sm-6" style="background-color:lightgreen; margin: 7px 0px 7px 0px">table3</div>
          </div>
          <div class="row">
             <div class="col-sm-6" style="background-color:lightblue; margin: 7px 0px 7px 0px">table4</div>
          </div>
          <!--<div class="row" style="background-color:lavender;"></div>-->
       </div>
    </body>

Type 2: One left and one right

Code snippet link: https://jsfiddle.net/wt70cfcj/

<body>
   <div class="container container-fluid">
      <h1>Offsetting Columns</h1>
      <p>Resize the browser window to see the effect.</p>
      <div class="row">
         <div class="col-sm-6" style="background-color:lightgray; margin: 7px 0px 7px 0px; overflow-wrap:break-word ">table1fffff ffffff fffff fffff fffff </div>
         <div class="col-sm-6"></div>
      </div>
      <div class="row">
        <div class="col-sm-6"></div>
         <div class="col-sm-6" style="background-color:lightcyan;margin: 7px 0px 7px 0px; overflow-wrap:break-word">table2  yyyyyyy fffffff ffffffy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy yyyyyyy  yyyyyyy yyyyyyy yyyyyyy yyyyy</div>
      </div>
      <div class="row">
         <div class="col-sm-6" style="background-color:lightgreen; margin: 7px 0px 7px 0px">table3</div>
         <div class="col-sm-6"></div>
      </div>
      <div class="row">
         <div class="col-sm-6"></div>
         <div class="col-sm-6" style="background-color:lightblue; margin: 7px 0px 7px 0px">table4</div>
      </div>
      <!--<div class="row" style="background-color:lavender;"></div>-->
   </div>
</body>

https://i.stack.imgur.com/GriXb.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

Navigate to a local server running on localhost:3000 and access the external URL www.google.com

When attempting to access an external URL, the website that should open in a new tab is redirecting to http://localhost:3001/www.google.com instead of www.google.com. <IconButton key={index} size="large" color="primary" href={e.url ...

Applying ngClass to handle positive and negative numbers and adjust color in Ionic/Capacitor

I have data from my API that includes price and percentage data. I want to display negative numbers in red, and zero or positive numbers in green. After exploring Angular documentation, I found that ngStyle and ngClass can be used for this purpose. I chose ...

Is there a way to create a JavaScript-driven search filter that updates automatically?

My website showcases a lineup of League of Legends champion icons, with one example shown below: <div class = "champion"> <p>Aatrox <img class = "face_left" src = "images/small/Aatrox.png"> <div class = "name" onmouseover="if(cha ...

Applying binary information to an image

Let's say I have an <img/>. The img is initially set with src='http://somelocation/getmypic'. Later on, there might be a need to change the content of the image based on some ajax call that returns binary data. However, this decision c ...

Is there a way to obtain the coordinates of an SVG element by simply clicking on a specific point?

I'm still learning about SVG and I'm trying to trigger an event that captures the click coordinates when clicking on the SVG. I have a few questions: Since I'm using Angular, I'm unsure if it's possible to keep my function in th ...

Count divisions using PHP and the LI function

I'm struggling with a loop that is responsible for displaying <li> elements, and I need to incorporate a new class into the first item, as well as every sixth subsequent <li> element. For example: while ($db_field = mysql_fetch_assoc($re ...

Steps for including a path to a base64 encoded image

I am currently facing a challenge in embedding images into my emails where I need to encode them using an online tool. The issue I am encountering is that the email template I am using has a dynamic URL, with ${loginurl}/images as the path to my image. H ...

CSS Priority - determining the ultimate winner

I have an upcoming exam and I'm reviewing the previous exam paper that was given to me. The question is: When multiple style sheet rules are applied to the same element, which type of rule takes precedence? a. Any declaration from the browser b. ...

The rounding of my image is uneven across all sides

I'm attempting to give my image rounded borders using border-radius, but I'm unsure if the overflow property is affecting the image. Image 1 shows my current image, while Image 2 depicts what I am trying to achieve. I am utilizing React, HTML, no ...

What are the benefits of keeping JavaScript and HTML separate in web development?

Recently, I came across the concept of Unobtrusive JavaScript while researching best practices in the realm of JavaScript. One particular point that grabbed my attention was the idea of separating functionality (the "behavior layer") from a web page's ...

Tips for transmitting multiple parameters using PHP via AJAX

Welcome to my page where I have a specific functionality that needs to be implemented. What I am looking for is, when the user clicks on the "accept" button, the "accept" function should be called with unique parameters attached to each row. Below is the ...

The selenium element for the submit button is currently not responsive to interactions

Recently, I encountered some challenges with selenium, specifically the anticaptcha API. Although I managed to resolve that issue, I am currently facing a different problem. Below is my existing code: from time import sleep from selenium import webdriver f ...

What is the best way to utilize XPATH effectively within scrapy?

Explore more here Check out this link too: https://i.stack.imgur.com/8bhzV.png If you are struggling with finding the red marked box number, take a look at the image on this link: https://i.stack.imgur.com/mca05.png Don't worry, I have provided my ...

Developing a transparent "cutout" within a colored container using CSS in React Native (Layout design for a QR code scanner)

I'm currently utilizing react-native-camera for QR scanning, which is functioning properly. However, I want to implement a white screen with opacity above the camera, with a blank square in the middle to indicate where the user should scan the QR code ...

Create a soft focus on the background sans any filters

I am in the process of developing a website and have implemented code to blur out the background: CSS #background{ background: url(img/bg.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o ...

Navigational strip within the grid

My grid has a size of 300px. When there are more than 10 records, a vertical scroll bar appears, which is fine. However, at the same time, a horizontal scroll bar also appears, which I do not want to display. My CSS class for vertical scrolling is: .vstyl ...

How to dynamically insert elements into the HTML page using Angular

When my page first loads, it looks like this <body> <div class="col-md-12" id="dataPanes"> <div class="row dataPane"> Chunk of html elements </div> </div> <div class"col-md-12 text-right"> <input type="butt ...

Question about Selecting Boxes

I'm looking for the name of the HTML tool that is used to create a list of objects from a select field. It typically consists of two boxes with an arrow in between them. For example, when creating a group, Box A would contain a list of users and you c ...

The div height set to 100% and using display:flex is experiencing issues in Chrome

Bootstrap 3.0 is utilized in the design. My goal is to have uniform height for all boxes, with the "more" link on the right box positioned correctly. However, the box ends before reaching the more link. Take a look at this JSFiddle example. Here is the H ...

The end of the /if in the small template system fails to correctly detect the desired condition

If I write the following line on its own, he cuts it without any reason. So...: Greetings, I'm in need of assistance regarding an issue that is currently beyond my understanding. I'm facing a challenge with a small TPL-System which requires so ...