What is the best way to design a grid consisting of 14 divs that span the entire width of the browser screen, incorporating dividers to separate different groups, utilizing a combination of html,

I am interested in creating a layout with two rows of divs that span the entire width of the screen, with a total of 14 divs in each row. These divs are fixed in size and grouped by color, with dividers separating each color group.

I am hoping to achieve equidistant spacing between the divs that span the full width of the screen without specifying a fixed width for each div in Bootstrap 4. Is there a way to accomplish this?

Here are the requirements:

  1. All divs are equal in size, regardless of the user's screen width. Resizing the screen should maintain the same number of divs per row.
  2. Divs of the same color should remain grouped together (e.g., green, blue, and orange).
  3. There should be dividers (in black) to separate the color groups.
  4. The layout should be scalable to support the addition of more divs without adjusting percentages or widths of existing elements.
  5. Avoid modifying or overriding the default Bootstrap classes, but custom classes can be added.

I am unsure if Bootstrap 4 or current CSS standards can assist with this challenge.

Link to example image: https://i.sstatic.net/cuGb5.jpg

Currently, I have created 12 individual divs with left floating and margins, but resizing the screen causes some divs to jump to the first row, leaving gaps below. While dividing 100 by 7 for percentage widths is a solution, it feels clunky and leaves whitespace on the container's right side. I am also unsure how to include the black dividers.

I am seeking a more efficient and modern solution. Can Bootstrap 4 help with this issue?

Current solution without black dividers: https://codepen.io/anon/pen/gvKaLW

HTML

<div class="container-fluid">
  <div class="row">
    <div class="col-lg-12">
      <div class="rect green">1</div>
      <div class="rect green">2</div>
      <div class="rect blue">5</div>
      <div class="rect blue"></div>
      <div class="rect blue"></div>
      <div class="rect orange">11</div>
      <div class="rect orange"></div>
      <div class="rect green">3</div>
      <div class="rect green">4</div>
      <div class="rect blue"></div>
      <div class="rect blue"></div>
      <div class="rect blue"></div>      
      <div class="rect orange"></div>
      <div class="rect orange"></div>
    </div>
  </div>
</div>

CSS

.rect {
  background: green;
  width:12%;
  height:200px;
  float:left;
  margin-right:10px;
  margin-top:5px;
  color:white;
  font-size:3em;
}

.green {
  background:green;
}

.blue {
  background:blue;
}

.orange {
  background:orange;
}

Answer №1

To achieve the desired layout using Bootstrap 4, one approach is to utilize 7 col auto-layout columns and nest the rect elements within them. Then, use :after elements for the dividers.

<div class="container-fluid">
    <div class="row no-gutters">
        <div class="col">
            <div class="rect green">1</div>
            <div class="rect green">3</div>
        </div>
        <div class="col">
            <div class="rect green">2</div>
            <div class="rect green">4</div>
        </div>
        <div class="col">
            <div class="rect blue">5</div>
            <div class="rect blue"></div>
        </div>
        <div class="col">
            <div class="rect blue"></div>
            <div class="rect blue"></div>
        </div>
        <div class="col">
            <div class="rect blue"></div>
            <div class="rect blue"></div>
        </div>
        <div class="col">
            <div class="rect orange"></div>
            <div class="rect orange"></div>
        </div>
        <div class="col">
            <div class="rect orange"></div>
            <div class="rect orange"></div>
        </div>

    </div>
</div>

Answer №2

stackoverflow.com/questions/26746168/… <- possibly connected to your inquiry.

Indeed, one approach is to construct a 14-grid bootstrap instead of a 12 grid. The usage of calc(100% / 7) is not a workaround, but rather a legitimate CSS method for modern browsers (CSS3). The issue arises from scaling due to forced whitespace margins. Bootstrap functions by adding padding to the wrappers and then inserting the elements inside, creating the appearance of margin which is actually padding. The padding contributes to the div's width, unlike margin, enabling it to be responsive, especially with box-sizing: border-box.

Therefore, sidestep the bootstrap aspect and utilize customized classes with some unique HTML, like this;

HTML

<div class="container-fluid">
  <div class="row">
    <div class="col-lg-12 customBlocks">
      <div class="block">
        <div class="rect green">1</div>
      </div>

      (contents of the HTML code)

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

CSS

(contents of the CSS code)

FIDDLE

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

Implement a context path in Angular 2 for enhanced functionality

Is there a way to change the base URL for my app from http://localhost:4200 to http://localhost:4200/pilot/? I attempted to modify the base href in index.html, but encountered an Uncaught SyntaxError: Unexpected token < This is the code snippet from m ...

Room available on the body's right side for tiny gadgets

I'm currently facing a website issue while using Bootstrap. Everything seems to be working fine until I attempt to check the responsiveness of my website. There appears to be an excessive white space on the right side of my body, but only in a specifi ...

