在某些情况下,我是一个全新的编程新手,只学了大约两个小时的HTML/CSS教程,所以除了您在这里看到的代码之外,我不知道很多元素、属性等.如果我的术语不准确,请原谅,但希望这是有意义的.

我在一节课结束时做了一个练习,试图匹配一个设计,并试图消除我的第一段行和第二段行之间的空白.如您所见,我已经try 将页边距、行高和填充更改为零(我能想到的任何值),但间距仍然存在.

在本练习的解决方案代码中,我看到老师 Select 更改针对所有段落的下边距,而不是特定的段落类.我想了解为什么这会奏效,但针对特定的段落类别并不影响页边距.我想我稍后会明白这一点,但在我明白之前,我会犹豫继续前进.

My code

<style>
p {
  font-family: arial;
}
.price {
  font-size: 36px;
}
.currency {
  margin-left: 12px;
  font-size: 16px;
  color: gray;
  margin-bottom: 0px;
  line-height: 0px;
  padding-bottom: 0;
}
.change {
  padding-top: 0;
  margin-top: 0;
  color: green;
  font-size: 16px;
  line-height: 0;
}
.after-hours {
  color: gray;
}
.after-hours-change {
  color: red;
}
</style>

<p class="price">1,049.61<span class="currency">USD</span></p>

<p class="change">+18.05 (1.75%) today</p>

<p class="after-hours">After hours 1,048.00 
  
<span class="after-hours-change">-1.61 (0.15%)</span></p>

Picture of my result

The teacher's solution code

<style>
  p {
    font-family: Arial;
    margin-top: 0;
    margin-bottom: 0;
  }

  .price {
    font-size: 32px;
    margin-bottom: 5px;
  }

  .currency {
    font-size: 16px;
    color: rgb(100, 100, 100);
  }

  .change {
    color: rgb(24, 128, 56);
    margin-bottom: 8px;
  }

  .after-hours {
    color: rgb(100, 100, 100);
  }

  .after-hours-change {
    color: rgb(235, 39, 39);
  }
</style>

<p class="price">
  1,049.61 <span class="currency">USD</span>
</p>

<p class="change">
  +18.05 (1.75%) today
</p>

<p class="after-hours">
  After hours 1,048.00
  <span class="after-hours-change">-1.61 (0.15%)</span>
</p>

Picture of his result

推荐答案

因为margin-bottom: 5px;不是你设定的.price. 段落是一个块元素,所以它在下面加起来是margin,但font-size也包括在内--正如我所看到的.

p {
  font-family: arial;
}

.price {
  font-size: 32px;
  margin-bottom: 0.5em;
}

.currency {
  margin-left: 12px;
  font-size: 16px;
  color: gray;
  margin-bottom: 0px;
  line-height: 0px;
  padding-bottom: 0;
}

.change {
  padding-top: 0;
  margin-top: 0;
  color: green;
  font-size: 16px;
  line-height: 0;
}

.after-hours {
  color: gray;
}

.after-hours-change {
  color: red;
}
<p class="price">1,049.61<span class="currency">USD</span></p>

<p class="change">+18.05 (1.75%) today</p>

<p class="after-hours">After hours 1,048.00<span class="after-hours-change">-1.61 (0.15%)</span></p>

Html相关问答推荐

如何让QML`Text`元素内的链接在悬停时显示鼠标指针?

如何使我的组织 struct 图的连接线响应?

具有可展开行的棱角material 表(垫子表),折叠时行之间仍有间隙

在WooCommerce单一产品页面上使产品图片库粘滞(固定)

滚动平滑在笔记本电脑上不起作用,但在Nextjs网站的手机浏览器中起作用

如何更改Django中的默认按钮?

在TWebLabel标题中设置换行符/换行符的方法?

(HTML框架标签)点击后目标框架将不再工作

Swift WKUserContentController 和 WKScriptMessageHandler 设置不正确

可以通过悬停时的自定义区域更改文本属性吗?

如何使用javascript在jsx中重复插入特殊字符?

CSS flex:0 0 auto创建了1像素的间隙

HTML画布放大/缩小算法与CSS(图像处理)

导航丸被选中(活动),但内容未显示.怎么会?

SVG 调整大小而不是溢出

单击按钮时更改字体真棒图标