Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display inline blocks without breaking them on new line when shrinking parent

Tags:

html

css

width

I have 2 columns (inline blocks) in a container (100% width).

  1. Left side column has to have a min-width, say 200px, width:25%.

  2. Right side column has width:75%

    <style> .outer {     width: 100%;     border: 1px solid black; } .left, .right {     display:inline-block; } .left {     min-width: 200px;     width: 25%;     background-color: #dcc2c2; } .right {     width: 75%;     background-color: #d0dee8; } </style>      <div class="outer">         <div class="left">left</div>         <div class="right">right</div>     </div> 

Until the min-width is reached when resizing, the columns sit side by side which is what I want, but once the min-width kicks in, the right column falls on the next line.

How can I make the right column to shrink but not fall on the next line ?

Link to JSFiddle

like image 673
code.tweetie Avatar asked Jun 10 '14 13:06

code.tweetie


People also ask

How do you make elements stay on the same line?

To get all elements to appear on one line the easiest way is to: Set white-space property to nowrap on a parent element; Have display: inline-block set on all child elements.

How do you prevent inline block elements from wrapping?

As a result, the elements can sit next to each other. The major difference between display: inline; and display: inline-block; is that, display: inline-block; also allows us to set the width and height of the element. We can prevent inline-block divs from wrapping by adding suitable Bootstrap classes.

How do I force HTML elements to stay on the same line?

You can force the content of the HTML <div> element stay on the same line by using a little CSS. Use the overflow property, as well as the white-space property set to “nowrap”.

Does inline block start a new line?

An inline element does not start on a new line. An inline element only takes up as much width as necessary. This is a <span> element inside a paragraph.


1 Answers

Add white-space:nowrap and overflow:hidden to outer:

.outer {     width: 100%;     border: 1px solid black;     white-space:nowrap;     overflow:hidden; } 

jsFiddle example

like image 176
j08691 Avatar answered Oct 07 '22 11:10

j08691