【问题标题】:Getting CSS classes to fill up the rest of the remaining width in %. (Pug/Jade) [duplicate]让 CSS 类以 % 的形式填充剩余的宽度。 (哈巴狗/翡翠)[重复]
【发布时间】:2019-05-16 13:55:20
【问题描述】:

所以我遇到了一些问题,即我的 div 没有正确对齐,这需要非常合适。我使用 pug 作为模板。

帕格:

  body
    .container
      .header
        include game_components/header.pug
      .game-row
        include game_components/game-row.pug
      .footer
        include game_components/footer.pug

标题:

doctype html
html(lang="en")
  .logo
    span PLH
  .user-info
    span PLH

游戏行:

doctype html
html(lang="en")
  .side-bar
    span PLH
  .action-scene
    span PLH

页脚:

doctype html
html(lang="en")
  .chat
    span Chat PLH

CSS:

* {
   background-color: grey;
   border-radius: 10px;
}
.container {
    width: 80%;
    margin: 1px;
    margin: auto;
}

.header, .game-row, .footer {
    display: block;
}

.logo, .user-info, .side-bar, .action-scene, .chat {
    display: inline-block;
    vertical-align: top;
    padding: 10px;
    margin: 0.2em;
    border:  1px solid gold;
}

.logo, .user-info {
    height: 5em;
}

.logo, .side-bar {
    width:  10%;
}

.user-info, .action-scene {
    width:  85.45%;
}

.side-bar, .action-scene {
    height: 20em;
}

.chat {
    width: 100%;
    height: 15em;
}

它目前的样子图片:http://prntscr.com/lvblcb(LightShot 链接)

如果您看一下,您会发现聊天非常适合,因为它应该。但是我在前两行很合适时遇到了麻烦。

【问题讨论】:

  • 鉴于 logo/sidebaruser/action 总宽度 (10 + 85.45) 为 95.45%,而 chat 为 100%,当然它们不匹配。
  • 如果我让它等于 100% 则换行
  • - 在旁注中,我通过使所有内容都按百分比工作并具有负边距和填充值来修复它。 (5分钟编辑规则是蹩脚的)
  • 这是由于 display:inline-block;在下面查看我的解决方案
  • 查找flexbox。解决各种对齐问题可能对您有用。一旦你知道它,你就不能没有它。

标签: css pug


【解决方案1】:

您遇到的问题是由于 display:inline-block, 我有多个相同的解决方案。 您可以尝试以下任何一种: 1. 尽管 display:inline-block 使用 float:left 并给他们 90% 和 10% 这样的宽度,这将解决,是的,他们的父母不要忘记隐藏溢出。

  1. 如果你想使用 display: inline-block;然后给它的父 font-size: 0;和内部跨度字体大小任意,然后为它们提供适当的宽度:

使用这个,如果您觉得有任何问题,请告诉我/

【讨论】:

  • 好的,我已经这样做了,但似乎并没有真正解决问题。 IT 让它变得更好,但仍未修复。
猜你喜欢
  • 2018-02-18
  • 2013-09-28
  • 1970-01-01
  • 2018-05-26
  • 2016-05-22
  • 2019-01-07
  • 2011-12-20
  • 1970-01-01
相关资源
最近更新 更多