Ways to position 4 containers next to each other using CSS

I need help aligning 12 buttons in a specific layout: 4 buttons on the top and 3 on each side to total 12 buttons. Also, I want 2 additional buttons at the top left (Div/Mult) and top right (Add/Sub).

Below, you'll find the HTML and CSS documents. If you require the JS document, please feel free to request it. I have provided the desired layout but I'm unsure how to implement it.

Div/MultBtn Add/SubBtn

1 2 3 4 (extend all the way to the other side)

<!DOCTYPE html>
<html>

<head>
  <title>Math Fact Tune Up</title>

  <style>
    #buttonContainer {
      position: relative;
      top: 50%;
      transform: translateY(-50%);
    }
    button {
      display: block;
      margin: 0 auto;
      background-color: #262b2b;
      border-style: solid;
      color: white;
      font-family: Open Sans, sans-serif;
      border-radius: 5px;
    }
    .lvlButton {
      padding-bottom: .1em;
      padding-top: .1em;
    }
    body,
    html {
      height: 100%;
      overflow: scroll;
      overflow-x: hidden;
      background-color: #262b2b;
    }
    body {
      overflow: hidden;
    }
    #go {
      background-color: #00d10d
    }
  </style>
</head>

<body>


  <div id="buttonContainer">
    <div class="lvlButton" id="divMult">
      <button id="divMultBtn">
        Multiplication/Division
      </button>
    </div>
    <br>
    <div class="lvlButton" id="addSub">
      <button id="addSubBtn">
        Addition/Subtraction
      </button>
    </div>
    <br>
    <div class="lvlButton" id="lvl1">
      <button id="lvl1Btn">
        Level 1
      </button>
    </div>
    <br>
    <div class="lvlButton" id="lvl2">
      <button id="lvl2Btn">
        Level 2
      </button>
    </div>
    <br>
    <div class="lvlButton" id="lvl3">
      <button id="lvl3Btn">
        Level 3
      </button>
    </div>
    <br>
    <div class="lvlButton" id="lvl4">
      <button id="lvl4Btn">
        Level 4
      </button>
    </div>
    <br>
    <div class="lvlButton" id="lvl5">
      <button id="lvl5Btn">
        Level 5
      </button>
    </div>
    <br>
    <div class="lvlButton" id="lvl6">
      <button id="lvl6Btn">
        Level 6
      </button>
    </div>
    <br>
    <div class="lvlButton" id="lvl7">
      <button id="lvl7Btn">
        Level 7
      </button>
    </div>
    <br>
    <div class="lvlButton" id="lvl8">
      <button id="lvl8Btn">
        Level 8
      </button>
    </div>
    <br>
    <div class="lvlButton" id="lvl9">
      <button id="lvl9Btn">
        Level 9
      </button>
    </div>
    <br>
    <div class="lvlButton" id="lvl10">
      <button id="lvl10Btn">
        Level 10
      </button>
    </div>
    <br>
    <div class="lvlButton" id="lvl11">
      <button id="lvl11Btn">
        Level 11
      </button>
    </div>
    <br>
    <div class="lvlButton" id="lvl12">
      <button id="lvl12Btn">
        Level 12
      </button>
    </div>
    <div class="lvlButton" id="gocontainer">
      <button id="go">
        GO
      </button>
    </div>
  </div>


</body>

</html>

Picture of result

https://i.sstatic.net/eaKgp.png

Answer №1

To make something float, follow these steps:

  1. Set the position to relative
  2. Set the float to left

There is no need for the <br /> tag after each div. The code below should work just fine:

#buttonContainer {
      position: relative;
      top: 50%;
      transform: translateY(-50%);
    }
    button{
         display: block;
         margin: 0 auto;
         background-color: #262b2b;
         border-style: solid;
         color: white;
         font-family: Open Sans, sans-serif;
         border-radius: 5px;
    }

    .lvlButton{
         padding-bottom: .1em;
         padding-top:.1em;
         float: left;
    }

    body, html{
         height:100%;
         overflow: scroll;
         overflow-x: hidden;
         background-color: #262b2b;
    }
    body{
         overflow: hidden;
    }

    #go{
         background-color: #00d10d
    }
<div id="buttonContainer">
 <div class="lvlButton" id="divMult">
 <button id="divMultBtn">
    Multiplication/Division
   </button>
 </div>
<div class="lvlButton" id="addSub">
 <button id="addSubBtn">
   Addition/Subtraction
  </button>
 </div>
...
...
<div class="lvlButton" id="gocontainer">
 <button id ="go">
   GO
  </button>
 </div>
 </div>

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

When trying to click the button in Navbar.jsx, I encounter an error when attempting to invoke the setShowCart(true) function

I've encountered an issue while trying to call the setShowCart(true) function in Navbar.jsx. I'm unsure of how to fix this. import React from 'react' import Link from 'next/link'; import {AiOutlineShopping} from 'react-ic ...

Artboard: Easily navigate through pictures

