简体   繁体   English

高度继承和垂直对齐(内联块)

[英]Height inheritance and vertical alignment ( inline-block )

I have the hardest time getting how those thing work and I'd love it if someone could explain it to me. 我最难得到这些东西的工作方式,如果有人可以向我解释,我将非常乐意。

1 http://d.pr/i/6TgE+ 1个http://d.pr/i/6TgE+

why http://d.pr/i/UAZn+ 为什么http://d.pr/i/UAZn+

*it's actually 9. *实际上是9。

I have this code: 我有以下代码:

<header>
    <div class="container">
        <div class="grid">      
            <div class="grid__item one-half">
                <a href="index.html"  class="logo-site">
                    <img src="http://aurelieremia.be/img/logo-aurelie.svg" alt="logo-ar">
                </a>
            </div><!--

         --><div class="grid__item one-half">
                <nav>
                    <ul class="nav main-nav">
                        <li>
                            <a href="#" class='active'>work</a>
                            <a href="#">about</a>
                            <a href="#">process</a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</header>

and this CSS : 和这个CSS:

.container {
  max-width: 1140px;
  height: 40px;
  margin: 0 auto; }

header {
  background: #4f4348;
  height: 40px;
  position: relative; }

.logo-site {
  height: 82%;
  background: #938b88;
  display: inline-block; }
  .logo-site img {
    height: 28px;
    vertical-align: middle;
    display: inline-block;
    line-height: 40px; }

.main-nav a {
  font-size: 14px;
  text-transform: uppercase;
  color: #f5f3e2;
  line-height: 40px;
  margin-right: 10px;
  font-family: "Brandon Grotesque Medium"; }
  .main-nav a.active, .main-nav a:hover {
    background: #f5f3e2;
    color: #4f4348; }

in case you're not familiar with inuit.css, here's the code that I used from this framework: 如果您不熟悉inuit.css,这是我在此框架中使用的代码:

.grid{
    margin-left:-$base-spacing-unit;
    list-style:none;
    margin-bottom:0;
}
    .grid__item{
        display:inline-block;
        width:100%;
        padding-left:$base-spacing-unit;
        vertical-align:top;
        @if $global-border-box == false{
            @include vendor(box-sizing, border-box);
        }
one-half          { width:50%; }

My first grid__item doesn't take up 100% of the height from their parent, the grid and container. 我的第一个grid__item不会占据其父级,网格和容器的高度的100%。 I tried with height, and a bunch of things, doesn't work. 我尝试了高度,但是一堆东西不起作用。 Only way I found to make it work was to make my logo larger. 我发现使它起作用的唯一方法是使徽标变大。

The second grid__item works, but it's because I applied a line-height with the value of the header on it to center it. 第二个grid__item起作用了,但这是因为我在其上应用了带有标题值的行高来使其居中。 However, I want to add border for the active state (5px from the text), so it doesn't help that the links take up all the height. 但是,我想为活动状态添加边框(距离文本5px),因此链接占据所有高度无济于事。 But the problem would be to center it. 但是问题是要居中。

What I'd like: 我想要的是:

dream http://d.pr/i/6Ggm+ 梦想http://d.pr/i/6Ggm+

Link to fiddle 链接到小提琴

Please. 请。 Help. 救命。

remove { height: XXpx;} from 从中删除{height:XXpx;}

header {} 

and from 和从

.container{}

http://jsfiddle.net/a9wnG/6/ http://jsfiddle.net/a9wnG/6/

now the nav is also vertically centered and the active state has border-top and -bottom http://jsfiddle.net/a9wnG/11/ 现在,导航栏也垂直居中,活动状态为border-top和-bottom http://jsfiddle.net/a9wnG/11/

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

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