Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Auto resize div to fit container width

Tags:

css

I have two <div>: left and contents. These two are inside wrapper div that has min-width:960px;. left has fixed width, but I want to make content flexible with min width of 700px and if screen is wider, stick it to the right bound of screen.
screenshot

CSS:

#wrapper
{
    min-width:960px;
    margin-left:auto;
    margin-right:auto;
}
#left
{
    width:200px;
    float:left;
    background-color:antiquewhite;
    margin-left:10px;
}
#content
{
    min-width:700px;
    margin-left:10px;
    width:auto;
    float:left;
    background-color:AppWorkspace;
}

JSFiddle: http://jsfiddle.net/Zvt2j/

like image 298
Maysam Avatar asked Jan 14 '13 13:01

Maysam


People also ask

How do I automatically resize div width?

Answer: Use the CSS max-width Property You can simply use the CSS max-width property to auto-resize a large image so that it can fit into a smaller width <div> container while maintaining its aspect ratio.

How do I auto-resize an image to fit a div container?

To auto-resize an image or a video to fit in a div container use object-fit property. It is used to specify how an image or video fits in the container. object-fit property: This property is used to specify how an image or video resize and fit the container.

How to auto-size images to fit into a DIV container using CSS?

It is very easy to auto-size images to fit into a div container. In this tutorial, we will learn about the CSS properties used to auto-size the image. The width and height properties can be used to auto-resize the image so that it fits into the div container. Do not use explicit height and width to the image tag.

How do I resize images to fit a Div?

Three ways to resize images to fit a DIV : 1 Two different CSS classes (one for width, one for height). 2 Using the STYLE attribute within the IMG tag to manually set the width or height for each image (essentially the same as #1). 3 Warning, exiting browser-side territory!

How to auto-resize an image to fit an HTML container?

CSS makes it possible to resize an image to fit an HTML container. To auto-resize an image or a video you can use the object-fit property. It is used to specify how an image or video fits in the entire container.

How to set a Div size according to its content using CSS?

Using inline-block property: Use display: inline-block property to set a div size according to its content. making web pages presentable. CSS allows you to apply styles to web pages. More each web page. Using fit-content property in width and height: In this method, we set the width and height property to fit-content value.


1 Answers

You can overflow:hidden to your #content. Write like this:

#content
{
    min-width:700px;
    margin-left:10px;
    overflow:hidden;
    background-color:AppWorkspace;
}

Check this http://jsfiddle.net/Zvt2j/1/

like image 171
sandeep Avatar answered Oct 07 '22 17:10

sandeep