Tips on displaying two columns as a single column on mobile devices

Bootstrap 3 table is described as:

<style>
/* Overriding Bootstrap style to ensure description text wraps into multiple rows on mobile */
.details-propertyvalue {
    white-space:normal !important;
}
</style>

<table class="table table-hover table-condensed table-striped">
                <tbody><tr>
                    <td>
                        Product information
                    </td>
                    <td class="details-propertyvalue">

sdofsdk sdklöfsdklö sdfklösdflök sdfkösdlökdsö sdfösdkf sdfkösdkf sdöfksdfö sdfksdölf sdfsdlfökö sdfösdlkf sdöfksdöflk sdfösdköfk söfsdköfskdf sdfksdö ... more similar tr elements

On a desktop screen, the table displays properly in two columns. However, on a mobile device, it also appears in two columns but the description column is very narrow.

Is there a way to make it appear in a single column on mobile: with the first row for the title and the second row for the description so that the column takes up the entire width of the screen in portrait orientation?

This table uses Bootstrap 3 and jquery-ui in an ASP.NET MVC4 shopping cart.

Answer №1

I faced a similar issue before, and my solution involved reworking the HTML structure. Instead of relying on tables, I opted for using DIVs that mimic table behavior:

HTML

<div class="table table-hover table-condensed table-striped">
  <div class="table-row">
    <div class="table-cell">
      Product information
    </div>
    <div class="table-cell">
      Unrefined Demerara sugar is an ideal complement to coffee. Its rich aroma and crunchy texture add exceptional flavor to cookies and cakes. You can sprinkle it on oatmeal or fruits. Unrefined Demerara sugar is minimally processed, preserving the natural molasses found in sugarcane.
    </div>
  </div>
</div>

CSS

.table {
  display: table;
}

.table-row {
    display: table-row;
}

.table-cell {
  display: table-cell;
}

For mobile optimization, simply change them to display: block:

@media screen and (max-width: 600px) {
  .table, .table-row, .table-cell {
    display: block;
  }
}

This will stack the elements vertically on mobile screens.

An example illustrating this can be found in this JSFiddle link.

Hope this solution proves helpful! :)

Answer №2

After considering new information:
Based on your preference for changing markup and the requirement of having a table with two columns resembling your example, I suggest utilizing horizontal description lists instead: http://getbootstrap.com/css/#horizontal-description

<dl class="dl-horizontal">
    <dt>...</dt>
    <dd>...</dd>
</dl>

Initially Suggested Solution: Achieving this without custom styles or a significant overhaul of your HTML structure is not feasible.

However, implementing custom CSS can simplify the process. Ensure that your CSS is loaded after Bootstrap for proper functionality.

View a demo on jsfiddle

The key steps taken include:

  1. Including a new class table-responsive to specify the desired behavior only on selected tables.
  2. Applying additional styles (within a media query) to alter the display of table cells accordingly:

Adjusted HTML code:

<table class="table table-hover table-condensed table-striped table-responsive">
    <!-- Your table data goes here -->
</table>

Additional CSS overrides:

/* Adjust the width in the media query below as needed */
@media only screen and (max-width: 768px) {
  table.table-responsive tr {
    display: block;
  }

  table.table-responsive tr td {
    display: block;
  }
}

Answer №3

Your response was:

I prefer to stick with Bootstrap 3 without adding any additional custom styles if possible

Although I share my answer here, it may be helpful for someone else:

To make your table responsive, assign a class name such as 'responsive'

table.responsive{
  width: 100%;
   }
table.responsive tr { 
   display: flex;
   display: -webkit-flex;
   flex-wrap: wrap;
   -webkit-flex-wrap: wrap;
   width:100%;
}
table.responsive td {
   width: 50%; //Adjust based on your needs

   }
 @media screen and (max-width:480px) {
   table.responsive td{
      width:100%;
     }
 }

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

Show information from the console logger

I'm currently working on displaying data from a database in an HTML page. While the data is showing up in my console, I'm struggling to figure out how to present it in an HTML table format. I'm unsure about the specific function that needs t ...

Ways to distinguish between two div elements that have scroll bars and those that do not

