twitter-bootstrap Bootstrap Carousel 中的 Href

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37030566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 23:53:32  来源:igfitidea点击:

Href in Bootstrap Carousel

htmlcsstwitter-bootstrap

提问by Thomas Hutton

I've been scouring the Interwebz, and I can't seem to find the answer. How to I add href within my carousel links? I tried to put the a tag outside of my h1 tag, but it destroys the functionality of the slider itself.

我一直在搜索 Interwebz,但似乎找不到答案。如何在我的轮播链接中添加 href?我试图将 a 标签放在我的 h1 标签之外,但它破坏了滑块本身的功能。

Here's my code?

这是我的代码?

<div class="col-sm-12">
  <div id="my-slider" class="carousel slide" data-ride="carousel">
    <!-- indicators dot nov -->
    <ol class="carousel-indicators">
      <li data-target="#my-slider" data-slide-to="0" class="active"></li>
      <li data-target="#my-slider" data-slide-to="1"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
      <div class="item active">
          <img src="img/Internet.jpg"  alt="Internet Services" />
          <div class="carousel-caption">
            <h1 href="/Internet">Truespeed Internet Services</h1>
          </div>
      </div>
    <div class="item">
        <img src="img/HomePhone.jpg" alt="Truespeed Internet Services" />
        <div class="carousel-caption">
          <h1>Phone</h1>
        </div>
    </div>
    </div>
    <!-- Controls or next and prev buttons -->
    <a class="left carousel-control" href="#my-slider" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#my-slider" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right"></span>
      <span class="sr-only">Next</span>
    </a>

  </div>
</div>

采纳答案by Pugazh

Just add the desired link to the imgusing hrefattribute. Check updated code below

只需将所需的链接添加到imgusinghref属性即可。检查下面的更新代码

<div class="col-sm-12">
  <div id="my-slider" class="carousel slide" data-ride="carousel">
    <!-- indicators dot nov -->
    <ol class="carousel-indicators">
      <li data-target="#my-slider" data-slide-to="0" class="active"></li>
      <li data-target="#my-slider" data-slide-to="1"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
      <div class="item active">
        <img src="img/Internet.jpg" href="http://google.com" alt="Internet Services" />
        <div class="carousel-caption">
          <h1 href="/Internet">Truespeed Internet Services</h1>
        </div>
      </div>
      <div class="item">
        <img src="img/HomePhone.jpg" href="http://google.com" alt="Truespeed Internet Services" />
        <div class="carousel-caption">
          <h1>Phone</h1>
        </div>
      </div>
    </div>
    <!-- Controls or next and prev buttons -->
    <a class="left carousel-control" href="#my-slider" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#my-slider" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right"></span>
      <span class="sr-only">Next</span>
    </a>

  </div>
</div>

回答by Rachel S

http://www.bootply.com/nZjger87Zc#

http://www.bootply.com/nZjger87Zc#

You can add the atags just outside the H1tags.

您可以在a标签外添加H1标签。