【问题标题】:How to put label under image in navigation bar?如何在导航栏中的图像下放置标签?
【发布时间】:2019-12-03 10:34:41
【问题描述】:

我的网站每个页面都有一个底部导航栏和 4 张图片。我现在想在图片下放置文字,但我不知道该怎么做。

我已经使用 span、div... 并且没有任何效果。

    .footer {
  position: absolute;
  bottom: 0;
  width: 100%;
  white-space: nowrap;
  /* Set the fixed height of the footer here */
  height: 60px;
  line-height: 60px; /* Vertically center the text there */
}

#footernavbar {
    background-color: #282064;
    height: 60px;
    width: 100%;
    bottom: 0;
    position: fixed;
    float: left;
}

.imagefooternav{
    object-fit:scale-down;
}

.icon{
    position:relative;
    width:100%;
    height:60px;
}

.icon img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
<footer class="border-top footer text-muted">

  <div id="footernavbar">
    <div class="row">

      <div class="col-xl-4"></div>
      <a class=" col-md-3 col-sm-3 col-3 col-xl-1" asp-controller="Home" asp-action="Index">
        <div class="icon">

          <img src="~/images/homepage.png" />

        </div>
      </a>
      <a class=" col-md-3 col-sm-3 col-3 col-xl-1" asp-controller="Tour" asp-action="Index">
        <div class="icon">

          <img src="~/images/calendar.png" />

        </div>
      </a>
      <a class=" col-md-3 col-sm-3 col-3 col-xl-1" href="/BuildingSite/CreateToday/">
        <div class="icon">

          <img src="~/images/pen.png" />

        </div>
      </a>
      <a class="col-md-3 col-sm-3 col-3 col-xl-1" href="/User">
        <div class="icon">
          <span>
                            <img src="~/images/user.png" />
                        </span>
          <span>
                            test
                        </span>

        </div>
      </a>
      <div class="col-xl-4"></div>
    </div>
  </div>
</footer>

目前我知道了:https://i.imgur.com/YSah00h.png

我想要的是:https://i.imgur.com/Ir5UTjf.png

(对于每张图片,例如我只为最后一张图片做)

【问题讨论】:

  • 您没有发布所有影响这一点的 CSS。 sn-p 视图和您的图像看起来不同。
  • 是的,我添加了代码很好

标签: html css asp.net-mvc web asp.net-core


【解决方案1】:

试试这个例子,我在你的 CSS 代码中添加了 profileName

https://jsfiddle.net/becher_henchiri/s9h8of1r/3/

【讨论】:

  • 好的,它可以工作,但我必须编辑它,因为你的 jsfiddle 和我的代码中的间距不一样。不过很好,谢谢你的帮助!!
【解决方案2】:

HTML: 刚刚创建了一行,其中包含您需要的图像和文本,它们都在 12 列中,它应该可以工作。

<footer class="border-top footer text-muted">

  <div id="footernavbar">
    <div class="row">

      <div class="col-xl-4"></div>
      <a class=" col-md-3 col-sm-3 col-3 col-xl-1 m-2" asp-controller="Home" asp-action="Index">
        <div class="icon">

          <img src="https://cdn2.iconfinder.com/data/icons/blue-round-amazing-icons-1/512/home-alt-512.png" />

        </div>
      </a>
      <a class=" col-md-3 col-sm-3 col-3 col-xl-1 m-2" asp-controller="Tour" asp-action="Index">
        <div class="icon">

          <img src="https://cdn2.iconfinder.com/data/icons/blue-round-amazing-icons-1/512/home-alt-512.png" />

        </div>
      </a>
      <a class=" col-md-3 col-sm-3 col-3 col-xl-1 m-2" href="/BuildingSite/CreateToday/">
        <div class="icon">

          <img src="https://cdn2.iconfinder.com/data/icons/blue-round-amazing-icons-1/512/home-alt-512.png" />

        </div>
      </a>
      <a class="col-md-3 col-sm-3 col-3 col-xl-1 m-2" href="/User">
        <div class="icon row">
          <span class="col-12 text-center">
           <img src="https://cdn2.iconfinder.com/data/icons/blue-round-amazing-icons-1/512/home-alt-512.png" />
          </span>
          <span class="col-12 text-center">
            test
          </span>

        </div>
      </a>
      <div class="col-xl-4"></div>
    </div>
  </div>
</footer>

css:

    .footer {
  position: absolute;
  bottom:0;
  width: 100%;
  white-space: nowrap;
  /* Set the fixed height of the footer here */
  height: 60px;
}

#footernavbar {
    background-color: #282064;
    height: 60px;
    width: 100%;
    bottom: 0;
    position: fixed;
    float: left;
}

.imagefooternav{
    object-fit:scale-down;
}

.icon{
    position:relative;
    width:100%;
    height:60px;
}

.icon img {
/*     position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); */
    width: 30px;
}

【讨论】:

  • 谢谢,也可以工作,但“测试”有点偏离页面。但是感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 2019-05-26
  • 2023-03-07
  • 2018-02-07
  • 2017-10-14
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 1970-01-01
相关资源
最近更新 更多