As part of a school assignment, I wanted to create an interactive story where users can click through images using the UP and DOWN buttons. However, I am facing an issue with my If function overriding the previous function. I envision this project to be a ...

Changing the font family for Bootstrap Glyphicons on a button

I have recently started using Bootstraps Glyphicons and encountered an issue while trying to insert text inside a button with a glyphicon icon: <button type="button" class="btn btn-default pull-left" data-toggle="collapse" data-bind="attr:{'href&a ...

Is there a way to reset the dynamic flexslider when a click event occurs?

Seeking a way to refresh the flexslider on a click event. I have embedded the flexslider in a Bootstrap pop-up and need it to update when the user clicks. The issue arises when I try to refresh the slider as it fails to display properly, likely due to losi ...

Tips for avoiding anchor tag text from being split across two lines when resizing

One issue I am facing is with an anchor tag that displays the name of the logged-in person. The problem arises when resizing the browser window, causing the name to split across two lines. Is there a way to prevent this from happening? ...

Why is there a mismatch between CSS and Angular 6 selector components?

website.html <website-chat></website-chat> chat-page.html <h1>Greetings</h1> chat-script.ts import { Component, OnInit } from '@angular/core'; @Component({ selector: 'website-chat', templateUrl: '. ...

Tips for switching back and forth between two classes using jQuery?

I'm having some trouble with the toggleClass function. It doesn't seem to be working correctly for me. The image should toggle between displaying and hiding, but it only changes to hide, not back again. You can view my example here, along with t ...

Issue with ng-disabled not functioning properly for href tag within list item

Is there a way to prevent clicking on the <a> tag within a list item in a UI list so that the associated <div> is not displayed when clicked (excluding the last list item)? I have attempted using ng-disabled directly on the list item attribute ...

Creating a Full-Width Dropdown in Bootstrap 4 Navbar: A Step-by-Step Guide

I'm attempting to create a dropdown that spans the full width of the screen and has a collapsible feature like many modern websites. However, I am having difficulty figuring out how to achieve this. I experimented with using Bootstrap's collapse ...

Having trouble with centering my div in HTML and CSS

Coding Challenge .nav_bar { position: absolute; top: 0; width: 800px; height: 23px; display: inline-block; text-align: center; background-color: #0090bc; border-bottom-left-radius: 12px; border-bottom-right-radius: 12px; border: 2px solid #004D6F; -web ...

Learn how to alter the website's overall appearance by changing the background or text color with a simple click on a color using Angular

Is there a way to dynamically change the background color or text color of the entire website when a user clicks on a color from one component to another? I know I need to use the Output decorator, but how can I implement this? style.component.html <di ...

Moving up stacked columns with bootstrap or any other CSS technique

Is there a way to make column [3] move up if column [2] is taller than column [1]? [1][2] [3][4] Check out this bootply example of the layout : http://www.bootply.com/KbAf8UOk9c Currently, there is empty space between column [1] and [3] that I would li ...

How can I showcase the selected file using jQuery's querySelector?

I have successfully implemented a file upload feature using jQuery querySelector. Now, I am looking for a way to display the selected file name in a span element after the user selects the file. Here is my HTML code: <span id="filename"></span&g ...

In Internet Explorer, the toggle div expands to fill the available space, but this behavior is not consistent in

Utilizing the toggle function in jQuery, I created a mechanism to switch between 4 different blocks of content. You can view a demonstration of how the functionality operates correctly in Google Chrome here: If you encounter any issues with the functiona ...

Having trouble retrieving data from the fetch database. The login page seems to be stuck in a continuous loop and won't let me

Every time I attempt to log in through: webhost/adminlogin.php, I am redirected back to the same page. Did I forget to add something? Thank you for your assistance. Here is my script: This is what is included in my adminlogin.php file: <?php session ...

Unable to display the string following a space in the value attribute of an hbs file

<input type="text" class="form-control" id="exampleInputEmail2" name="productName" value={{product.productName}} > When I input 'Smart Phones' into product.produc ...

Troubles with HTML, CSS, and jQuery Double-Level Menu

After creating a simplified version of an HTML, CSS, jQuery navigation menu, I noticed that the submenu items were being considered part of the containing list item. This caused them to not function as intended when clicked because they were being treated ...

The alignment of links is not meeting the centering requirement

I'm facing a challenge with aligning my "buttons" on the pages, although they are essentially text links designed to resemble buttons using CSS. These buttons are utilized within an unordered list structure (refer to the HTML snippet below). The rele ...

Tips for creating responsive emails

Yesterday, I posted about my email newsletter and received some helpful feedback on creating a good structure. I implemented the suggestions provided into my newsletter and also added media query code to make layout adjustments for supported email clients. ...

Exploring how to set dropdown menu width for Angular2 mat-select options

Currently, I am using the angular2 mat-select control and facing an issue with the width and position of its dropdown list menu. By default, it is wider and overflows the element on both sides by a few pixels. I have not found any option for adjusting the ...