Creating a Responsive Table with HTML and CSS in Magento

I'm having trouble formatting a table on my Magento website using the HTML Code Element. Even with responsive media types, the table is still extending off the screen on mobile devices.

Check out my Magento Responsive Table for Mobile

    <style>
    .table {
        width: 100%;
        border-collapse: collapse;
    }
    tbody tr:nth-child(odd) {
        background-color: #f2f2f2;
    }
    .responsive-table {
        overflow-x: auto;
    }
</style>
<body>
    <table>
        <thead>
            <tr>
                <th>Variant</th>
                <th>ETA-approval</th>
                <th>Drill diameter</th>
                <th>Min. drill hole depth</th>
                <th>Effect. anchorage depth</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>FIS H 12 x 50 K</td>
                <td>Yes</td>
                <td>12 [mm]</td>
                <td>60 [mm]</td>
                <td>50 [mm]</td>
            </tr>
            <tr>
                <td>FIS H 12 x 85 K</td>
                <td>Yes</td>
                <td>12 [mm]</td>
                <td>95 [mm]</td>
                <td>85 [mm]</td>
            </tr>
            <tr>
                <td>FIS H 16 x 85 K</td>
                <td>Yes</td>
                <td>16 [mm]</td>
                <td>95 [mm]</td>
                <td>85 [mm]</td>
            </tr>            
        </tbody>
    </table>
</body>

Answer №1

You are not using the correct selector for the table. Instead, utilize the element selector and eliminate the use of the period ".".

Answer №2

Give this a shot.

    .table {
        width: 100%;
        border-collapse: collapse;
    }
    tbody tr:nth-child(odd) {
        background-color: #f2f2f2;
    }
    .responsive-table {
        overflow-x: auto;
    }
<div class="responsive-table">
    <table class="table">
        <thead>
            <tr>
                <th>Type</th>
                <th>Approval ETA</th>
                <th>Drill Bit Size</th>
                <th>Minimum Drill Hole Depth</th>
                <th>Effective Anchorage Depth</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>FIS H 12 x 50 K</td>
                <td>Yes</td>
                <td>12 [mm]</td>
                <td>60 [mm]</td>
                <td>50 [mm]</td>
            </tr>
            <tr>
                <td>FIS H 12 x 85 K</td>
                <td>Yes</td>
                <td>12 [mm]</td>
                <td>95 [mm]</td>
                <td>85 [mm]</td>
            </tr>
            <tr>
                <td>FIS H 16 x 85 K</td>
                <td>Yes</td>
                <td>16 [mm]</td>
                <td>95 [mm]</td>
                <td>85 [mm]</td>
            </tr>            
        </tbody>
    </table>
</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

What is the best way to save pictures in an array and use a for loop to display them? PHP

Whenever I attempt to print images using a for loop, the images fail to load. <?php $images = array('1.png', '2.jpg', '3.png', '4.jpg','IMG_0105.JPG'); ?> <div class="container"> <d ...

Changing the default date display in Vue.js

Is there a way to automatically set today's date as the default date on the datepicker? Here is the code snippet: <template lang="html"> <input type="date" v-model="date"> </template> <script lang="js"> export default { nam ...

PHP unable to display echo containing line breaks and text in nested lists

Currently, I am tackling an issue with a multi-select list in my PHP pages. The problem arises when I select text and it appears in the wrong order due to the lack of wrap or text break on each item. Below is the PHP code I have written: <select id="SK ...

Having issues with vertical space distribution in flexbox column layout

Is there a way to align vertical content with space-between without specifying the height? I want to justify-content-between the red and black divs in the third column without setting a height value. Can this be achieved considering we already have a max-h ...

Using Jquery to add new HTML content and assign an ID to a variable

Here is some javascript code that I am having trouble with: var newAmount = parseInt(amount) var price = data[0]['Product']['pris']; var id = data[0]['Product']['id']; var dat ...

