html - 填充为顶部和底部提供不同的填充
问题描述
html {
font-size : 10px;
}
body {
text-align : center;
color : #9da8c1;
font-family : sans-serif;
background : #013f81;
}
h1 {
font-size: 4rem;
}
#img-div {
background : #2a5590;
width : 600px;
margin : 0 auto;
padding : 10px;
}
#conway-photo {
height : auto;
width : 500px;
}
figcaption {
font-size : 1.5rem;
background : red;
}
<main id="main">
<h1 id="title">John Horton Conway<h1>
<figure id="img-div">
<img id="conway-photo" src="https://static01.nyt.com/images/2020/04/18/obituaries/14Conway1/14Conway1-mediumSquareAt3X-v2.jpg"</img>
<figcaption>J.H.Conway holding a model of polyhedron</figcaption>
<figure>
</main>
我有这个 html 代码,我想在图中添加填充,以便文本和图像与边框的距离相同。
由于某种原因,我不知道,底部的距离比顶部的距离要大。当我从无填充切换到 10px 时,底部也有一个很大的跳跃。
解决方案
您的 HTML 标签搞砸了,请务必使用 HTML Validator(如https://validator.w3.org/ )检查您的代码。
我修复了您的 HTML,它似乎正在按照您的预期工作:
html {
font-size: 10px;
}
body {
text-align: center;
color: #9da8c1;
font-family: sans-serif;
background-color: #013f81;
}
h1 {
font-size: 4rem;
}
#img-div {
background-color: #2a5590;
width: 600px;
margin: 0 auto;
padding: 10px;
}
#conway-photo {
height: auto;
width: 500px;
}
figcaption {
font-size: 1.5rem;
background-color: red;
}
<html>
<main id="main">
<h1 id="title">John Horton Conway</h1>
<figure id="img-div">
<img id="conway-photo" src="https://static01.nyt.com/images/2020/04/18/obituaries/14Conway1/14Conway1-mediumSquareAt3X-v2.jpg">
<figcaption>J.H.Conway holding a model of polyhedron</figcaption>
</figure>
</main>
</html>
推荐阅读
- graph - 从邻接列表快速创建 Scipy 稀疏矩阵
- fiware - Authzforce - 用于策略管理 (PAP) 的现有 GUI
- python - python中Z3的按位运算
- groovy - 为什么这个简单的 Groovy 脚本在 Jenkins 管道中失败?
- python - 将数据框分为两组时,您是否可以有多个变量的影响因素?熊猫
- selenium - 无法将 /etc/hosts 中映射的 URL 用于 Webdriver.io
- gcc - 在 c/cpp 中初始化空字符数组的其他方法
- c++ - “下一个”不是“标准”的成员
- javascript - 项目未使用 Redux 从数组中删除
- python - Django 3 - 具有初始 ForeignKey 字段的 CreateView