Implementing the .container and .row responsive classes within a modal

Looking to achieve a layout similar to this within a bootstrap modal:

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

For larger devices, I want 3 columns with a size of 4, for medium devices 2 columns with a size of 6, and for smaller devices just 1 column. The pink area represents a small image.

I'm unsure of the best approach to implement this. Should I create multiple <ul> elements, such as using 3 separate uls each with 1/3 of the options and add .col classes to each <ul>, or is it better to use just one <ul> with .col classes on each list item?

Additionally, I would like to maintain equal spacing between list items both horizontally and vertically.

I currently have a structure set up here: https://jsfiddle.net/dehnxj77/. However, I am having trouble addressing the following issues:

  • The list items are not displaying with consistent horizontal and vertical spacing

  • The structure does not adjust responsively based on screen size like the desired image

  • I am using flex-basis:30% on the list item to ensure equal width, but I'm uncertain if this is necessary with responsive classes

Answer №1

li {margin-top:10px;}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <ul class="row" type="none">
    <li class="col-lg-4 col-md-6 col-sm-12">
      <img src="http://weknowyourdreams.com/images/pink-color/pink-color-05.jpg" class="img-responsive img-rounded" style="height:50px;width:50px;display:inline"/>
      <span>option1</span>
    </li>
    <li class="col-lg-4 col-md-6 col-sm-12">
      <img src="http://weknowyourdreams.com/images/pink-color/pink-color-05.jpg" class="img-responsive img-rounded" style="height:50px;width:50px;display:inline"/>
      <span>option1</span>
    </li>
    <li class="col-lg-4 col-md-6 col-sm-12">
      <img src="http://weknowyourdreams.com/images/pink-color/pink-color-05.jpg" class="img-responsive img-rounded" style="height:50px;width:50px;display:inline"/>
      <span>option1</span>
    </li>
    <li class="col-lg-4 col-md-6 col-sm-12">
      <img src="http://weknowyourdreams.com/images/pink-color/pink-color-05.jpg" class="img-responsive img-rounded" style="height:50px;width:50px;display:inline"/>
      <span>option1</span>
    </li>
    <li class="col-lg-4 col-md-6 col-sm-12">
      <img src="http://weknowyourdreams.com/images/pink-color/pink-color-05.jpg" class="img-responsive img-rounded" style="height:50px;width:50px;display:inline"/>
      <span>option1</span>
    </li>
   </ul>
</div>

Answer №2

One suggestion is to center your block using margin: 0 auto; and add justify-content: space-between to the elements within your flexbox.

Another tip is to take advantage of Bootstrap's grid system by using col-md, col-sm, and col-lg classes inside your modal for easier styling and layout adjustments.

Lastly, ensure all elements have a max-height set to achieve uniform height throughout, and make use of media queries when necessary for responsive design.

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

Is there a way to center-align a link?

I've been attempting to center align a link on my website. This is the code snippet I have so far: <div class="cont"> <div class="form sign-in"> <h2>Welcome back,</h2> <label> <span>Email</sp ...

Adding a background image to a box in MUI is a simple task that can enhance

I've been attempting to include a background image in the Box component of mui, but I can't seem to get it to work. Here is the code I've been using: const Main = () => { return ( <Box sx={{backgroundImage:'images/cove ...

The conclusion of jQuery's nested animation

Functioning, But Page Transitions Inconsistent What I Believe to be the Correct Approach, But Event Triggering Issue Currently, I am experimenting with page transitions and utilizing bind() to detect the end of the CSS event transition. When a class is ad ...

Having trouble getting the Bootstrap 4 Modal javascript trigger to function properly?

I am facing a challenge with displaying my modal after asking the user to authenticate. The modal content overrides server files, so I want the user to authenticate before viewing it. My idea is to have the user click on an editmodal button, which will th ...

Can Google Maps Directions be acquired through HTTP requests?

Can the Google Maps API be used solely through HTTP? For example, a format like Would it be possible to receive XML or JSON data containing directions using this method? ...

Is there a way to hide the borders between cells within these divs?

I am working on an application screen using Vue.js and facing an issue with the divisions between cells. I want to hide these divisions so that the lines of the items appear continuous. I attempted to modify the classes of the columns to "col-md" and "col ...

Oops! Looks like there was a hiccup in processing your query. Please review the MySQL manual for guidance on fixing the SQL syntax error

After being pressured to update to MySQL 5 and PHP 5 due to my service provider no longer supporting older versions, I encountered a problem with my MySQL search. The query was functioning properly on the server, but when included in the user's listin ...

What are some ways to enhance mobile browsing with CSS?

I'm facing a challenge with optimizing my webpage for different mobile resolutions in my beginner HTML/CSS course. Whenever I use a website resolution simulator to test, the layout doesn't look right on certain settings. Is there a method to aut ...

Angular 13: A guide on pulling data from an Excel spreadsheet

I have been encountering issues while trying to display data from a CSV file on a web platform using Angular 13. The errors I am facing are related to binding 'ngModel' and type mismatches in the code. errors Error: src/app/app.component.html:24 ...

Enhancing the appearance of text in an article by using hover effects, while ensuring the link is attached to the

As I work on the design of my website, I am faced with a challenge involving elements that have links attached to them. I want visitors to be able to click anywhere on the article and be directed to a specific page. The code snippet I currently have is as ...

Having trouble with the responsive design not functioning properly?

Having trouble with mobile view in my simple HTML Bootstrap code. Everything looks fine in desktop view but not in mobile. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> < ...

The align-self-center property in Twitter Bootstrap Flex does not properly center elements vertically

I recently started working with twitter bootstrap 4.4.1 and flex to create a unique layout for my project. My main goal is to have a navbar at the top and the content displayed in the middle of the screen, as shown in the image here: https://i.sstatic.net ...

In my HTML document, I have three identical Id's and I need to figure out how to target the third one using CSS. Can you help

I am working on an HTML document that contains multiple instances of ids and classes. Here is a snippet of the code: <!DOCTYPE html> <html> <body> <div id="Caption_G" class="editor-group"> editor-group<br /> ...

Activate form caching in HTML/PHP

Feeling a bit overwhelmed trying to solve what seems like a simple issue. I have a collection of reports on an internal network (not accessible from the outside) and each report includes a form with various HTML inputs that adjust the report data. The pr ...

Exploring the Layout Options of Twitter Bootstrap 3

Can someone help me achieve this specific layout design using Bootstrap 3? --------------------------------------------------------- | | | | | ...

Guide on presenting an image retrieved from a database with ajax

I am currently developing a straightforward mobile application that utilizes a database to store various types of content, including images. I have implemented ajax requests to retrieve this information and display it within the app. However, I am encounte ...

Can Javascript be used to identify the number of td elements in a table and specify column widths within the table tags?

Is there a way to automatically add the "col width" tag based on the number of td tags within a Table tag? For example, if there are 2 td's, then it should add 2 "col width", and if there are 3 then, 3 "col width", and so on. <!DOCTYPE html> &l ...

Unusual body padding found in the mobile design

When visiting on a mobile device and inspecting the elements in Google Chrome, try disabling the style rule overflow-x: hidden from the body element and then resizing the window. You may notice a white vertical stripe (padding) appearing on the right side ...

Steps for Converting Unicode Characters to HTML Encoding in C++

Can you assist me with converting unicode characters like the ones below in C++? Thére Àre sôme spëcial charâcters ïn thìs têxt عربى I need to convert them to HTML encoding as shown below: Th&eacute;re &Agrave;re s&ocirc;me sp&am ...