Utilizing display: flex for creating table padding

Hey there! I'm currently working on a webpage layout that includes a logo and a table. To achieve this, I've used display flex for the wrapper element. However, I've noticed that when viewing the page on mobile devices, the padding of the table seems to disappear. Can anyone help me figure out how to fix this issue? Here is what my layout looks like normally: https://i.sstatic.net/PhJ4a.png And here is what I am aiming for: https://i.sstatic.net/8I8TO.png Unfortunately, this is what happens with the current code: https://i.sstatic.net/C5ESb.png

Here's a snippet of my code:

.wrapper
{
    min-height: 100%;
    overflow: hidden;
}

._container
{
    max-width: 1310px;
    margin: 0px auto;
    padding: 0px 45px;
    box-sizing: content-box;
}

.main_section{
    width: 100%;
    display: flex;
}

.table_text table{
    width: 100%;
    display: block;
}

.table_text tbody, 
.table_text th{
    width: 100%;
    display: block;
}

.table_text tbody{
    overflow-x: auto;
}

.table_text tbody tr{
    width: 100%;
    display: table-cell;
}

.table_text td{
    width: 100%;
    display: block;
}

.table__container {
    padding: 0px;
}

.yacheika td{
    padding: 34px 25px;
}
.yacheika th{
    padding: 34px 25px;
    text-align: left;
}

.title {
    text-align: center;
    padding-bottom: 40px;
}
    <div class="wrapper _container">
        <div class="main_section ">
            <div class="header__container ">
                <img src="logo.svg" alt="logo" class="header_img">
            </div>
            <div class="table__container">
                <div class="title">Table name</div>
                <div class="table_text">
                    <table>
                        <tr>
                            <th>header</th>
                            <th>header</th>
                            <th>header</th>
                            <th>header</th>
                            <th>header</th>
                        </tr>
                        <tr>
                            <td>Content</td>
                            <td>Content</td>
                            <td>Content</td>
                            <td>Content</td>
                            <td>Content</td>
                        </tr>
                        <tr>
                            <td>Content</td>
                            <td>Content</td>
                            <td>Content</td>
                            <td>Content</td>
                            <td>Content</td>
                        </tr>
                        <tr>
                            <td>Content</td>
                            <td>Content</td>
                            <td>Content</td>
                            <td>Content</td>
                            <td>Content</td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>

Answer №1

If you take a look at the layout inspector in your web developer tools, you'll notice that the min-width is set too high causing overflow in your browser window. To fix this issue, simply add min-width:0 to your .table__container rule.

https://i.sstatic.net/W59q8.jpg

.wrapper {
  min-height: 100%;
  overflow: hidden;
}

._container {
  max-width: 1310px;
  margin: 0px auto;
  padding: 0px 45px;
  box-sizing: content-box;
}

.main_section {
  width: 100%;
  display: flex;
}

.table_text table {
  width: 100%;
  display: block;
}

.table_text tbody,
.table_text th {
  width: 100%;
  display: block;
}

.table_text tbody {
  overflow-x: auto;
}

.table_text tbody tr {
  width: 100%;
  display: table-cell;
}

.table_text td {
  width: 100%;
  display: block;
}

.table__container {
  padding: 0px;
  min-width: 0; /* <--- Added this property */
}

.yacheika td {
  padding: 34px 25px;
}

.yacheika th {
  padding: 34px 25px;
  text-align: left;
}

.title {
  text-align: center;
  padding-bottom: 40px;
}
<div class="wrapper _container">
  <div class="main_section ">
    <div class="header__container ">
      <img src="https://www.fillmurray.com/200/200" alt="logo" class="header_img">
    </div>
    <div class="table__container">
      <div class="title">Table name</div>
      <div class="table_text">
        <table>
          <tr>
            <th>header</th>
            <th>header</th>
            <th>header</th>
            <th>header</th>
            <th>header</th>
          </tr>
          <tr>
            <td>Content</td>
            <td>Content</td>
            <td>Content</td>
            <td>Content</td>
            <td>Content</td>
          </tr>
          <tr>
            <td>Content</td>
            <td>Content</td>
            <td>Content</td>
            <td>Content</td>
            <td>Content</td>
          </tr>
          <tr>
            <td>Content</td>
            <td>Content</td>
            <td>Content</td>
            <td>Content</td>
            <td>Content</td>
          </tr>
        </table>
      </div>
    </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

Alignment issue with Bootstrap 4 form fields within inline form group

My experience with Bootstrap 4 on certain pages has been quite challenging, specifically when it comes to aligning fields with labels to the left and maintaining an aligned appearance for input fields. Here is the snippet of my code: <div class="wrap ...

When utilizing Blazor to create dynamic URLs within a loop, incorrect references may be generated

While working on a Blazor web assembly application, I encountered an issue when trying to loop over content to generate URLs for MP3 files. The media files are named "1.mp3", "2.mp3", "3.mp3", and so on. Imagine having a razor page with the following con ...

