首页 > 解决方案 > How do I make this Materialize table more responsive on mobile devices

问题描述

I have created a table that has Likert scale answer options with the Materialize framework and I am finding it difficult to make it reduce its size on mobile device screen width. It fits perfectly till it gets to below 466px width.

I want the table to fit on the card when they appear on mobile devices but it doesn't work. I tried to offset it, activate the scrollbar, and reduce the width of the table at the media width of 320px but it all did not work.

Here is a JSFiddle link to it.

CODE:

body {
  background-color : wheat;
}
<head>
    <!-- Compiled and minified CSS -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
    <!-- Compiled and minified JavaScript -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</head>
<body>
    <div class="container">
    <div class="card">
    <div class="card-content hoverable black-text">
    <ol start="10">
        <div class="row">
            <b>Behaviour</b><br />
            <div class="input-field col s12">
                <li>
                    <p>
                        To what extent do you agree with the following?
                        (1=strongly agree, 2=agree 3= Neutral, 4= disagree
                        5=strongly disagree)
                    </p>
                    <br />
                    <p class="mini">
                        <b>Various Moods</b>
                    </p>
                    <p class="mini">Mark only one oval per row.</p>
                    <table>
                        <thead>
                            <tr>
                                <th></th>
                                <th>1</th>
                                <th>2</th>
                                <th>3</th>
                                <th>4</th>
                                <th>5</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td style="padding-right:20px">
                                    I am calm
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Strongly agree" name="grps1" type="radio"/>
                                    <span></span></label>
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Agree" name="grps1" type="radio" />
                                    <span></span></label>
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Neutral" name="grps1" type="radio" />
                                    <span></span></label>
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Disagree" name="grps1" type="radio" />
                                    <span></span></label>
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Strongly disagree" name="grps1"type="radio" />
                                    <span></span></label>
                                </td>
                            </tr>
                            <tr>
                                <td style="padding-right:20px">
                                    I am impatient
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Strongly agree" name="grps2" type="radio"/>
                                    <span></span></label>
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Agree" name="grps2" type="radio"  />
                                    <span></span></label>
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Neutral" name="grps2" type="radio" />
                                    <span></span></label>
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Disagree" name="grps2" type="radio" />
                                    <span></span></label>
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Strongly disagree" name="grps2" type="radio"/>
                                    <span></span></label>
                                </td>
                            </tr>
                            <tr>
                                <td style="padding-right:20px">
                                    I don't feel
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Strongly agree" name="grps3" type="radio"/>
                                    <span></span></label>
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Agree" name="grps3" type="radio" />
                                    <span></span></label>
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Neutral" name="grps3" type="radio" />
                                    <span></span></label>
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Disagree" name="grps3" type="radio" />
                                    <span></span></label>
                                </td>
                                <td>
                                    <label><input class="with-gap" value="Strongly disagree" name="grps3" type="radio"/>
                                    <span></span></label>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </li>
            </div>
        </div>
    </ol>
    <div>
    </div>
</body>

标签: htmlcsshtml-tableresponsive-designmaterialize

解决方案


我能够通过使用 Materialize 网格方法来解决这个问题。这是它的JSFiddle链接。

```
body {
  background-color : wheat;
}
```
```
<head>
  <!-- Compiled and minified CSS -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

  <!-- Compiled and minified JavaScript -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>

</head>

<body>
  <div class="container">

    <div class="card">
      <div class="card-content hoverable black-text">
        <ol start="10">
          <div class="row">
            <b>Behaviour</b><br />
            <div class="input-field col s12">
              <li>
                <p>
                  To what extent do you agree with the following?
                  (1=strongly agree, 2=agree 3= Neutral, 4= disagree
                  5=strongly disagree)
                </p>
                <br />
                <p class="mini">
                  <b>Various Moods</b>
                </p>
                <p class="mini">Mark only one oval per row.</p>
                <div class="row">
                  <div class="col s5"></div>
                  <div class="col s1">1</div>
                  <div class="col s1">2</div>
                  <div class="col s1">3</div>
                  <div class="col s1">4</div>
                  <div class="col s1">5</div>
                </div>
                <div class="row">
                  <div class="col s5">I am calm</div>
                  <div class="col s1"><label><input class="with-gap" value="Strongly agree" name="grps1" type="radio" />
                      <span></span></label></div>
                  <div class="col s1"><label><input class="with-gap" value="Agree" name="grps1" type="radio" />
                      <span></span></label></div>
                  <div class="col s1"> <label><input class="with-gap" value="Neutral" name="grps1" type="radio" />
                      <span></span></label></div>
                  <div class="col s1"><label><input class="with-gap" value="Disagree" name="grps1" type="radio" />
                      <span></span></label></div>
                  <div class="col s1"><label><input class="with-gap" value="Strongly disagree" name="grps1" type="radio" />
                      <span></span></label></div>
                </div>

                <div class="row">
                  <div class="col s5"> I am impatient</div>
                  <div class="col s1"><label><input class="with-gap" value="Strongly agree" name="grps1" type="radio" />
                      <span></span></label></div>
                  <div class="col s1"><label><input class="with-gap" value="Agree" name="grps2" type="radio" />
                      <span></span></label></div>
                  <div class="col s1"> <label><input class="with-gap" value="Neutral" name="grps2" type="radio" />
                      <span></span></label></div>
                  <div class="col s1"><label><input class="with-gap" value="Disagree" name="grps2" type="radio" />
                      <span></span></label></div>
                  <div class="col s1"><label><input class="with-gap" value="Strongly disagree" name="grps2" type="radio" />
                      <span></span></label></div>
                </div>

                <div class="row">
                  <div class="col s5"> I don't feel</div>
                  <div class="col s1"><label><input class="with-gap" value="Strongly agree" name="grps3" type="radio" />
                      <span></span></label></div>
                  <div class="col s1"><label><input class="with-gap" value="Agree" name="grps3" type="radio" />
                      <span></span></label></div>
                  <div class="col s1"> <label><input class="with-gap" value="Neutral" name="grps3" type="radio" />
                      <span></span></label></div>
                  <div class="col s1"><label><input class="with-gap" value="Disagree" name="grps3" type="radio" />
                      <span></span></label></div>
                  <div class="col s1"><label><input class="with-gap" value="Strongly disagree" name="grps3" type="radio" />
                      <span></span></label></div>
                </div>

              </li>
            </div>
          </div>
        </ol>
        <div>
        </div>

        <body>


推荐阅读