What is the best way to utilize the bootstrap grid system for smaller screens while incorporating a table?

I have a PHP generated table that retrieves data and dynamically displays it in a table. It is crucial to ensure that the table data adjusts according to the screen size.

Below is the code snippet:

echo "<div class='container'><div class='row'><div class='col-sm-3'></div><div class='col-sm-6'><div class='table-responsive'><table border='0' class='table' >

<tr>
<td><img src='itempics/$i.jpg' width=200 height=200></td>
<td><h3>Product Details:</h3><b>Product:</b> ".$arr['pname']."<br>
<b>Item No:</b> ".$arr['itemno']."<br>
<b>Price:</b> ".$arr['price']."<br>
<b>Size:</b> ".$arr['size']."<br></td>

<td><h3>Buyer Details:</h3><b>Buyer:</b>  ".$arr['uname']."<br>
<b>Account No:</b> ".$arr['ac_no']."<br>
<b>Mobile No:</b> ".$arr['mob_no']."<br>
<b>Address:</b> ".$arr['add']."<br>
<b>Bank:</b> ".$arr['bank']."<br>
<b>City:</b> ".$arr['city']."<br>
<b>Order No:</b> ".$arr['order_no']."<br></td>
</tr>
</table>
</div>
</div>
<div class='col-sm-3'></div>
</div>
</div>

";

The .col-sm-3 class and other Bootstrap methods used within the td are not responsive enough for smaller screens, resulting in the Buyer Details section not displaying properly in the table. Responsive image classes also do not help in this case. The desired layout is to have the image on one row, Product details on the next row, and Buyer details on another row when the screen size is small. Is there a way to achieve this by using <div> tags instead of <td> tags?

Answer №1

Make sure to utilize col-xs-val for sizes under or equal to 768px in your html code, rather than using col-sm-val

Answer №2

Make sure to utilize the col-xs class as indicated and apply the "img-responsive" class for images, while for thumbnails, you can use the "img-thumbnail" class.

Update your code with this:

    <div class='container'>
    <div class='row'><div class='col-xs-3'></div><div class='col-xs-6'><div class='table-responsive'><table border='0' class='table' >

<tr>
<td><img class="img-responsive" src='itempics/$i.jpg'></td>
<td><h3>Product Details:</h3><b>Product:</b> ".$arr['pname']."<br>
<b>Item No:</b> ".$arr['itemno']."<br>
<b>Price:</b> ".$arr['price']."<br>
<b>Size:</b> ".$arr['size']."<br></td>

<td><h3>Buyer Details:</h3><b>Buyer:</b>  ".$arr['uname']."<br>
<b>Account No:</b> ".$arr['ac_no']."<br>
<b>Mobile No:</b> ".$arr['mob_no']."<br>
<b>Address:</b> ".$arr['add']."<br>
<b>Bank:</b> ".$arr['bank']."<br>
<b>City:</b> ".$arr['city']."<br>
<b>Order No:</b> ".$arr['order_no']."<br></td>
</tr>
</table>
</div>
</div>
<div class='col-xs-3'></div>
</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

Utilizing HTML documents instead of images in Owl Carousel 2

I am currently utilizing owl carousel 2 to construct a basic sliding carousel. However, I am only using images at the moment and would like to incorporate HTML files instead. These HTML files contain multiple divs where images can be inserted, and instead ...

How to add dimensions to a background image using CSS3

I would like the background image to have a size of 636px by 1140px instead of applying it to the div element directly. This is because I want to avoid scrollbars due to the height of the div. When I specify the width and height for the parent div, the ba ...

Organizing playing cards in a React JS application

As a beginner just starting out with React JS, I'm working on arranging cards in a medium size for my application. I came across a card design that I like and I'm seeking help to achieve something similar. Any assistance would be greatly apprecia ...

React Fixed Footer Implementation against My Preferences

Here's an issue that I'm facing: https://i.stack.imgur.com/gtQqm.png The footer on my webpage is normally displayed at the bottom of the page. However, when the user performs certain actions that extend the size of the page: https://i.stack.im ...

What is the best method for assigning real-life units, such as centimeters or millimeters, to a dimension