Utilize Boostrap to stylishly incorporate an image within a DIV using CSS

I have a project with numerous HTML pages all containing the same elements. To make updating easier, I decided to call all images from the CSS files so that if an image needs to be changed, I only need to update the CSS file rather than each individual HTM ...

The total sum of various divs containing a mix of numbers and letters

I have a group of div elements with the same class, each containing a value in the format (X1), (X2),... I need to add up these numeric values only, like 1 + 2 + .... Since these divs are generated dynamically, I won't know how many there will be. How ...

Is there a way to create a header that fades out or disappears when scrolling down and reappears when scrolling up?

After spending some time researching and following tutorials, I have not made much progress with my goal. The task at hand is to hide the top header of my website when the user scrolls down and then make it reappear when they scroll back up to the top of t ...

Implementing a JQuery script that triggers every time there is a change in the scroll

This script creates a shrinking effect on a box followed by a fade-in/out transition when the scroll position changes. However, the issue is that it triggers every time there is a scroll position change. For example, if the scroll position is at 100px and ...

Selecting multiple items in jQuery based on different attributes is a useful feature that

I am looking to choose multiple items based on their data attribute. Each item has a unique data-id. <div class="foo" data-id="1"></div> <div class="foo" data-id="2"></div> <div class=" ...

Execute HTML code within a text field

Is it possible to run html code with javascript inside a text box, similar to w3schools.com? I am working solely with html and javascript. Thank you. For example, I have two text areas - one for inserting html, clicking a button to run the code, and displ ...

Troubleshooting: Why isn't my jQuery Click Event functioning in Mozilla but working perfectly fine in

While I know this question has been asked before, I can't seem to locate the posts I remember reading about it. I apologize for any duplication, but I am trying to implement a "click anywhere BUT here to close element overlay" effect on my personal we ...

Creating an HTML table syntax from a PHP 2-dimensional array

I am looking for a way to extract data from a bi-dimensional array and display it in an HTML table format. Here is an example of the array: $grid = array( array(0,0,0,0),array(0,0,0,0),array(0,0,0,0),array(0,0,0,0),array(0,0,0,0)); $grid[0][0]=4;$grid[0][ ...

Using jQuery and Modernizr for CSS3 and Javascript transitions support in Internet Explorer

Looking for a way to add support for button hover effects in IE 7-9 on this Codepen.io project. Can anyone help? For example, I'm trying: transition-duration: 0.5s; transition-property: all; transition-timing-function: ease; margin-top: 5px; I atte ...

Arranging elements within a complex div structure

I have been working on styling this div that displays the products for an e-commerce website. I initially used CSS and a table within it, but it seems like using tables for content is not recommended, so I am trying to find a better solution. However, my a ...

Material-UI organizes its Grid Items vertically, creating a column layout rather than a horizontal row

I'm struggling to create a grid with 3 items in each row, but my current grid layout only displays one item per row. Each grid item also contains an image. How can I modify the code to achieve a grid with 3 items in a row? Here's the code snippet ...

Determine whether a WebElement contains a particular content within the :after pseudo class

After locating my element in Selenium, I've come across an interesting challenge. IWebElement icon = box.FindElement(By.ClassName("box-icon")); Sometimes, this element (icon) has a content set as follows: &:after { content: $icon-specia ...

What is causing the discrepancy in functionality between these two HTML/CSS files with identical code?

In this codepen, you'll find the first example: Subpar Pen: https://codepen.io/anon/pen/jGpxrp Additionally, here is the code for the second example: Excellent Pen: https://codepen.io/anon/pen/QqBmWK?editors=1100 I'm puzzled why the buttons l ...

Having trouble with the placement of my footer div - seeking a solution

I've been trying to center my footer, but it keeps aligning to the left. Here's a screenshot for reference Below is the code I'm working with (core.blade.php): <div class="footer"> <div class="row align-self-end& ...

Creating a dynamic dropdown menu using JQuery that does not automatically submit the form when a value is

Upon selecting a background color from the dropdown menu, I am generating a dynamic dropdown for text colors. The Text Color dropdown is populated correctly based on the selection of Background Color. Although the functionality works as intended, I encoun ...

Tips on showcasing the elements within a div container using flexbox

Seeking advice on positioning items/cards using flexbox in my initial react app. The issue lies with the div within my card component where applying display: flex; turns every card into a block (column-like) structure, flexing only the content within each ...

Using CSS Classes with PHP Variables in Conditionals: A Handy Guide

I have limited experience in programming and I'm attempting to edit a .php file within a Wordpress theme. Please keep this in mind as I explain my issue. Within the theme, there is code that calculates the average score from 1 to 10 and then displays ...

Retrieving the chosen option using a change event listener

Is there a way to retrieve the selected option using a change listener in TypeScript? I have come across JavaScript examples where the value is retrieved through event., but I am unable to locate any field that contains the selected option. <!DOCTYPE ...