Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

201 строка
7.6 KiB

  1. <div class="bs-docs-section">
  2. <h1 id="helper-classes" class="page-header">Helper classes</h1>
  3. <h3 id="helper-classes-colors">Contextual colors</h3>
  4. <p>Convey meaning through color with a handful of emphasis utility classes. These may also be applied to links and will darken on hover just like our default link styles.</p>
  5. <div class="bs-example">
  6. <p class="text-muted">Fusce dapibus, tellus ac cursus commodo, tortor mauris nibh.</p>
  7. <p class="text-primary">Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
  8. <p class="text-success">Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</p>
  9. <p class="text-info">Maecenas sed diam eget risus varius blandit sit amet non magna.</p>
  10. <p class="text-warning">Etiam porta sem malesuada magna mollis euismod.</p>
  11. <p class="text-danger">Donec ullamcorper nulla non metus auctor fringilla.</p>
  12. </div>
  13. {% highlight html %}
  14. <p class="text-muted">...</p>
  15. <p class="text-primary">...</p>
  16. <p class="text-success">...</p>
  17. <p class="text-info">...</p>
  18. <p class="text-warning">...</p>
  19. <p class="text-danger">...</p>
  20. {% endhighlight %}
  21. <div class="bs-callout bs-callout-info">
  22. <h4>Dealing with specificity</h4>
  23. <p>Sometimes emphasis classes cannot be applied due to the specificity of another selector. In most cases, a sufficient workaround is to wrap your text in a <code>&lt;span&gt;</code> with the class.</p>
  24. </div>
  25. <h3 id="helper-classes-backgrounds">Contextual backgrounds</h3>
  26. <p>Similar to the contextual text color classes, easily set the background of an element to any contextual class. Anchor components will darken on hover, just like the text classes.</p>
  27. <div class="bs-example bs-example-bg-classes">
  28. <p class="bg-primary">Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
  29. <p class="bg-success">Duis mollis, est non commodo luctus, nisi erat porttitor ligula.</p>
  30. <p class="bg-info">Maecenas sed diam eget risus varius blandit sit amet non magna.</p>
  31. <p class="bg-warning">Etiam porta sem malesuada magna mollis euismod.</p>
  32. <p class="bg-danger">Donec ullamcorper nulla non metus auctor fringilla.</p>
  33. </div>
  34. {% highlight html %}
  35. <p class="bg-primary">...</p>
  36. <p class="bg-success">...</p>
  37. <p class="bg-info">...</p>
  38. <p class="bg-warning">...</p>
  39. <p class="bg-danger">...</p>
  40. {% endhighlight %}
  41. <div class="bs-callout bs-callout-info">
  42. <h4>Dealing with specificity</h4>
  43. <p>Sometimes contextual background classes cannot be applied due to the specificity of another selector. In some cases, a sufficient workaround is to wrap your element's content in a <code>&lt;div&gt;</code> with the class.</p>
  44. </div>
  45. <h3 id="helper-classes-close">Close icon</h3>
  46. <p>Use the generic close icon for dismissing content like modals and alerts.</p>
  47. <div class="bs-example">
  48. <p><button type="button" class="close"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button></p>
  49. </div>
  50. {% highlight html %}
  51. <button type="button" class="close"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  52. {% endhighlight %}
  53. <h3 id="helper-classes-carets">Carets</h3>
  54. <p>Use carets to indicate dropdown functionality and direction. Note that the default caret will reverse automatically in <a href="../components/#btn-dropdowns-dropup">dropup menus</a>.</p>
  55. <div class="bs-example">
  56. <span class="caret"></span>
  57. </div>
  58. {% highlight html %}
  59. <span class="caret"></span>
  60. {% endhighlight %}
  61. <h3 id="helper-classes-floats">Quick floats</h3>
  62. <p>Float an element to the left or right with a class. <code>!important</code> is included to avoid specificity issues. Classes can also be used as mixins.</p>
  63. {% highlight html %}
  64. <div class="pull-left">...</div>
  65. <div class="pull-right">...</div>
  66. {% endhighlight %}
  67. {% highlight scss %}
  68. // Classes
  69. .pull-left {
  70. float: left !important;
  71. }
  72. .pull-right {
  73. float: right !important;
  74. }
  75. // Usage as mixins
  76. .element {
  77. .pull-left();
  78. }
  79. .another-element {
  80. .pull-right();
  81. }
  82. {% endhighlight %}
  83. <div class="bs-callout bs-callout-warning">
  84. <h4>Not for use in navbars</h4>
  85. <p>To align components in navbars with utility classes, use <code>.navbar-left</code> or <code>.navbar-right</code> instead. <a href="../components/#navbar-component-alignment">See the navbar docs</a> for details.</p>
  86. </div>
  87. <h3 id="helper-classes-center">Center content blocks</h3>
  88. <p>Set an element to <code>display: block</code> and center via <code>margin</code>. Available as a mixin and class.</p>
  89. {% highlight html %}
  90. <div class="center-block">...</div>
  91. {% endhighlight %}
  92. {% highlight scss %}
  93. // Classes
  94. .center-block {
  95. display: block;
  96. margin-left: auto;
  97. margin-right: auto;
  98. }
  99. // Usage as mixins
  100. .element {
  101. .center-block();
  102. }
  103. {% endhighlight %}
  104. <h3 id="helper-classes-clearfix">Clearfix</h3>
  105. <p>Easily clear <code>float</code>s by adding <code>.clearfix</code> <strong>to the parent element</strong>. Utilizes <a href="http://nicolasgallagher.com/micro-clearfix-hack/">the micro clearfix</a> as popularized by Nicolas Gallagher. Can also be used as a mixin.</p>
  106. {% highlight html %}
  107. <!-- Usage as a class -->
  108. <div class="clearfix">...</div>
  109. {% endhighlight %}
  110. {% highlight scss %}
  111. // Mixin itself
  112. .clearfix() {
  113. &:before,
  114. &:after {
  115. content: " ";
  116. display: table;
  117. }
  118. &:after {
  119. clear: both;
  120. }
  121. }
  122. // Usage as a Mixin
  123. .element {
  124. .clearfix();
  125. }
  126. {% endhighlight %}
  127. <h3 id="helper-classes-show-hide">Showing and hiding content</h3>
  128. <p>Force an element to be shown or hidden (<strong>including for screen readers</strong>) with the use of <code>.show</code> and <code>.hidden</code> classes. These classes use <code>!important</code> to avoid specificity conflicts, just like the <a href="#helper-classes-floats">quick floats</a>. They are only available for block level toggling. They can also be used as mixins.</p>
  129. <p><code>.hide</code> is available, but it does not always affect screen readers and is <strong>deprecated</strong> as of v3.0.1. Use <code>.hidden</code> or <code>.sr-only</code> instead.</p>
  130. <p>Furthermore, <code>.invisible</code> can be used to toggle only the visibility of an element, meaning its <code>display</code> is not modified and the element can still affect the flow of the document.</p>
  131. {% highlight html %}
  132. <div class="show">...</div>
  133. <div class="hidden">...</div>
  134. {% endhighlight %}
  135. {% highlight scss %}
  136. // Classes
  137. .show {
  138. display: block !important;
  139. }
  140. .hidden {
  141. display: none !important;
  142. visibility: hidden !important;
  143. }
  144. .invisible {
  145. visibility: hidden;
  146. }
  147. // Usage as mixins
  148. .element {
  149. .show();
  150. }
  151. .another-element {
  152. .hidden();
  153. }
  154. {% endhighlight %}
  155. <h3 id="helper-classes-screen-readers">Screen reader and keyboard navigation content</h3>
  156. <p>Hide an element to all devices <strong>except screen readers</strong> with <code>.sr-only</code>. Combine <code>.sr-only</code> with <code>.sr-only-focusable</code> to show the element again when it's focused (e.g. by a keyboard-only user). Necessary for following <a href="../getting-started/#accessibility">accessibility best practices</a>. Can also be used as mixins.</p>
  157. {% highlight html %}
  158. <a class="sr-only sr-only-focusable" href="#content">Skip to main content</a>
  159. {% endhighlight %}
  160. {% highlight scss %}
  161. // Usage as a Mixin
  162. .skip-navigation {
  163. .sr-only();
  164. .sr-only-focusable();
  165. }
  166. {% endhighlight %}
  167. <h3 id="helper-classes-image-replacement">Image replacement</h3>
  168. <p>Utilize the <code>.text-hide</code> class or mixin to help replace an element's text content with a background image.</p>
  169. {% highlight html %}
  170. <h1 class="text-hide">Custom heading</h1>
  171. {% endhighlight %}
  172. {% highlight scss %}
  173. // Usage as a Mixin
  174. .heading {
  175. .text-hide();
  176. }
  177. {% endhighlight %}
  178. </div>