CSS trick for float left without new line but show some and hide remaining

Sudhakar Krishnan

I tried css code in google and find none for a long time. I can do this by javascript,

Get the body/parent div's width and height, then place div and hide remaining

or

By div * nos and add this value to parent div's width and stop overflow.

I think this trick can be done using css3. If you achieved this by css3, pls post your code.

My Question demo will be something like this.

<div id="parent">
<div class="small s1">some thing</div>
<div class="small s2">some thing</div>
<div class="small s3">some thing</div>
<div class="small s4">some thing</div>
</div>

In this parent will have 500px width and height 500px; class small will have 300px width and 100px height;

If i apply float for class small i can see this in next line.

I need to show only 2 small div, and the second div must show only 200px and 100px hidden. also s3 and s4 must be hidden.

IMPORTANT parent div will be a dynamic value.

Daniel Perván

I suggest that you try playing around with display: inline-block and white-space: nowrap which I believe would achieve what you are looking for.

JsFiddle

For maximum compatibility with IE7 and below, you should however replace the .small divs with spans.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

CSS text starts a new line in float left

From Dev

Float Left in more columns CSS trick

From Dev

CSS Float Left to Line Up

From Dev

CSS - Float: left on the same line

From Dev

How to float left without wrapping to next line?

From Dev

Hide/Show from left

From Dev

How to start a new line after float:left with different height?

From Dev

Multiple divs on same line without using float:left on each element

From Dev

How to code optional attribute without value to show/hide some blocks?

From Dev

CSS hide/show using only in-line CSS

From Dev

HTML/CSS Float Left and Top/Bottom without position absolute/fixed

From Dev

float: left; ambiguity - CSS

From Dev

CSS overflow to float left

From Dev

CSS Float Left and then Right

From Dev

HTML/CSS: Float Left

From Dev

Show hide divs on click in HTML and CSS without jQuery

From Dev

Onclick show/hide a div -only css and without href. NO jquery

From Dev

Show/Hide without reloading

From Dev

Float right and left are on the same line

From Dev

Go to a new line after meet some char with css

From Dev

How do I prevent line breaks on centered images without using float left?

From Dev

TextBlock with some text as left aligned and the remaining text as right aligned

From Dev

CSS: Float left and position absolute

From Dev

Float Left Suppressing CSS Accordion

From Dev

CSS UL as table with float left

From Dev

CSS Can't float left

From Dev

CSS float left and position elements

From Dev

CSS Inheritance and float:left issues

From Dev

CSS: Difference between float:left and float:right