I'm attempting to create 16 squares using bootstrap, but for some reason, it's not functioning properly and I'm unsure of

I'm struggling to create 16 squares on my website using Bootstrap, but it's not working as expected. I tried using "col-xs-3" for the width, but it's not setting correctly. Can someone please assist?

PS (I know I could customize the width in CSS, but ideally, I shouldn't have to)

<!DOCTYPE html>
<html>
<head>
  <link rel="icon" href="favicon.png" type="image/x-icon">
  <link rel="stylesheet" href="resources/css/reset.css">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  <link rel="stylesheet" href="resources/css/style.css">
  <title>Match Game</title>
</head>
<body>
  <div class="container">
    <div class="row">
      <div class="gameInstructions col-sm-12 col-md-3">
        <h1>Match Game</h1>
        <h2>Rules</h2>
        <p>Click on a card to reveal the number on the other side. Click on a second card to try and find a match to the first. If you succeed, the pair will be removed from play. If not, try again!</p>
        <h2>How To Win</h2>
        <p>You win when all pairs have been found.</p>
      </div>
      <div id="game"class="col-sm-12 col-md-9">
        <div class="row">
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
          <div class="col-xs-3 card"></div>
        </div>
      </div>
    </div>
  </div>
  <script
    src="https://code.jquery.com/jquery-3.1.1.min.js"
    integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
    crossorigin="anonymous"></script>
  <script type="text/javascript" src="./resources/js/match-game.js"></script>
  <script type="text/javascript" src="./resources/js/tests.js"></script>
</body>
</html>
/*"Work Sans" Font*/
@font-face {
  font-family: 'Work Sans';
  font-style: normal;
  font-weight: 400;
  src: local('Work Sans'), local('WorkSans-Regular'), url(https://fonts.gstatic.com/s/worksans/v5/QGYsz_wNahGAdqQ43Rh_fKDp.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

...

The desired outcome should be 16 squares each with 25% width and a height of 12.5rem.

Answer №1

The reason the columns aren't displaying is because you haven't added any text to your column. Try adding some text and the columns should appear. Take a look at this example I created in a jsfiddle.

Answer №2

In order to achieve the desired output of 16 boxes, adjust the width attribute in your card class.

.card{
    height: 12.5rem;
    width: 30px; /* Adjust this value to get 16 boxes */
    background-color: rgb(153, 153, 153);
    border: 1px solid black;
    border-radius: 8px;
}

Answer №3

To ensure that your sixteen boxes have the same width within a row, you can use the following CSS code:

.card{
  width: calc(100% / 16)
  height: 12.5rem;
  background-color: rgb(153, 153, 153);
  border: 4px solid #fff;
  border-radius: 8px;
}

Answer №4

The -xs- infix is not part of the Bootstrap 4 framework anymore

This layout consists of 16 card boxes that adjust to all screen sizes...

<div class="row">
  <div class="col-3"><div class="card">1</div></div>
  <div class="col-3"><div class="card">.. </div></div>
  <div class="col-3"><div class="card">.. </div></div>
  ...
  <div class="col-3"><div class="card">16 </div></div>
</div>

View this design on Codeply

Related: Bootstrap columns stacking vertically on mobile devices

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

Guide to executing a batch file using electron

I've been struggling all morning to find a solution. I've gone through several tutorials, but I still can't wrap my head around how this should work. In my Electron app, there is a button that, when clicked, should execute a batch file (hpm ...

The CSS effect fails to take effect following an AJAX response

After a successful ajax response, I am attempting to apply a jQuery .css effect. However, it seems that this process is not working as expected because I am trying to retrieve the height of a newly created element and then applying it to another newly crea ...

Expand the background of columns to cover grid gutters

Imagine this... You're working on a layout with three columns, all within a fixed-sized container that is centered using margin:0 auto. The design requires the first column to have a background color that reaches the left edge of the browser window. ...

Issue with html2canvas image download in Firefox

I am currently using HTML2Canvas to try and download a div as an image. It works perfectly fine on Google Chrome, but I am experiencing issues with Firefox. Below is the code snippet: <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0. ...

Utilizing Media Queries with Dynamic Vue Properties

On one of my website pages, I always have a Div element with a Background Image that changes based on Media Queries (for example, I fetch a smaller resolution from my CDN on mobile phones). However, since I retrieve the Image URL on Page Load, I need to s ...

Trouble concealing information in Gmail and Outlook, issue persists

I need to create an email with two different links, one to be visible only in Gmail and the other only in Outlook. I discovered that I should use mso-hide for Outlook and display none for Gmail, but neither seem to be working as expected. When I use displa ...

Create a rectangular container with text using CSS

Looking to achieve a square box design using CSS with specific dimensions? Want to insert text inside the square and ensure it is horizontally centered within the square? Check out this code snippet: #myid { width: 100px; height: 100px; ...

CSS Duo-Toned Background

I've been searching everywhere for a solution to this issue. I have a design that I'm attempting to code using divs and CSS. The top half of the image features a gradient that transitions from left to right with different colors. My struggle lies ...

Ways to organize divs in a layout resembling a partial table

While working on my e-commerce platform with vue.js, I noticed that my product listings are not aligning properly, as displayed in the image linked below. https://i.sstatic.net/2FwaA.png My goal is to achieve the desired layout illustrated in the image b ...

Looking to subtly transition from the current webpage to the next one with a fading effect?

I'm looking to create a smooth transition between web pages on my site by slowly fading out the current page and fading in the next one when a link is clicked. $(document).ready(function() { $('body').css("display","none"); $(&a ...

Utilizing a jQuery variable within an .html() method

Can a Jquery if statement be used to display different content inside a div based on a variable? For example, if the variable is set to "cats", the displayed content might say "I like cats", and if it changes to "dogs", it would read "I like dogs". Is this ...

Validate the presence of an element on a page using selenium

I attempted to use the following code: if driver.find_element_by_xpath("/html/body/div[2]/div[3]/div[1]/div[1]/button"): pass believing it would be successful, however it did not work and instead resulted in: selenium.common. ...

Creating a dynamic and modern website header using Bootstrap 4.0, featuring a responsive design with an eye-catching image

Currently, I am in the process of constructing a dynamic webpage using Bootstrap 4. This page includes a header section with the client's logo, their name, and a responsive navbar. The challenge lies in making these elements adapt to various screen si ...

Accessing the API to retrieve an image when the 'a' tag is clicked

Currently, I am accessing the API to retrieve an image of a specific cat breed. When the API is called for the image, you receive a JSON object with the following URL: URL: "" I aim to display this image upon clicking on that specific breed. However, I a ...

Using Jquery slideToggle is creating additional spacing between inline-block divs

I am struggling with displaying a list of cities in an inline format. <div class="accordion-container"> <a href="#" class="accordion-toggle">London</a> <div class="accordion-content"> <p>Inform ...

How can I automatically switch to the time view in Tempus Dominus Bootstrap 4 datetimepicker after choosing a date?

Is there a way to automatically switch to the time view after selecting a date in Tempus Dominus Bootstrap 4 datetimepicker? Here's the snippet of code I'm working with: $("#datetimepicker1").on("change.datetimepicker", function (e) { // Need ...

Ways to customize hover color of Bootstrap 5 Dropdown menu

I'm having trouble modifying the hover color for a dropdown menu using Bootstrap 5. I'm unsure of the correct method to achieve this. The desired outcome is as follows: However, at the moment it appears like this: Apologies for the oversight, h ...

Could you explain the meaning of the :host /deep/ selector?

Can you provide a simple explanation of what the :host /deep/ selector does? :host /deep/ .ui-autocomplete { width: 85%; } ...

Vanishing metamorphoses

I'm encountering a strange issue with phantomJS where it seems to be losing the transformations applied to certain images. On my webpage, I have a function that takes some HTML and inserts it into the page. Here's an example of how it looks: fun ...

Is tabIndex being used as a css property?

I'm trying to understand how to utilize the HTML attribute tabindex using CSS. Specifically, I want to assign tabIndex=0 to all div elements that have the className='my-checkbox'. This is my current approach: <div tabIndex="0" classNam ...