【发布时间】:2021-09-25 15:53:22
【问题描述】:
我正在尝试使用 100% 的高度在“动物收养中心”旁边放置一个徽标。在开发者工具的 img 上可以看到 height 属性为 100%,但没有被应用。但是,width 属性确实有效。父属性不是 height = 0 并且具有高度,因此这不应该是问题。我很困惑为什么宽度会起作用而高度不会。另外,img 源是 svg。
TLDR
height: 100% 不能在 site-logo 上工作,但 width: 可以。
感谢您的帮助:)
渲染了什么
蓝色轮廓代表“header-content” div,它是图像的父元素。
html
<div id="header-bar">
<div id="header-content">
<!-- The site logo -->
<img id="site-logo" src="assets/logo.svg" alt="site-logo">
<div id="title-wrapper">
<h1 id="website-title">{{websiteTitle}}</h1>
<h4 id="selected-center-city-name">{{currentStoreCity}} Center</h4>
</div>
</div>
</div>
css
#header-bar {
background-color: rgb(75, 75, 75);
width: 100%;
padding-top: 10px;
padding-bottom: 10px;
}
#header-content {
color: #fff;
margin-left: 25px;
}
#site-logo {
height: 100%;
}
#title-wrapper {
display: inline-block;
}
#website-title {
margin-left: 25px;
}
#selected-center-city-name {
text-align: right;
margin-right: 25px;
margin-top: 10px;
}
【问题讨论】:
-
您的最终目标是什么?您是否希望徽标是全高和旁边的两段文字?对于第二个标题,你想要它一直到右边吗?对齐方式是什么?您可能需要为此使用 flexbox。
-
您需要定义不带百分比的#header-bar 的高度值。我遇到了这个问题,并以这种方式解决了。我会关注这个问题。如果有其他方法可以提供帮助吗?
-
@davidleininger 最终目标就像你说的那样;使徽标的两个标题的全高。第二个标题的对齐方式是右对齐并且正在工作。