How can I arrange the "elements" within a bootstrap container?

Check out the code display here:

Here's what I aim for it to show

The alignment of the elements has been a real challenge for me. I just can't seem to get the "Gender:", "Gender RadioButton list", "Age:", "Age RadioButton list" to appear in 4 columns on a single row. Since there will be multiple survey questions, I need to design the layout using CSS.

Where or how can I learn to properly utilize the <Div class="col">? It feels like learning another language to me.

.form-container {
  /* Styles for form container */
}

.form-container .RadioArray {
  /* Styles for Radio Array */
}

.form-container .RadioBox {
  /* Styles for Radio Box */
}

.form-container .spread {
  /* Additional styles */
}

h4 {
  /* Heading styles */
}
<!DOCTYPE HTML>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://unique-bootstrap-css-link.css">
  <link rel="stylesheet" href="https://unique-bootstrap-icon-font.css">
  <link rel="stylesheet" href="PlayRoom.css" type="text/css">
  <title>PlayRoom</title>
</head>

<body>
  <h4>Optional</h4>
  <div class="form-container">
    <div class="RadioArray">
      <div class="row">
        <div class="col-sm-5">
          <!-- Gender section -->
        </div>
        <div class="col-sm-5">
          <!-- Age section -->
        </div>
      </div>
    </div>
  </div>
</body>

</html>

Answer №1

Consider trying out this method in your HTML code:

<div class="row">
<div class="col-md-2">
    Category:
</div>
<div class="col-md-4">
    "Category RadioButton list"
</div>
<div class="col-md-4">
    Type:
</div>
<div class="col-md-2">
   "Type RadioButton list" 
</div>

Explanation: The row is divided into 12 columns, with 2 columns allocated for the headings "category" and "type" as they require less space (col-md-2), while the lists need more space hence col-md-4 is used. By ensuring all columns add up to 12, the layout remains organized and neat.

Answer №2

Bootstrap utilizes a 12-column grid system. The containers can have margin based on whether you choose container or container-fluid. Rows are defined by row, and columns within a row can be specified using classes like col-6 to determine the size of each column. It's not necessary to use all 12 columns.

There were instances where classes lacked the equals sign, for example: class "someclass".

The customization provided may not match your exact preferences but it serves as a starting point in terms of colors and visual style.

If you find yourself adding excessive custom CSS, remember that Bootstrap offers predefined classes for padding (p-3) and borders (border), among others. Some additional customizations might be unnecessary and can potentially be removed.

When working with Bootstrap's grid system, reference the documentation at https://getbootstrap.com/docs/5.0/layout/grid/. For instance, consider using col instead of col-6 if you only require a smaller number of columns, preventing the need to change from col-6 to col-4 when adjusting column quantities.

.survey-block {
  border-radius: 1.25rem;
  border: 0.375rem solid;
}

.survey-group {
  border-radius: 1.25rem;
  background-color: #00ff00;
}

.form-container .RadioArray {
  border-style: groove;
  border-width: 0.125rem;
}

