문제

The starter template for bootstrap css includes the following inline:

body {
    padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}

What practical reasons are there for including this style in-line, while all the other code is in an external .css file?

도움이 되었습니까?

해결책

The inline style was deliberately inserted between bootstrap.css and bootstrap-responsive.css. Moving it to main.css (and so after bootstrap-responsive.css) will show the padding above the black menu bar when it adjusts to a smaller window, at least in IE 10 and Chrome 22.

Ideally it should have been added to bootstrap.css but it wasn't for some reason.

Another solution would be to put it in a separate css file but that would require downloading an additional very small file.

Loading main.css between the two bootstrap*.css files would make it more difficult to override specific settings.

So I presume it's a compromise.

다른 팁

There could be several cases,

  • Maybe they wanted this rule to override anything declared in the external stylesheet (aside from !important rules). As inline <style> elements are automatically considered more specific.
  • Maybe they wanted this specific rule to be unique to this page, and not globally available on the entire website. It's possible that the 60px topbar only exists on that page.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top