javascript - CSS 网格和媒体查询的问题

标签 javascript html css

<分区>


这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助 future 的读者。

关闭 4 年前

我的媒体查询目前似乎无法按预期使用 CSS 网格,并且无法找出原因。我正在构建一种移动优先的方式,所以我的第一个容器是单列。在大约 850 像素处,我想转到包含两个元素的 5 列 View ,但媒体查询未按预期工作。

index.html

<div class='container'>

    <div class='testbox'><h1>Test Box Walk Dog Hit Gym and Lift Bro Hit Gym and Lift Bro  Hit Gym and Lift Bro Hit Gym and Lift Bro Walk Dog Hit Gym and Lift Bro Hit Gym and Lift Bro  Hit Gym and Lift Bro Hit Gym and Lift Bro Walk Dog Hit Gym and Lift Bro Hit Gym and Lift Bro  Hit Gym and Lift Bro Hit Gym and Lift Bro</h1></div>




    <div id='main-grid'>

        <div class="container2">
            <h5 id='appHeader'>To-Do-List</h5>
            <div id='displayHideButton' >  <a href='#' id='addItemSymbol' onclick='hideInputAndChangeSymbol()' ><i id='symbol'  class="fas fa-minus-circle"  type='submit' ></i></a></div>
            <a href='#' id='addItem' ></a>
        </div>

        <ul id='list-body'>
            <li id='enterItem'><input type='text' placeholder="Enter List Item..."  id='newNote' class='inputEnterItem'></li>
            <li><span>Walk Dog Hit Gym and Lift Bro Hit Gym and Lift Bro  Hit Gym and Lift Bro Hit Gym and Lift Bro</span></li>
            <li><span>Hit Gym and Lift Bro</span></li> 
            <li><span>Stretch</span></li>
        </ul>
    </div>


</div>

index.css容器代码

.container{
display:grid;
grid-gap: 1.2em;
grid-template-columns: auto;
grid-template-rows: auto;
grid-template-areas: 
'option-panel' 
'todo-list';
margin: 2em;

}

@media only screen and (min-width:  850px) {
.container{
display:grid;
grid-gap: 1.2em;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
grid-template-rows: auto;
grid-template-areas: 'option-panel option-panel option-panel todo-list todo-list'
margin: 2em;

    }
}
.testbox{
    border:     1px solid red;
    background-color:   blue;
    grid-area: option-panel;
}
#main-grid{
 grid-area: todo-list;
 max-width:     30em;
 margin:    auto;
}

最佳答案

您只是在媒体查询中的网格模板区域后忘记了一个分号。

.container {
  display: grid;
  grid-gap: 1.2em;
  grid-template-columns: auto;
  grid-template-rows: auto;
  grid-template-areas: 'option-panel' 'todo-list';
  margin: 2em;
}

@media only screen and (min-width : 850px) {
  .container {
    display: grid;
    grid-gap: 1.2em;
    grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
    grid-template-rows: auto;
    grid-template-areas: 'option-panel option-panel option-panel todo-list todo-list';
    margin: 2em;
  }
}

.testbox {
  border: 1px solid red;
  background-color: blue;
  grid-area: option-panel;
}

#main-grid {
  grid-area: todo-list;
  max-width: 30em;
  margin: auto;
}
<div class='container'>
  <div class='testbox'>
    <h1>Test Box Walk Dog Hit Gym and Lift Bro Hit Gym and Lift Bro Hit Gym and Lift Bro Hit Gym and Lift Bro Walk Dog Hit Gym and Lift Bro Hit Gym and Lift Bro Hit Gym and Lift Bro Hit Gym and Lift Bro Walk Dog Hit Gym and Lift Bro Hit Gym and Lift Bro Hit
      Gym and Lift Bro Hit Gym and Lift Bro</h1>
  </div>

  <div id='main-grid'>
    <div class="container2">
      <h5 id='appHeader'>To-Do-List</h5>
      <div id='displayHideButton'> <a href='#' id='addItemSymbol' onclick='hideInputAndChangeSymbol()'><i id='symbol'  class="fas fa-minus-circle"  type='submit' ></i></a></div>
      <a href='#' id='addItem'></a>
    </div>

    <ul id='list-body'>
      <li id='enterItem'><input type='text' placeholder="Enter List Item..." id='newNote' class='inputEnterItem'></li>
      <li><span>Walk Dog Hit Gym and Lift Bro Hit Gym and Lift Bro  Hit Gym and Lift Bro Hit Gym and Lift Bro</span></li>
      <li><span>Hit Gym and Lift Bro</span></li>
      <li><span>Stretch</span></li>
    </ul>
  </div>
</div>

关于javascript - CSS 网格和媒体查询的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55231770/

上一篇:css - 当用户滚动时,如何使图像看起来被内容覆盖?

下一篇:html - 力求垂直对齐元素框的边框?

相关文章:

javascript - Jquery mobile 中的 setInterval 不起作用

javascript - 在 Javascript 中获取未展平的过滤多维数组

javascript - 如何在 jQuery UI 对话框上设置包含?

html - 如何在 ASP.NET MVC 中获取移动设备的 CSS 宽度?

javascript - 在 Bootstrap 模态窗口上使用 Intro.js 提示,提示显示在模态后面

html - 无论缩放多少,只有 Firefox 在中间显示 Logo 。 IE 和 Chrome 不读取顶部和底部边距。任何人都知道为什么?

html - div 内的图像根据 Edge 上的标题长度调整大小

html - 自动调整两个 DIV 之间的垂直间距

php - 表格 html/CSS 输出错误 : unexpected T_STRING

javascript - Android 的 WebRTC 支持