3

I quite often build websites whose container acts as like a white page on a different coloured background and the site's content sits within that white page with a little bit of padding so that it doesn't touch the sides.

This is quite challenging when using a responsive grid. If I add say 50px of padding to the container, at certain resolutions things work perfectly but at other sizes, the page becomes too big for the screen, this is obviously to do with the widths defined in bootstrap's CSS for certain media queries.

I started going into each media query and doing some mathematics to figure out exactly how many pixels needed to be subtracted from each span and each offset in order for the page to display correctly at any given resolution but then I stopped myself and thought, there must be a better way!

I'm not averse to doing the necessary work but as I see myself coming across this problem on many if not all TB projects, I'd like to feel that I'm approaching the process in the most logical and easily-repeatable way.

Would you manually change pixel sizes for each span and offset? Or perhaps there is another more sensible way to approach a padded container?

I would much appreciate your thoughts! Thanks.

4

1 回答 1

6

您可以将 box-sizing 设置为border-box。问题是 12 个跨度的 with 大于容器的 with。您可以通过使用.row-fluid来解决这个问题,它使网格相对。

.container { box-sizing: border-box; padding: 50px; }

http://www.w3schools.com/cssref/css3_pr_box-sizing.asp http://twitter.github.com/bootstrap/scaffolding.html#fluidGridSystem

于 2012-10-17T13:39:08.600 回答