Bootstrap 轮播中的 Href [英] Href in Bootstrap Carousel

查看:30
本文介绍了Bootstrap 轮播中的 Href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是我的代码?

<div id="my-slider" class="carousel slide" data-ride="carousel"><!-- 指标点 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><!-- 幻灯片包装器--><div class="carousel-inner" role="listbox"><div class="item active"><img src="img/Internet.jpg" alt="Internet 服务"/><div class="carousel-caption"><h1 href="/Internet">Truespeed Internet 服务</h1>

<div class="item"><img src="img/HomePhone.jpg" alt="Truespeed Internet Services"/><div class="carousel-caption"><h1>电话</h1>

<!-- 控件或下一个和上一个按钮 --><a class="left carousel-control" href="#my-slider" role="button" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span><span class="sr-only">上一个</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">下一步</span></a>

解决方案

只需使用 href 属性将所需的链接添加到 img.检查下面的更新代码

<div id="my-slider" class="carousel slide" data-ride="carousel"><!-- 指标点 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><!-- 幻灯片包装器--><div class="carousel-inner" role="listbox"><div class="item active"><img src="img/Internet.jpg" href="http://google.com" alt="Internet 服务"/><div class="carousel-caption"><h1 href="/Internet">Truespeed Internet 服务</h1>

<div class="item"><img src="img/HomePhone.jpg" href="http://google.com" alt="Truespeed Internet Services"/><div class="carousel-caption"><h1>电话</h1>

<!-- 控件或下一个和上一个按钮 --><a class="left carousel-control" href="#my-slider" role="button" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span><span class="sr-only">上一个</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">下一步</span></a>

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>

解决方案

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>

这篇关于Bootstrap 轮播中的 Href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