search

Home  >  Q&A  >  body text

css3 - 为啥img的高度和a的高度不一样

<p>
    <a href="">
        <img src="images/1.jpg" alt="">
    </a>
</p>
css
*{
    margin: 0;padding: 0;
}

@media (min-width: 320px) {
html {
    font-size: 100px;
}
}
@media (min-width: 360px) {
html {
font-size: 112.5px;
}
}
@media (min-width: 400px) {
html {
font-size: 125px;
}
}
p{
    margin: 2%;
}
a{
    display: block;
}
img{
    height: .64rem;
}


为什么img的高度是64px,而a的高度是114px呢?

高洛峰高洛峰2784 days ago515

reply all(4)I'll reply

  • 黄舟

    黄舟2017-04-17 11:33:14

    Are you sure the margin and padding have been cancelled?

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 11:33:14

    Add display:block

    to the
    img tag or add font-size:0 or line-height:0
    to the

    a tag

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 11:33:14

    Because img is an inline element, the outer layer has a default line-height

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 11:33:14

    em is inheritable
    If the img height is calculated in em, its height is 0.64*the font-size of the a element
    If the iPhone 5 is simulated with the chrome browser, the result is
    img high 80px, element height is 125px

    How did you come up with the combination of 64 and 114?

    reply
    0
  • Cancelreply