.h4 {
  font-weight: bold;
  font-size: 1.50rem;
  color: #CCCCCC;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="492b26262d3a3d3b2839097c677a677b">[email protected]</a>/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ff9d90908b8c8b8d9e8fd2969c90918cbfced1cad1cf">[email protected]</a>/font/bootstrap-icons.css">

<body>
  <div class="survey-block container text-center p-4 bg-info">
    <div class="h3">Optional</div>
    <div class="form-container container">
      <div class="row">
        <div class="col-6">
          <div class="row">
            <span class="h3 p-2 col-5 text-end">Gender:</span>
            <div class="col-7 RadioBox p-3 border border-dark survey-group">
              <div class="form-check">
                <input type="radio" class="form-check-input" id="gender1" name="cGender" value="No Answer" checked>
                <label class "form-check-label" for="gender1">Declined</label>
              </div>
              <div class="form-check">
                <input type="radio" class="form-check-input" id="gender2" name="cGender" value="Male">
                <label class="form-check-label" for="gender3">Male</label>
              </div>
              <div class="form-check">
                <input type="radio" class="form-check-input" id="gender3" name="cGender" value="Female">
                <label class="form-check-label" for="gender3">Female</label>
              </div>
              <div class="form-check">
                <input type="radio" class="form-check-input" id="gender4" name="cGender" value="Neutral">
                <label class="form-check-label" for="gender4">Neutral</label>
              </div>
            </div>
          </div>
        </div>
        <div class="col-6">
          <div class="row">
            <span class="col-5 h3  p-1 text-end">Age:</span>
            <div class="col-7 RadioBox p-3 border border-dark survey-group">
              <div class="form-check">
                <input type="radio" class="form-check-input" id="cAge1" name="cAgeGroup" value="No Answer" checked />
                <label class="form-check-label" for='cAge1'>Declined</label>
              </div>
              <div class="form-check">
                <input type="radio" class="form-check-input" id="cAge2" name="cAgeGroup" value="under 19" />
                <label class="form-check-label" for='cAge2'>under 19</label>
              </div>
              <div class="form-check">
                <input type="radio" class="form-check-input" id="cAge3" name="cAgeGroup" value="19-40" />
                <label class="form-check-label" for='cAge3'>19 to 40</label>
              </div>
              <div class="form-check">
                <input type="radio" class="form-check-input" id="cAge4" name="cAgeGroup" value="over 40" />
                <label class="form-check-label" for='cAge4'>Over 40</label>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>

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

Troubleshooting Flexbox: Content within a Flex Item is not displaying properly within a scrollable container

I recently embarked on converting one of my websites to flexbox and encountered an issue with vertical scrolling within a flex container. It appears that Firefox displays it correctly, while Chrome and Safari do not. You can check out the code here. . ...

Is there a way to showcase my information on flash cards using JavaScript?

Currently, I am developing a full stack application that utilizes JavaScript on both the front and back end. This application allows users to create their own flashcards set. Upon clicking "View Cards," the data is fetched and the question-answer pair is d ...

basic two-column design

Located at the end of this page, you will find two distinct columns. On the right side, there is a Twitter feed, while the left side showcases a YouTube video and a comments section. Below is the HTML and CSS code that was used to create these columns: .l ...

Is there a way to reverse the animation playback in Angular?

I am working on an animation that involves a box fading from its original color to yellow. However, I would like to achieve the opposite effect: when the page loads, I want the box to start off as yellow and then fade back to its original color. The challe ...

The Navbar is not displaying the React Bootstrap 4 CSS module as intended

Having some trouble changing the color of my navbar. Is there a step I might be missing? Here's the component I'm trying to render: import React from 'react'; import { Nav, Navbar } from 'react-bootstrap'; import styles from ...

Ensure that the width of the table rows (tr) matches the width of the table header

I'm currently working on implementing a sticky table header. The issue I'm facing is that the width of tableHeaderRow does not match the width of tableHeader. Steps taken for creating sticky header: Make an Ajax call to populate the table with ...

Using jQuery UI to style div elements with dynamic titles

Is it possible to style a standard div container using the same styling as jQuery dialogs? I am looking to create a div panel with text content but with the title bar styling similar to that of jQuery UI dialog boxes. Appreciate your assistance in advance ...

The amazingly efficient Chrome quick find feature, accessible by pressing the powerful combination of Ctrl + F, ingeniously

Currently using Google Chrome version 29.0.1547.62 m. I've employed the CSS attribute overflow set to hidden on the parent element, which renders some of my DIV elements hidden from view. Additionally, these concealed DIV elements are adjusted in pos ...

Using a CSS button to activate a JavaScript function: A step-by-step guide

My current project involves writing a script to change the color of text when a specific button is clicked. The idea is that clicking the "Change color1" button triggers the text color change using the following code snippet: <button onclick="myFunction ...

What is the best way to ensure that a React app is always displayed in full screen

I am facing an issue while developing an app with React and Material UI. I am trying to display the app in full-page mode, but unable to achieve it successfully. Currently, it appears like this: https://i.sstatic.net/Hg0CA.png Here is my code snippet from ...

Looking to recreate this style of table using HTML and CSS?

https://i.sstatic.net/nDrxq.png Trying to replicate the layout from this image for my blog, but struggling with the source code. Any suggestions on how to achieve a similar design without using divs within table rows? Looking for a cleaner solution. ...

Insufficient column height when using CSS flex-grow property

I am facing an issue with my 3 flex columns that have varying text lengths, resulting in uneven heights. I have tried using flex-grow: 1; to make them match in height, but it does not seem to be working as intended. Can someone please help me identify what ...

Adjust the CSS to set the size of the element's height to a percentage of the screen

I'm curious if there's a way to set the CSS with an x (unknown) percentage amount, like height: *%;. If it's not possible, how can I make it take the size of the rest of the screen? I experimented in http://jsfiddle.net/omarjuvera/xnau2wsL/ ...

"Exploring the versatility of Tailwind css: A guide to implementing multiple themes

I know how to customize dark and light themes in tailwind, but I'm curious about extending this functionality to include additional themes such as pink, blue, red, etc. Is there a way to achieve this with regular tailwind CSS? <p className="t ...

What is the best way to incorporate width adjustments in an image source for a responsive website?

Currently learning CSS and experimenting with it on an HTML page. For reference, I'm using this link. Encountering an issue with a responsive header image that adjusts size based on device (small on mobile, large on desktop). Is it possible to achiev ...

The utilization of bootstrap can lead to CSS interruptions

I am trying to create a navigation button that transforms from 3 horizontal lines to an X shape when clicked. var anchor = document.querySelectorAll('button'); [].forEach.call(anchor, function(anchor) { var open = false; an ...

What is the best way to prevent a sticky element from scrolling along with the

I am looking to prevent a sticky div from taking up space on the website. It currently sticks to the desired position as expected. https://i.sstatic.net/wG4SK.png HTML <div v-if="isToastActive" class="toast"> <span clas ...

What is the best way to stack div elements one after the other?

I am a complete beginner in HTML and I have a project for my web design class about a movie. http://jsfiddle.net/Lbo1ftu9/ <div id="footer"> <a href="D:/MOVIE REPORT/akira.htm" title="GO BACK?"><img src="D:/IMAGES/goback.gif"> My code ...

Struggling with CSS on your website and need some help?

Working on a website project with my own design, I ran into an issue regarding the positioning of the menu style. Describing this problem can be challenging, so let's start by looking at some images. What it should look like: https://i.sstatic.net/ ...

The jQuery function is not functioning correctly

Currently, I am in the process of setting up an accordion menu using jQuery and CSS3. Everything is working perfectly fine so far except that the menu always opens upon page load and the code to hide it is not functioning as intended. Here's the link ...