我有类似的问题。
就我而言,我的基本字体大小为 12 像素,基线为 18 像素。
正如 Eric 所说,“通过添加两个 1px 的边框,你就知道你正在打破 2px 的节奏”。
这就是leading-border
和trailing-border
mixins 可以帮助你的地方。
leading-border($width: 1px, $lines: 1, $font-size: $base-font-size,
$border-style: $default-rhythm-border-style)
trailing-border($width: 1px, $lines: 1, $font-size: $base-font-size,
$border-style: $default-rhythm-border-style)
不幸的是,默认情况下,这些 mixins 会将边框与填充相结合,但没有边距(我的 hr 标签所需的顶部和底部边框各为 1px)。
我所做的是覆盖默认mixins以添加边距属性(不确定这样做是否是个好主意):
@function rhythm($lines: 1, $font-size: $base-font-size, $offset: 0) {
@if not $relative-font-sizing and $font-size != $base-font-size {
@warn "$relative-font-sizing is false but a relative font size was passed to the rhythm function";
}
$rhythm: $font-unit * ($lines * $base-line-height - $offset) / $font-size;
// Round the pixels down to nearest integer.
@if unit($rhythm) == px {
$rhythm: floor($rhythm);
}
@return $rhythm;
}
/*override original apply-side-rhythm-border mixin to include property variable - now you can use padding or margin for adding whitespace*/
@mixin apply-side-rhythm-border($side, $width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style, $property: padding) {
@if not $relative-font-sizing and $font-size != $base-font-size {
@warn "$relative-font-sizing is false but a relative font size was passed to apply-side-rhythm-border"; }
border-#{$side}: {
style: $border-style;
width: $font-unit * $width / $font-size; };
#{$property}-#{$side}: rhythm($lines, $font-size, $offset: $width);
}
/*override original leading-border mixin to include property variable - now you can use padding or margin for adding whitespace*/
@mixin leading-border($width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style, $property: padding) {
@include apply-side-rhythm-border(top, $width, $lines, $font-size, $border-style, $property);
}
/*override original trailing-border mixin to include property variable - now you can use padding or margin for adding whitespace*/
@mixin trailing-border($width: 1px, $lines: 1, $font-size: $base-font-size, $border-style: $default-rhythm-border-style, $property: padding) {
@include apply-side-rhythm-border(bottom, $width, $lines, $font-size, $border-style, $property);
}
现在我的 hr 标签:
hr {
@include leading-border($property:margin);
@include trailing-border($property:margin);
border-bottom-color: #353535;
border-top-color: #0d0d0d;
}
将编译为:
hr {
border-bottom: 0.083em solid #353535;
border-top: 0.083em solid #0D0D0D;
margin-bottom: 1.417em;
margin-top: 1.417em;
}
而且我的垂直节奏不再中断。
试一试,让我知道它是否有效。