简体   繁体   English

如何获取jQuery的标题文本以使其与图像对齐?

[英]How do I get the caption text of the jQuery to align with the image?

I'm having a problem with carousel . 我对传送带有问题。 I would like to make the caption the same width as the image but just now it is set to the same width as the inner item class. 我想使标题与图像具有相同的宽度,但现在将其设置为与内部项类相同的宽度。

I get the following effect: 我得到以下效果:

在此处输入图片说明

Is there a way to set the caption so it is centred (and aligned with the image)? 有没有一种方法可以将标题设置为居中(并与图像对齐)?

My markup is: 我的标记是:

<div id="myCarousel" class="carousel slide">
  <!-- Carousel items -->
  <div class="carousel-inner">
    <div class="active item">
      <div class="inner-item">
        <img src="img/1.jpg">
      </div>
      <div class="carousel-caption">
        <p>Caption</p>
      </div>
    </div>
    <div class="item">
      <div class="inner-item">
        <img src="img/1.jpg">
      </div>
       <div class="carousel-caption">
        <p>Caption text here</p>
      </div>
    </div>
    <div class="item">
      <div class="inner-item">
        <img src="img/1.jpg">
      </div>
       <div class="carousel-caption">
        <p>Caption text here</p>
      </div>
    </div>
  </div>
  <!-- Carousel nav -->
  <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
  <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
</div>

If I understand your question correctly Why you don't use text-align:center; 如果我正确理解您的问题,为什么不使用text-align:center; for the caption and change the width to the image's width 用于标题,并将宽度更改为图像的宽度

.carousel-caption
{
    text-align:center;
    width:800px; 
    /*If you are having aligning problems and the position is absolute or relative use left:some_number px or margin if not absolute */ 

}

I hope this can help :) 我希望这可以帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM