2017-08-23 119 views
1

我使用引導程序4和codeigniter,由於某些原因bootstrap carousal寬度不起作用。實際上圖像是1140像素寬度Bootstrap 4 carousal沒有使圖像全寬

問題如何獲取bootstrap carousal中的圖像以顯示其全寬和高度?我一起使用codeigniter和bootstrap。

如圖圖像的圖像不充分寬度低於轉盤

enter image description here

<div id="carouselExampleIndicators<?php echo $module; ?>" class="carousel slide" data-ride="carousel"> 

    <ol class="carousel-indicators"> 
    <?php foreach ($banners as $i => $banner) { ?> 
     <li data-target="#carouselExampleIndicators<?php echo $module; ?>" data-slide-to="<?php echo $i; ?>"<?php echo !$i ? ' class="active"' : ''; ?>></li> 
    <?php } ?> 

    </ol> 

    <div class="carousel-inner"> 

    <?php foreach ($banners as $i => $banner) { ?> 
     <div class="carousel-item <?php echo !$i ? ' active' : ''; ?>"> 
      <img class="w-100" src="<?php echo $banner['image']; ?>" alt=""> 
     </div> 
    <?php } ?> 

    </div> 

    <?php if (count($banners) > 1) { ?> 
    <a class="carousel-control-prev" href="#carouselExampleIndicators<?php echo $module; ?>" role="button" data-slide="prev"> 
     <span class="carousel-control-prev-icon" aria-hidden="true"></span> 
     <span class="sr-only">Previous</span> 
    </a> 

    <a class="carousel-control-next" href="#carouselExampleIndicators<?php echo $module; ?>" role="button" data-slide="next"> 
     <span class="carousel-control-next-icon" aria-hidden="true"></span> 
     <span class="sr-only">Next</span> 
    </a> 
    <?php } ?> 

</div> 

控制器

<?php 

class Slideshow extends MX_Controller { 

    public function index($setting = array()) { 

     static $module = 0; 

     $this->load->model('catalog/tool/image_model'); 

     $data['width'] = $setting['width']; 
     $data['height'] = $setting['height']; 

     $results = $this->getBanner($setting['banner_id']); 

     $data['banners'] = array(); 

     foreach ($results as $result) { 
      $data['banners'][] = array(
       'image' => $this->image_model->resize($result['image'], $setting['width'], $setting['height']) 
      ); 
     } 

     $data['module'] = $module++; 

     if (file_exists(config_item('catalog_template_path') . $this->site->get('config_theme') . '/template/module/slideshow_view.php')) { 
      $this->load->view($this->site->get('config_theme') .'/template/module/slideshow_view', $data); 
     } else { 
      $this->load->view('default/template/module/slideshow_view', $data); 
     } 
    } 

    public function getBanner($banner_id) { 
     $this->db->select('*'); 
     $this->db->from($this->db->dbprefix . 'banner'); 
     $this->db->join($this->db->dbprefix . 'banner_image', 'banner_image.banner_id = banner.banner_id', 'LEFT'); 
     $this->db->where('banner_image.banner_id', $banner_id); 
     $query = $this->db->get(); 

     return $query->result_array(); 
    } 
} 
+0

看來這班'類= 「W-100」'專門設置的小圖像? – Tpojka

回答

1

設置寬度= 100%爲您w-100

.w-100 { 
    width: 100%; 
} 

OR

添加style="width: 100%"到您的img標籤

<img class="w-100" src="<?php echo $banner['image']; ?>" alt="" style="width: 100%">