【问题标题】:Float text on the left of the screen when horizontal scrolling水平滚动时在屏幕左侧浮动文本
【发布时间】:2019-06-26 12:29:53
【问题描述】:

我正在尝试用 HTML 和 CSS 制作节日的时间表。已经做了很多工作,但我无法弄清楚这一点。所以我在 HTML 中使用列表 'UL' 'LI' 制作了一个时间表,并在 CSS 文档中设置样式。

目前看起来是这样的。 Look at the screenshot here.

因为它是一个非常庞大的时间表,所以有一个横向滚动。我想弄清楚的是如何让舞台名称的文本,例如“Har&Mar”随着页面滚动,所以当你向左或向右滚动时它会保持在左侧。 Because that ain't the case at the moment ;P

我尝试了一切来解决这个问题,但我不知道如何完成。请发送帮助!我的代码在这里:

<iframe width="100%" height="300" src="//jsfiddle.net/CasperBoon/ayjsuLxe/embedded/html,css,result/" allowfullscreen="allowfullscreen" allowpaymentrequest frameborder="0"></iframe>

最好的问候, 卡斯帕恩

【问题讨论】:

  • 我已经将我的代码上传到了 jsfiddle,现在就在这篇​​文章中!对不起!

标签: html css text fixed


【解决方案1】:

如果您有任何方法可以选择浮动名称,则可以通过将position: fixed; 属性应用于该名称的容器来实现。根据您的代码,它应该看起来像这样(对于“Har & Mar”):

CSS

li.stage-0 > .stage-name {
   position: fixed !important;
   left: 0;
}

我想你会希望在滚动时将所有名称固定在左侧,所以它可能看起来像这样:

CSS

li > .stage-name {
   position: fixed !important;
   left: 0;
}

【讨论】:

    【解决方案2】:

    只有 css 真的很难。

    但是使用jq或js这变得非常容易。

    你可以这样做

    我假设show-right-shadow 是可滚动元素

    $(".show-right-shadow").scroll(function(e){
    var left = this.scrollLeft;
    $(".stage-name").css(// make all the divs [stage-name] follow the scroll
    {
    position:"absolute", // use absolute and not fixed, so u dont mess upp the design
    left:this.scrollLeft, // follow the scroll
    "z-index":9999, // make it at top of all other elements
    })
    });
    

    【讨论】:

      猜你喜欢
      • 2011-03-04
      • 2015-09-26
      • 1970-01-01
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      • 2011-03-12
      • 1970-01-01
      相关资源
      最近更新 更多