简体   繁体   English

如何使内联块继承高度?

[英]How to make inline-block inherit height?

how can I make article title p element have the same height as the snippet div? 如何使文章标题p元素的高度与摘要div相同? Both p and div are inline-block elements. p和div都是内联块元素。

I tried height: inherit for p , but it doesn't work because li doesn't have explicit height values. 我尝试了height: inheritp height: inherit ,但是因为li没有明确的高度值,所以它不起作用。 Any idea?? 任何想法??

Wiki p标签高度

const dataRow = dataArray.map(row => {
  return (
    <li key={row.title}>
      <p className="title col-md-2">{row.title}</p>
      <div className="content__div col-md-10">
        <a href={row.link} className="content">{row.content}</a>
      </div>
    </li>
  );
});


ul {
  li {
    list-style-type: none;
  }

  .title {
    display: inline-block;
    background: $title-bg;
    color: $content-bg;
    height: inherit;
    margin: 0;
    text-align: right;
    vertical-align: middle;
  }

  .content__div {
    display: inline-block;
    margin: 1px 0 1px 0;
    padding: 0;
  }

  .content {
    display: inline-block;
    background: $content-bg;
    color: $title-bg;
    text-decoration: none;
    padding: 10px 15px 10px 15px;
  }
}

Add this to ur stylesheet 将此添加到您的样式表

li {
 display:flex
}

Display flex on the parent li will automatically stretch(match) its children height to the tallest element 父级li上的display flex将自动将其子级高度拉伸(匹配)到最高元素

You can use flex on the li element to make the p fill the height. 您可以在li元素上使用flex以使p填充高度。

li {
 display: flex;
}

There is will be a size difference visually since you have a margin around the div. 由于div周围有边距,因此视觉上会有大小差异。 Remove that will flush the p and div elements. 删除将刷新p和div元素。

.content__div {
 ...
  margin: 0px;
 ...
}

Looks like you may be using bootstrap as a grid. 看起来您可能正在使用引导程序作为网格。 Mixing the inline block and flex will probably not fill the row as you might expect. 混合使用内联代码块和flex可能不会按预期填充行。 If you don.t want to change the structure you can get away with adding flex: 1 to the div. 如果您不想更改结构,则可以在div中添加flex:1。

.content__div {
 ...
  flex: 1;
 ...
}

examples: https://plnkr.co/edit/x9DdxX?p=preview 示例: https//plnkr.co/edit/x9DdxX?p = preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM