【问题标题】:How can I get different spacing between lines and between "paragraphs"?如何在行之间和“段落”之间获得不同的间距?
【发布时间】:2019-12-14 05:55:48
【问题描述】:

我有一个框,其中的文本以跨度显示。我使用 line-height 来改变一个部分内的间距,但需要有不同的部分之间的距离。

查看此页面上的橙色框: https://theslowroad.org/category/destinations/asia/laos/#

我尝试使用边距和填充,但似乎没有效果。

        '<span class="boxhead">' . 'Major stops:' . '</span>' . '<span class="boxtext">' . $where . '</span>' . '<br>' .
        '<span class="boxhead">' . 'Memorable moment:' . '</span>' . '<span class="boxtext">' . $moment . '</span>' . '<br>' .
        '<span class="boxhead">' . 'Did you know?' . '</span>' . '<span class="boxtext">' . $fact . '</span>';
    ?> 

CSS:

.boxhead {
    margin-right: 18px; 
    font-weight: bold;
    font-style: italic;
    text-transform: uppercase;
    padding-bottom: 19px;
}

.boxtext {
padding-bottom: 19px;
}

.infobox {
    line-height: 1.2em;
    clear: both;
    background-color: #bf593a;
    color: white;
    padding: 5%;
    border-radius: 10px ;
    margin-left:6%;
    margin-right: 6%;
    margin-top: 8%;
    margin-bottom: 10%;
}

谢谢!

【问题讨论】:

  • span 是内联元素,尝试使用p 标记行分隔段落

标签: html css text


【解决方案1】:

一种简单的方法是将 .boxtext 选择器更改为:

.boxtext {
  padding-bottom: 19px;
  display: inline-block;
}

但我建议将所有 span.boxhead span.boxtext 类与 &lt;div class="boxgroup"&gt; 分组

'<div class="boxgroup"><span class="boxhead">Major stops:</span> <span class="boxtext">' . $where . '</span></div>' .
'<div class="boxgroup"><span class="boxhead">Memorable moment:</span> <span class="boxtext">' . $moment . '</span></div>' .
'<div class="boxgroup"><span class="boxhead">Did you know?</span> <span class="boxtext">' . $fact . '</span></div>';

(还冒昧地删除了多余的字符串连接,希望你不介意。)

并将 .boxtext 选择器更改为:

.boxgroup {
  padding-bottom: 19px;
}

【讨论】:

  • 完美——谢谢! (我对此很陌生。我非常感谢帮助。)
猜你喜欢
  • 2017-05-06
  • 1970-01-01
  • 1970-01-01
  • 2017-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-19
  • 2010-10-08
相关资源
最近更新 更多