1

I have a div with class container. I have 3 more divs inside .container. What I want is to display internal divs float: left so that 2 divs tags are visible inside .container and the third one is invisible and is placed on the right side of first 2 div tags which are visible. I am trying the following code but it makes all tags visible all the time.

jsfiddle

<div class="container">
        <div class="div"></div>
        <div class="div"></div>
        <div class="div"></div>
    </div>

css

.container {
            position: relative;
            width: 405px;
            height: 500px;
            background: red;
            margin: 0 auto;
            overflow: hidden;
        }
        .div {
            width: 200px;
            height: 200px;
            background: blue;
            float: left;
            border: 1px solid red;
        }

I want above to look like this

enter image description here

Om3ga
  • 30,465
  • 43
  • 141
  • 221
  • increase the width of .container. It have only 405px as width. child div tag have 200px as width, 2 div occupies 400px. then how 3rd one will display? – DRAJI Sep 07 '13 at 08:21
  • I want the 3rd div to be not shown. I will later add `next` button so when clicking next button the first div will move towards left and will become invisible and the third will become visible. – Om3ga Sep 07 '13 at 08:23
  • reduce width of the .container class upto you reach your goal – DRAJI Sep 07 '13 at 08:26
  • Check my modified answer. – Ashis Kumar Sep 07 '13 at 08:39
  • @2619 did you check other answer's besides Ashis'? – omma2289 Sep 07 '13 at 22:45

3 Answers3

3

You can do as such in other way,

HTML

<div class="container">
    <div class="innerContainer">
        <div class="div"></div>
        <div class="div"></div>
        <div class="div"></div>
    </div>
</div>

CSS

.container {
    position: relative;
    width: 405px;
    height: 500px;
    background: red;
    margin: 0 auto;
    overflow: hidden;
}
.innerContainer {
    position: relative;
    width: 605px;
    height: 500px;
    overflow: hidden;
}
.div {
    width: 200px;
    height: 200px;
    background: blue;
    float: left;
    border: 1px solid red;
}

Check over here http://jsfiddle.net/nftp6/8/

Ashis Kumar
  • 6,494
  • 2
  • 21
  • 36
  • @2619 In your design, the third one is partially visible. If you want in that way, check this http://jsfiddle.net/nftp6/10/. – Ashis Kumar Sep 08 '13 at 03:55
2

Use:

display: inline-block;
white-space: nowrap;

For that effect

Fiddle:

http://jsfiddle.net/Hive7/nftp6/5/

Hive7
  • 3,599
  • 2
  • 22
  • 38
1

Use display:inline-block instead of float and set white-space:nowrap to the container:

.container {
    position: relative;
    width: 405px;
    height: 500px;
    background: red;
    margin: 0 auto;
    overflow: hidden;
    white-space: nowrap;
}
.div {
    width: 200px;
    height: 200px;
    background: blue;
    display: inline-block;
    border: 1px solid red;
}

Demo fiddle

Now you'll most likely face some white-space issues, read this answer for multiple ways to handle that

Community
  • 1
  • 1
omma2289
  • 54,161
  • 8
  • 64
  • 68