Is there a way to set the height of an img in millimeters, regardless of the device being used? Currently, setting the CSS rule height: 10mm; actually translates to height: 37.8px, as explained in this link: http://css-tricks.com/the-lengths-of-css/ If p ...

tips for efficiently using keyboard to navigate through tabs in an unordered list

Utilizing unordered lists in this web application. I am looking to implement tab navigation with keyboard functionality. How can I achieve this? The first tab should contain text boxes, and when the user fills out a text box and presses the tab key, they s ...

A guide on incorporating Bootstrap Toggle in your PHP project

I'm trying to style a checkbox to look like the ones on If I use this HTML input field: <input checked data-toggle="toggle" type="checkbox">, it resembles the desired design. However, I'm unsure of how to make it function as a real checkb ...

Why won't the div move when I click it?

Could you please explain why my JavaScript code isn't functioning as expected? The intended behavior is for the 'mark' div to move to the current mouse coordinates upon clicking within the map. ...

I am experiencing an issue where the close button image on tap is not closing on the first tap on

Why does the page close on the second tap instead of the first tap when using an iPhone? The image changes on tap but doesn't close as expected. $("#privacy-close-btn").mouseenter(function() { $("#privacy-close-btn").css("display", "none"); $(" ...

What are the steps to implementing PNG masking using PixiJS?

I am currently working on incorporating a png sprite as a mask for another layer. I found a demo on the pixi.js official website and created this fiddle: https://jsfiddle.net/raphadko/ukc1rwrc/ The code snippet below is what I am using for the masking fu ...

Searching for a comprehensive guide to web-related terminology that is widely accepted

Constantly immersing myself in studying the languages I am familiar with and exploring new development concepts and languages is a regular practice for me. When it comes to books, O'Reilly is my go-to choice, but when it comes to online resources, I&a ...

Loading content dynamically with AJAX and enabling smooth page scrolling

Looking for a solution to this issue. I have a button on my webpage that, when clicked, uses AJAX to load content into a "div" element below the button. Everything functions properly except for one problem - every time the button is pressed, the page scrol ...

Adjusting the CSS class name based on the screen size and applying styles to that class only during the "onload" event

The website I am currently developing can be found at . It is built on WordPress using the Avada theme and everything seems to be functioning correctly. The image move up effect on this site is achieved with the following JavaScript: window.onload = funct ...

Mobile view div failing to fill remaining space

When viewing my website on a mobile device, the heading in the div tag is not occupying the remaining space like it does on desktop. The heading is an h4 tag inside a div tag for mobile view. If you want to check out my website in inspect mode, here is the ...

Exploring ng-view navigation in AngularJS

I have come across an SEO issue while working on a static website in AngularJS. Google Webmasters Tools report no crawl errors, but when I attempt to fetch different routes, it consistently returns the same home page result. It seems to be ignoring what ...

dropdown menu items with jQuery toggle feature

Having an issue with a jQuery dropdown menu. Below is the code: $('.item-active, .item').click(function() { $(this).toggleClass('item-active'); if($('h3').hasClass('item-active')) { $(this).siblings ...

Angular JS: Grabbing Text from a Specific div and Copying it to Clipboard

I recently developed a Random Password Generator using Angular JS. Here is how the output appears in the application: <div data-ng-model="password" id="password"> <input class="form-control" data-ng-model="password" id="password" placeholder=" ...

What could be causing all of my Bootstrap accordion panels to close at once instead of just the one I selected?

When implementing Bootstrap accordions in my projects, I encountered an issue where closing one accordion would cause the others to also close when reopened. To address this problem, I utilized the collapse and show classes in Bootstrap to enable users to ...

Transferring data from ng-init to <script> in AngularJS

Take a look at this code snippet: <div ng-init="companyData"> <script type="text/javascript"> window.timeline = new TL.Timeline('timeline-embed', sampleJson); </script> </div> Is there a method to include company ...

Use .load() to set an image as background in the div

There is a block of code that is supposed to display images in a div with the class "img", but it isn't functioning correctly. Can you provide some guidance on how to fix this issue? <div class="other"><a href="/index1.html">Link1</a&g ...