Thomas Hutton Thomas Hutton - 7 months ago 24
HTML Question

Href in Bootstrap Carousel

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.

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>

Answer

Just add the desired link to the img using href attribute. Check updated code below

<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>