Scrollspy in Twitter Bootstrap consistently highlights the final element

I'm struggling to understand why only the final section is being highlighted when scrolling. Can you help? <body data-spy="scroll" data-target="#homeToolbar" data-offset="50"> <nav class="navbar navbar-default navbar-fixed-top" id="homeToo ...

I'm feeling a bit lost on where to go next with this JavaScript

I've been working on a project in Python where I need to retrieve a file, store it in an array, and display a random string from the array on HTML. However, I have no experience with JavaScript and am unsure how to proceed. I suspect there may be an i ...

An Angular JS interceptor that verifies the response data comes back as HTML

In my current Angular JS project, I am working on implementing an interceptor to handle a specific response and redirect the user to another page. This is the code for my custom interceptor: App.factory('InterceptorService', ['$q', &ap ...

Why does my array seem to update only once in the view?

I am currently working on a project that aims to visually represent sorting algorithms, but I have encountered an issue. In order to effectively visualize the sorting process of an algorithm, it is crucial to display every change in the array as the proc ...

Unexpected issue encountered for identifiers beginning with a numerical digit

Is it possible to select an element from a page with an id that begins with a number? $('#3|assets_main|ast_module|start-iso-date') Upon attempting to do so, the following error occurs: Uncaught Error: Syntax error, unrecognized expression: ...

Embeddable javascript code can be enhanced by incorporating references into the header

I have developed a basic calculator application using HTML, JavaScript, JQuery, and CSS. My intention is to allow others to embed this calculator app on their own web pages by utilizing a file named generate.js. Within this file, there are several documen ...

What is the reason that styled() does not apply styles to the Material-UI <TextField /> component?

I've managed to figure out a solution, but I'm curious about why this code is working: <TextField label='Zip Code' size='small' InputProps={{ style: { borderRadius: '.4rem' }, }} sx={{ width: & ...

Enhance your visual content by incorporating text onto images with CSS/Bootstrap5

I'm having trouble getting my rows and columns to display on top of my background image. I've been struggling with this issue for a while now. Any assistance on this matter would be greatly appreciated! I'm fairly new to this, so if it&apos ...

Identifying and handling overlay blockers using Selenium technology

Currently, I am conducting tests on a website that utilizes in-browser pop-ups to display details about objects. These pop-ups are occasionally modal, meaning they render the rest of the screen unusable and activate a gray transparent overlay that covers e ...

Angular 2's SVG creations do not resize properly

It is a common knowledge that an svg element with the attribute viewbox should automatically scale to fit the sizes specified in the styles. For instance, let's consider a 200*200 circle placed inside a 100*100 div. Prior to that, we need to ensure t ...

Placing a div in the corner of an image

Is there a way to position a meta-data div in the corner of every post image, even with different image sizes? For example: This is what I currently have in my loop: <div id="images"> <?php wp_get_attachment_image(); ?> </div> < ...

Obtaining JSON data in a separate JavaScript file using PHP

I have an HTML file with the following content: // target.html <html xmlns="http://www.w3.org/1999/xhtml"> ... <script src="../../Common/js/jquery-ui-1.10.3.js"></script> <script src="../../Common/js/select.js" type="text/javascript"& ...

Having trouble centering my menu bar on CSS, can anyone help?

I'm having trouble getting the buttons inside the menu bar to align properly. Does anyone have any suggestions on how to fix this? I'm not very experienced with coding, so any assistance would be greatly appreciated! .main-navigation { clear ...

Having trouble positioning a specific element at the top right of the header navbar in Laravel Bootstrap 5

Is there a way to create a top navbar with the project name and menu on the left, and user management on the right? Currently, both options are aligned to the left. Here is an example of what I have: top navbar This navbar is placed in the header, and her ...

Refresh Twitter Bootstrap Tooltip after deactivating/removing

I have a quick question. I am currently dealing with data that is constantly changing and displayed from a selected item in a table. To monitor for overflow, I have implemented the following code: if (event.target.offsetWidth < event.target.scrollW ...

Ensure that the bootstrap popover remains hidden when clicked outside of it, unless there is an element within the

Currently, I am facing an issue with a Bootstrap popover that contains a text input. My goal is to have the popover hide if the user clicks outside of it, and remain open if any elements inside the popover, like the input field, receive focus. Unfortunate ...

How you can incorporate an icon in between menu items using Bootstrap 4

As a novice web developer, I am currently utilizing Bootstrap 4 in my project. Here is the code snippet I have created: .footer-menu a{ color: #2D2D2D; font-size: 1em; } .copyright{ color: #D1D1D1; font-size: 0.9em; } <footer> ...

Clarity of visual in a lattice

I'm encountering a small issue with my ExtJS 4.2 MVC application that involves grid and image transparency. Below is a snippet of my grid setup: Ext.define('XProject.view.message.inbox.Grid', { extend: 'Ext.grid.Panel', al ...