Adjustable Size with jQuery UI - Resizing Multiple Divs Causes Movement of Adjacent Divs

I've been experimenting with a webpage that consists of a div element containing multiple nested divs and jQuery UI resizable functionality. Essentially, it's a dashboard comprised of individual widgets. My goal is to resize each widget independe ...

Calculate the number of input boxes that have been filled

<input type="number" name="day1"> <input type="number" name="day2"> <input type="number" name="day3> Can anyone help me figure out how to count the number of filled fields in this form? For example, if only day1 is filled, the count resu ...

Retrieve base64 encoded data from several content attributes

Is there a way to optimize the use of base64 data in CSS by defining it once and referencing it in multiple content properties? div#my_id1 { content: url(data:image/png;base64,...); } div#my_id2 { content: url(data:image/png;base64,...); } Using ...

Swapping React components within a list: How to easily change classes

For my latest project, I am building a straightforward ecommerce website. One of the key features on the product page is the ability for users to select different attributes such as sizes and colors. These options are represented by clickable divs that pul ...

How to resolve the issue of a visible line between a clipped div and its parent div

When I zoom in, a faint, transparent line appears between the triangular div and its parent div. It seems like this issue is caused by anti-aliasing in the browser. Any suggestions on how I can fix this would be greatly appreciated. I've already attem ...

What is the best way to incorporate a background image while using floated divs?

Is there a way to align divs next to each other without them overlapping when the container-div has a background? I've tried using "float: left" but encountered issues with the inner divs being positioned outside the container-div once a background co ...

What is the best way to style these CSS elements within the stylesheet?

I'm currently working on customizing a navigation menu in DotNetNuke. Although my question primarily relates to CSS syntax. Can someone please provide guidance on how to style a class that resembles the following? <tr class="mi mi0-0 id58 first"& ...

Adjusting the size of all elements on a webpage

Upon completing my project, I noticed that my localhost:3000 is zoomed in at 125%, causing it to appear less than ideal at 100% zoom. Is there a way to adjust the zoom/scale of my website to match how it appeared on my localhost environment? I came across ...

Is it possible to identify when a key is pressed on any part of an HTML webpage?

I am currently seeking a solution to detect when a key is pressed on any part of an HTML page, and then showcase a popup displaying the specific key that was pressed. While I have come across examples of achieving this within a textfield, my goal is to m ...

Function activation in Element requires a double click to initiate

I've encountered an issue with a web element I'm working on where the click function only triggers after the first click, rendering the initial click ineffective. Here's the code snippet in question: HTML: <div> <a href="#0" cla ...

The process of converting RaphaelJS patterns into an SVG format

I am currently creating an interactive map using AngularJS and RaphaelJS. The entire SVG object is generated within a directive, and my goal is to assign different colors to each area on the map. Specifically, I want some regions to have a striped patter ...

Is there a way to trigger a fabric.js event externally?

Is there a way to trigger a fabric.js event externally? For example, if I have a 3D model that tracks the mouse's position and provides the UV coordinates on the canvas, I want to be able to emit click, mousemove, and mouseup events. Currently, everyt ...

What is the best way to send an authorized request to a Django view from an external HTML page using AJAX

In django version 1.10, I have created register.html, login.html, and home.html pages for my application. These HTML pages are hosted on separate application servers. Utilizing a Custom User Model, I am able to successfully register users and store their ...

Ways to emphasize a navigation menu item that points to the same URL

One issue I am facing is with my navigation menu, where two items are pointing to the same URL. <div id="LEFTmenu"> <ul> <li><a href="app/link1">Page1</a></li> <li><a href="app/link2">Page2</a&g ...

The alignment of the icon to the center of a div is disrupted when using bootstrap.css

Take a look at this code To center the icon within a div, I am using the following code: <div class="webview-back icon" style="width: 34px; height: 34px; display: inline-block; text-align: center; background-color: lightgray;"><i class= ...