如何在不增加标题的实际高度的情况下增加标题中的徽标高度?

时间:2019-06-24 11:57:14

标签: html css

所以我有一个标题,在标题的右侧有一些菜单链接,在标题的左侧有一个徽标。

因此,目前徽标的尺寸很小,但是只要我更改徽标的高度以满足我的需要,它也会增加实际标题的高度。

但是,我只希望徽标的高度增加而不是实际标题的高度。

我还搜索了有关堆栈溢出和Google的其他问题,该问题与我的相似,但仍然存在一些问题。请帮助我。

这是我的标头代码:

<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8">
        <title>Home - Diamond Collections</title>
        <style>



            @import url('https://fonts.googleapis.com/css?family=Work+Sans:300,600');

:root {
  --background: rgba(0, 214, 170, .85);
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
    margin: 0;
    background: 
    font-family: 'Work Sans', sans-serif;
    font-weight: 400;
}

.content {

}

/* navigation styles start here */

header {
  background: var(--background);
  text-align: center;
  position: fixed;
  z-index: 999;
  width: 100%;
}

/* changed this from the tutorial video to
   allow it to gain focus, making it tabbable */
.nav-toggle {
  position: absolute !important;
  top: -9999px !important;
  left: -9999px !important;
}

.nav-toggle:focus ~ .nav-toggle-label {
  outline: 3px solid rgba(lightblue, .75);
}

.nav-toggle-label {
  position: absolute;
  top: 0;
  left: 0;
  margin-left: 1em;
  height: 100%;
  display: flex;
  align-items: center;
}

.nav-toggle-label span,
.nav-toggle-label span::before,
.nav-toggle-label span::after {
  display: block;
  background: white;
  height: 2px;
  width: 2em;
  border-radius: 2px;
  position: relative;
}

.nav-toggle-label span::before,
.nav-toggle-label span::after {
  content: '';
  position: absolute;
}

.nav-toggle-label span::before {
  bottom: 7px;
}

.nav-toggle-label span::after {
  top: 7px;
}

nav {
  position: absolute;
  text-align: left;
  top: 100%;
  left: 0;
  background: var(--background);
  width: 100%;
  transform: scale(1, 0);
  transform-origin: top;
  transition: transform 400ms ease-in-out;
}

nav ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

nav li {
  margin-bottom: 1em;
  margin-left: 1em;
}

nav a {
  color: white;
  text-decoration: none;
  font-size: 1.2rem;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 150ms ease-in-out;
}

nav a:hover {
  color: #000;
}

.nav-toggle:checked ~ nav {
  transform: scale(1,1);
}

.nav-toggle:checked ~ nav a {
  opacity: 1;
  transition: opacity 250ms ease-in-out 250ms;
}

@media screen and (min-width: 800px) {
  .nav-toggle-label {
    display: none;
  }

  header {
    display: grid;
    grid-template-columns: 1fr auto minmax(600px, 3fr) 1fr;
  }

  .logo {
    grid-column: 2 / 3;
  }

  nav {
    // all: unset; /* this causes issues with Edge, since it's unsupported */

    position: relative;
    text-align: left;
    transition: none;
    transform: scale(1,1);
    background: none;
    top: initial;
    left: initial;
    /* end Edge support stuff */

    grid-column: 3 / 4;
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }

  nav ul {
    display: flex;
  }

  nav li {
    margin-left: 3em;
    margin-bottom: 0;
  }

  nav a {
    opacity: 1;
    position: relative;
  }

  nav a::before {
    content: '';
    display: block;
    height: 5px;
    background: black;
    position: absolute;
    top: 1.75em;
    left: 0;
    right: 0;
    transform: scale(0, 1);
    transition: transform ease-in-out 250ms;
  }

  nav a:hover::before {
    transform: scale(1,1);
  }
}


        </style>
    </head>
    <body>
        <header>
  <h1 class="logo"><a href="#" style="text-decoration: none; color: black"><img src="Images/Logo5.JPG"></a></h1>
  <input type="checkbox" id="nav-toggle" class="nav-toggle">
  <nav>
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">About</a></li>
      <li><a href="#">Blog</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
  </nav>
  <label for="nav-toggle" class="nav-toggle-label">
    <span></span>
  </label>
</header>

3 个答案:

答案 0 :(得分:0)

.logo {
    grid-column: 2 / 3;
    transform: scale(2);
}

更新您的logo类。

答案 1 :(得分:0)

阅读devtools-这将帮助您轻松解决此类问题。 随着子元素的增长,父元素也必须不断增加才能容纳子元素。

您以前的徽标文本在所包含的h1标签上也具有顶部和底部边距。删除h1上的一些顶部和底部边距将有助于您增加徽标

答案 2 :(得分:0)

这里是您回答jsfiddle的关键词

我添加了虚拟图像..因为您的相对路径图像未按此处打开...在代码中添加了以下代码

h1 {
     margin:0
}

.logo a {
     display: flex;
     justify-content: center;
}

.logo img {
    height: 45px;
}