php - 为什么链接的顶部和底部有空白?

标签 php html css

我有一个被 anchor 标记包围的 h3 标记,但文本的顶部和底部有很多空白,我似乎无法去除。我将发布我拥有的代码和它的外观图像。

HTML/PHP:

echo
'<div class="entertainment-loc-cont">
    <a href="' . $object['link'] . '"><h3 class="entertainment-title">' . $object['title'] . '</h3></a>
    <a href="' . $object['link'] . '"><img src="' . $object['img_link'] . '" /></a>
        <div class="entertainment-info">
            <p class="entertainment-line-1">' . $object['line_1'] . '</p>
            <p class="entertainment-line-2">' . $object['line_2'] . '</p>
            <p class="entertainment-line-3">' . $object['line_3'] . '</p>
            <p class="entertainment-line-4">' . $object['line_4'] . '</p>
            <p class="entertainment-line-5">' . $object['line_5'] . '</p>
        </div>
</div>';

CSS:

.entertainment-loc-cont {
    width: 100%;
}
.entertainment-loc-cont img {
    width: 100%;
}
.entertainment-loc-cont a {
    font-size: 2.5em;
    text-decoration: none;
}
.entertainment-title {
    color: #000000;
}

结果: enter image description here enter image description here

最佳答案

根据 W3 specifications , <h3> 的默认 css 值标签如下:

h3 {
    display: block;
    font-size: 1.17em;
    margin-before: 1em;
    margin-after: 1em;
    margin-start: 0;
    margin-end: 0;
    font-weight: bold;
}

如果你想改变它,在你的CSS中覆盖它,最简单的方法:

h3 { margin: 0; }

关于php - 为什么链接的顶部和底部有空白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35247040/

相关文章:

html - 如何禁用 HTML 元素中的换行?

javascript - 显示列表中的 1 个特定图像?

php - 如何获得总计为特定值的行的随机组合?

javascript - 如果下拉值发生变化,则从数据库中获取值并填充所有文本框

php - 为什么段落与面板标题重叠?

PHP exec() 作为后台进程(Windows Wampserver 环境)

html - Flexbox:使用 Flexbox 将页眉和页脚移动到侧边栏

css - 在模板标签内使用远程样式表(带 shadow dom)

html - 删除 Angular Material slider 幻灯片上的强调色

css - UL 文本菜单 : Inline converted to Block via Media Query - Display Issues