I created a div with CSS styling. .comment-list { margin: 20px 0; max-height: 100px; min-height: 100px; overflow-y: scroll; width: 100%; background-color:#000; } Here is the HTML code for the div: <div class="comment-list"> </div> When the ...

Incorporating text box input into a data table

When I click the "add game" button, I want the value of the input named "game-name" to appear in the "Name of the game" column of a table. Additionally, I am experiencing issues with the delete button functionality. Below is the code snippet I am working ...

Incorporating image uploading into an already existing user form using the Cropper Jquery Plugin

I have a standard web form where users input their name, telephone number, job title, etc. Upon submission, the data is saved to a database and their profile for future updates. Now, I want to add functionality for users to upload a picture as their avata ...

I am puzzled by the presence of the 'x' value in the JSON object when creating a column chart using CanvasJS. Its origin remains unknown to me

I'm exploring the use of canvasjs and I have a test code snippet that I'm working with: 9 $con = pg_connect("host=localhost port=5432 dbname=testdb user=postgres") or die ("Could not connect to server\n"); 10 $query ="SELECT id as label, ...

Invoke the loaded function using ajax

I am populating my div with data from an HTML file using the following code: $('#result').load('ajax/test.html'); Within test.html, there is a function called alertme. Is there a way to execute this function after the HTML is loaded i ...

Finding the Row Number of an HTML Table by Clicking on the Table - Utilizing JQuery

Seeking assistance to tackle this issue. I currently have an HTML table with a clickable event that triggers a dialog box. My goal is to also retrieve the index of the row that was clicked, but the current output is not what I anticipated. //script for the ...

Using the width property to style a div element

There are two div elements in my HTML, each with a specified width. However, I want both divs to take up the full space as designated in the width property, regardless of the content inside them. Currently, the divs adjust their size based on the content a ...

What are some methods for utilizing jQuery or Javascript to dynamically modify CSS styles depending on the current URL?

I'm working on integrating a separate navigation area file with my content using PHP includes. I have this idea where I want the links in the navigation area to change color depending on the active page (current URL). Essentially, I need jQuery or Jav ...

What are some troubleshooting steps for adjusting the position of this carousel control?

I have developed an HTML page to experiment with the Bootstrap 5 carousel. This carousel displays multiple items and features previous and next controls positioned outside of the slide images. The controls utilize the glyphicon-chevron-left and glyphicon-c ...

IE is notorious for not playing well with CSS

I am facing an issue with my Google search box code. It works perfectly on Firefox, Chrome, and other browsers except for Internet Explorer. Can anyone help me troubleshoot this? Below is the code snippet: Abulkas Tablet #outerContainer{ width: ...

Display options through numerical selection

I have been attempting to construct something, but I'm encountering difficulties. My goal is to create a functionality where entering a number in an input field will generate that many additional input fields. I've attempted to implement this us ...

Issues with Bootstrap Modal Checkbox Functionality

Issue with Bootstrap modal checkbox functionality when the checkbox is selected The desired behavior is for the bootstrap modal popup to be triggered upon clicking the checkbox Bootstrap Version: 3.3.6 Jquery Version: 2.1.3 $(function() { $(&ap ...

Creating a custom named page using PHP and MySQL

Currently, I am in the process of learning how to create my own database with the help of tutorials and resources like Stack Overflow. I have successfully created a register page where users can enter their username and password to access the upload page. ...

Guide to integrating jssor into an AngularJS application

Struggling to integrate jssor with angularjs, it seems to be failing because jssor is being initialized before angularjs, causing the ng-repeat elements to not resolve correctly. <div id="slider1_container"> <div u="slides"> <!-- Th ...

Looking for and changing the background of a div element using jQuery's .find

Suppose I have a pair of div elements. How can I utilize the .find method to access the background image of div1, then transfer that background image to div2 while substituting ".jpg" with "_highlighted.jpg"? var div2bg = $('.div1').find(' ...

Counting down with Jquery when times run out

Seeking assistance with implementing a jquery countdown timer on a webpage. The countdown I am utilizing is available at . My requirement is for the countdown to transition to another date once the current countdown expires. For instance, it should countdo ...

Generating a collection of model objects using Javascript

I want to generate a JavaScript list of my model. I am currently working on an ASP.NET MVC app The model 'testModel' looks like this: public string prop1{ get; set; } public string prop2{ get; set; } public string prop3{ get; set; } ...

Ways to retrieve the file name and additional attributes from a hidden input type

Is it possible to access the file name and other attributes of a hidden file when submitting it using the <input type="hidden"> tag? My current project involves drag and drop file functionality on a server using Node.js. If I am able to dynamically ...

Having trouble concealing images in HTML Emails on Outlook 2013

Struggling to properly hide images in Outlook 2013? Even when hidden, they are leaving a line of spacing that stretches the email. Here's the code I'm using to hide an image from the desktop version: <tr style="display: none; line-height: 0; ...