Horizontal scroll css?

后端 未结 5 1964
礼貌的吻别
礼貌的吻别 2020-12-23 19:35

I want to have one

with id that has horizontal scroll, but the problem is it has to be responsive, not with fixed width.



        
相关标签:
5条回答
  • 2020-12-23 20:15

    use max-width instead of width

    max-width:530px;

    demo:http://jsfiddle.net/FPBWr/161/

    0 讨论(0)
  • 2020-12-23 20:18

    Just set your width to auto:

    #myWorkContent{
        width: auto;
        height:210px;
        border: 13px solid #bed5cd;
        overflow-x: scroll;
        overflow-y: hidden;
        white-space: nowrap;
    }
    

    This way your div can be as wide as possible, so you can add as many kitty images as possible ;3

    Your div's width will expand based on the child elements it contains.

    jsFiddle

    0 讨论(0)
  • 2020-12-23 20:20

    Below worked for me.

    Height & width are taken to show that, if you 2 such children, it will scroll horizontally, since height of child is greater than height of parent scroll vertically.

    Parent CSS:

    .divParentClass {
        width: 200px;
        height: 100px;
        overflow: scroll;
        white-space: nowrap;
    }
    

    Children CSS:

    .divChildClass {
        width: 110px;
        height: 200px;
        display: inline-block;
    }
    

    To scroll horizontally only:

    overflow-x: scroll;
    overflow-y: hidden;
    

    To scroll vertically only:

    overflow-x: hidden;
    overflow-y: scroll;
    
    0 讨论(0)
  • 2020-12-23 20:28

    I figured it this way:

    * { padding: 0; margin: 0 }
    body { height: 100%; white-space: nowrap }
    html { height: 100% }
    
    .red { background: red }
    .blue { background: blue }
    .yellow { background: yellow }
    
    .header { width: 100%; height: 10%; position: fixed }
    .wrapper { width: 1000%; height: 100%; background: green }
    .page { width: 10%; height: 100%; float: left }
    
    <div class="header red"></div>
    <div class="wrapper">
        <div class="page yellow"></div>
        <div class="page blue"></div>
        <div class="page yellow"></div>
        <div class="page blue"></div>
        <div class="page yellow"></div>
        <div class="page blue"></div>
        <div class="page yellow"></div>
        <div class="page blue"></div>
        <div class="page yellow"></div>
        <div class="page blue"></div>
    </div>
    

    I have the wrapper at 1000% and ten pages at 10% each. I set mine up to still have "pages" with each being 100% of the window (color coded). You can do eight pages with an 800% wrapper. I guess you can leave out the colors and have on continues page. I also set up a fixed header, but that's not necessary. Hope this helps.

    0 讨论(0)
  • 2020-12-23 20:32

    Just make sure you add box-sizing:border-box; to your #myWorkContent.

    http://jsfiddle.net/FPBWr/160/

    0 讨论(0)
提交回复
热议问题