【问题标题】:fix first and last divs css修复第一个和最后一个 div css
【发布时间】:2014-10-07 09:41:30
【问题描述】:

当我在此示例jsfiddle example here 上绑定 scrool 时,我想修复第一个和最后一个 div,就像在 this image 上一样。

我在平板电脑上试过,但它不工作

这里是css

.mother_div {
    display:block;
    height:auto;
    width:500px;
    border:1px solid #000;
    overflow-x:scroll;
}
.child_divs {
    height:40px;
    margin-bottom:1px;
    background:green;
    display:block;
    width:1000px;
}
.child_divs div {
    float:left;
    line-height:40px;
    color:#fff;
    font-size:15px;
    width:100px;
    text-align:center;
}
.child_divs div:first-child {
    background:#ccc;
    color:#000;
}
.child_divs div:last-child {
    background:#ccc;
    color:#000;
}

【问题讨论】:

  • 我无法理解,你能准确解释一下你想要在这里实现的目标吗?

标签: html css-position fixed horizontal-scrolling


【解决方案1】:

试试这个:

解决方案 1:

JSFiddle - DEMO

.child_divs div:first-child {
    position:fixed;
}
.child_divs div:last-child {
    position:fixed;
    left:409px;
}
.child_divs div:nth-child(2) {
    margin-left:100px;
}

解决方案 2:

JSFiddle - DEMO

.child_divs div:first-child {
    position: absolute;
    left: 1px;
}
.child_divs div:last-child {
    position: absolute;
    right: 1px;
}
.child_divs div:nth-child(2) {
    margin-left:100px;
}

【讨论】:

    【解决方案2】:

    这个怎么样?

    .child_divs div:first-child {
        background:#ccc;
        color:#000;
        position: fixed;
        left: 0;
    }
    
    .child_divs div:first-child + div {margin-left: 100px;}
    .child_divs div:last-child {
        background:#ccc;
        color:#000;
        position: fixed;
        right: 0;
    }
    

    http://jsfiddle.net/jy0hmh9g/4/

    【讨论】:

    • 您好,感谢您的回答。是的,我试过这个方法,但是当这个表之前的网站内容很大时,它不起作用jsfiddle.net/qnrv29xj/2
    猜你喜欢
    • 2016-10-13
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多