English 中文(简体)
html element with percentage width needs to have a minimum width of its inner static content
原标题:

html element with percentage width needs to have a minimum width of its inner static content

Hello, I m trying to create a fluid / responsive layout. Is there any way to force an html element that has a percentage width to have a minimum width of its inner content? That is, if it s inner content has some sort of static width, like 200px?

Here’s an example: http://www.nathanielkessler.com/div/csshelp.html

If, in IE9 you set it to Quirks mode and resize the windows in and out, it behaves exactly like I want. (notice how the second div on the right pops under the first div on the left when the screen is resized inward).

If you set the document back to IE9 Standards mode and then resize inwards you ll see that the outer red bordered div does not respect its inner contents (the yellow box). I just continues to shrink beyond what should be its boundary.
Is there any way to make it behave like it does in quirks mode? (Without JavaScript)

最佳回答

Thanks, I ended up finding a pretty specific css/html combination that gave me the behavior I was after. Works in all major browsers including ie7 to ie 9.

Basically, in a row of left floating elements, if you give the first element a min-width % setting and the rest of the elements a combination of min-width % + width % ... you get a fluid layout that forces elements to drop under their sibling elements when the browser window shrinks.

Here s a working example, try resizing the browser. http://www.nathanielkessler.com/div/cssfluid.html

问题回答

I think what you want is the min-width CSS attribute. Set .item { min-width: 200px; }





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签