CSS Div with fixed height and automatic width

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



CSS Div with fixed height and automatic width



so i want to make a div container, which i give a fixed height and want that it automatically fit its width to the content in it, even if it is over 100% of the screen width.
Simply by declaring width:auto on the css of the div won't work, because it's not becoming bigger than 100% of the screen.


.container
background: red;
height: 200px;
width: auto;



Here is a demo:



http://jsfiddle.net/8MqtN/2/





If you want a div to encompass an entire width, simply do not add a width property to the CSS. I see no issue in your fiddle. Perhaps you haven't explained the issue well enough.
– Scott
Mar 29 '13 at 18:54




3 Answers
3



Use the following css for your body and try once and see if you get what you want .


body

margin : 0;
padding: 0;



Instead of width try using display:inline-block


display:inline-block



I just added to your css class .container


position: relative; display: table;



Now your content seems to be aware of the the height of your content. The red background you set expands accordingly to the content inside. Is that what you are trying to achieve?





Sorry I see you want expanding width not height.. I'm trying below suggestions for display: inline-block;, that isn't working for me.. I'm playing with more things... un momento por favor
– Scott Dallas
Sep 3 '16 at 6:39





What if you added, td float: left; width: 100%: that should expand each block 100% of the available viewing area
– Scott Dallas
Sep 3 '16 at 6:42







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard