<a> inside of a </a> <标题> <a> won&#39;t move to the bottom

时间:2018-10-03 05:05:09

标签: css

I have my code here in css for the a inside the header:

header {
    display: block;
    background-color: black;
    color: white;
    width: 100%;
    height: 150px;
    position: relative;
    min-width:200px;
}

header img {
    float: left;
 }

header a {
    color: white;
    font-family: 'Roboto Slab', sans-serif;
    font-weight: 100;
    font-size: 200%;
    text-decoration: none;
    float: left;
}

<header>

  <div class="header-image-container">
    <img src="benny.jpg" alt="Benny logo">
  </div>

  <h1 class="site-title"><a href="#">Benny's List</a></h1>

</header>

I just want the a that is inside the header to be down towards the bottom of the header but no matter if I put margin or padding, it won't move at all. Thank you guys for any help!

Screenshot: https://imgur.com/a/YbwDAML

4 个答案:

答案 0 :(得分:0)

您可能只需要为超链接添加clear

header {
  display: block;
  background-color: black;
  color: white;
  width: 100%;
  height: 150px;
  position: relative;
  min-width: 200px;
}

header img {
  float: left;
}

header a {
  color: white;
  font-family: 'Roboto Slab', sans-serif;
  font-weight: 100;
  font-size: 200%;
  text-decoration: none;
  float: left;
  clear: both; /* Added */
}
<header>
  <img src="https://via.placeholder.com/100x100">
  <a href="#">Link</a>
</header>

答案 1 :(得分:0)

当您不需要浮点数时,不需要使用浮点数,而无需使用float: left来查看下面的工作代码段,希望对您有所帮助:)

header {
  display: block;
  background-color: black;
  color: white;
  width: 100%;
  height: 150px;
  position: relative;
  min-width: 200px;
}

header img {
  /* float: left; */ /* removed */
  display: block; /* Added */
}

header a {
  color: white;
  font-family: 'Roboto Slab', sans-serif;
  font-weight: 100;
  font-size: 200%;
  text-decoration: none;
  /* float: left; */ /* removed */
}
<header>
  <img src="http://placekitten.com/g/80/80">
  <a href="#">Link</a>
</header>

答案 2 :(得分:0)

header {
  background-color: #000000;
  color: #ffffff;
  width: 100%;
  height: 150px;
  position: relative;
  min-width: 200px;
}
header img {
  width: 100px;
  height: 100px;
   display: block; 
}
header a {
  color: #ffffff;
  font-family: 'Roboto Slab', sans-serif;
  font-weight: 100;
  font-size: 200%;
  text-decoration: none;
}
<header>
  <img src="https://image.ibb.co/nsrpRz/111.jpg">
  <a href="#">Link</a>
</header>

答案 3 :(得分:0)

根据您的要求,仅将img的margin-top设为负值即可。 它会工作。以下是CSS代码:

header img {
   float: left;
   margin-top: -10px;
}

只需根据您的要求调整margin-top的值。