【问题标题】:CSS Grid Layout - How to put scrollbar on left, and populate left to rightCSS 网格布局 - 如何将滚动条放在左侧,并从左到右填充
【发布时间】:2019-07-29 20:39:19
【问题描述】:

如何将滚动条放在左边,但让 ng-repeat 从左到右填充

我正在使用 ng-repeat 填充 3 x X(宽度 x 高度)的网格,默认情况下,滚动条在右侧,按照正常的 webview 标准,我想将它放在左侧,所以我使用了direction: rtl;,但问题是现在我的ng-repeat 数据也从右到左填充,但我需要像通常那样从左到右显示数据。

根据我的理解direction:rtl 是将滚动条移动到另一边的唯一方法,是否有一些我缺少的工具可以移动不是direction: rtl 的滚动条,或者是否有另一种方法来翻转我的内容回到ltr?

我的 HTML:

<div class="h-blue-holding-grid">
  <div class="blue-holding-item" ng-repeat='img in recipeArray'>
    <div class="h-blue-holdingImg"><img src="/imgs/redhead.png" width="45" height="45"></img></div>
    <div class="h-blue-smalltime">{{Math.floor(img.data.data.start_time_ms/1000/60)}}:{{img.data.data.start_time_ms/1000%60}}<span ng-if="img.data.data.start_time_ms/1000%60 < 10">0</span></div>
    <div class="h-blue-smallfont">{{img.data.data.name}}</div>
  </div>
</div>

我的 CSS:

.h-blue-holding-grid{
  width: auto;
  display: grid;
  grid-template-columns: 33% 33% 33%;
  grid-gap: 3px 3px;
  margin-right: 5vh;
  height: 25.5vh;
  overflow-y: scroll;
  direction: rtl;
}
.blue-holding-item{
  width: 100%;
  height: 8vh;
  text-align: left;
  background-image: url(/imgs/gradient_blue.png);
  background-size: 20vh 8vh;
  color: white;
  font-family: "Segoe UI";
  font-weight: bold;
  display: grid;
  grid-template-columns: auto auto;
}
.h-blue-holdingImg{
  grid-row-start: 1;
  grid-row-end: 3
}

谢谢,

【问题讨论】:

    标签: html css angularjs css-grid grid-layout


    【解决方案1】:

    是否有一些[方法]可以移动不是direction: rtl的滚动条?

    您可以在现代浏览器中使用父&lt;div&gt; 上的transform: scaleX(-1) 来反转滚动条的一侧,然后应用相同的变换来反转子“袖子”元素。

    HTML

    <div class="parent">
      <div class="sleeve">
        <!-- content -->
      </div>
    </div>
    

    CSS

    .parent {
      overflow: auto;
      transform: scaleX(-1); //Reflects the parent horizontally
    }
    
    .sleeve {
      transform: scaleX(-1); //Flips the child back to normal
    }
    

    在How to position a div scrollbar on the left hand side? 中查看this answer

    【讨论】:

    • 这并不能解决我的问题,因为我的网格现在从右到左填充,我不希望它这样做。我的目标是左一个滚动条,但我的网格仍然从左到右填充
    【解决方案2】:

    您可以通过将 direction:ltr 添加到子元素来做到这一点,对您来说它应该像这样工作:

    .blue-holding-item {
        direction:ltr;
    }
    

    这是你想要的吗?

    ===== 更新 =====

    首先,ng-repeat 不是问题,它只是普通的 css,它可以按预期工作。如果您有权访问 html,则需要一个额外的 div 作为 .blue-holding-item 的包装器,您将为它分配方向:ltr;一切都会好起来的。

    这里的工作示例:https://codepen.io/anon/pen/wVeyQg

    【讨论】:

    • 不,网格仍然从右到左填充,将 ltr 放在子元素上只是确保图像保持在子元素的 lft 和右侧的文本
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-27
    • 2011-11-12
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 2023-03-10
    相关资源
    最近更新 更多