2017-05-30 56 views
0

在文档这里提到我使用ngb-carousel图像的边缘:https://ng-bootstrap.github.io/#/components/carousel使传送带一样的图像的高度的高度,而忽略

代码:

在app.ts:

<div class="col-md-4"> 
    <ngbd-carousel-basic></ngbd-carousel-basic> 
</div> 

在转盘-basic.html:

<ngb-carousel> 
    <ng-template ngbSlide> 
    <img src="https://lorempixel.com/900/500?r=1" alt="Random first slide"> 
    <div class="carousel-caption"> 
     <h3>First slide label</h3> 
     <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p> 
    </div> 
    </ng-template> 
    <ng-template ngbSlide> 
    <img src="https://lorempixel.com/900/500?r=2" alt="Random second slide"> 
    <div class="carousel-caption"> 
     <h3>Second slide label</h3> 
     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> 
    </div> 
    </ng-template> 
    <ng-template ngbSlide> 
    <img src="https://lorempixel.com/900/500?r=3" alt="Random third slide"> 
    <div class="carousel-caption"> 
     <h3>Third slide label</h3> 
     <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p> 
    </div> 
    </ng-template> 
</ngb-carousel> 

在旋转木马basic.css:

img { 
    margin: auto; 
    height: auto; 
    width: 100%; 
} 

ngb-carousel { 
    background-color: black; 
} 

输出:

enter image description here

普拉克:

http://plnkr.co/edit/aph3NqBCEuVGsxkWbco4?p=preview

我想使传送带的高度与图像的高度相同,忽略图像使用的边距。

因此,简而言之,上图中显示的黑色部分不应出现,标题和指示器也应在图像上移动。

+0

@TeutaKoraqi的这个例子,我不想要100%的身高。我想保持高度和宽度之间的宽高比。 – Vishal

回答

1

它可能有点复杂,如果不想删除保证金:汽车,也没有要修复的height.Better看到

bootstrap carousel example

+0

你正在解释我有点不对。我对保证金不感兴趣。但我不想固定图像的高度。我希望该图像应保持其宽度和高度之间的纵横比。虽然我只会看看你提供的例子。 – Vishal

+0

这个答案有你的解决方案,但对于容器项目img,他们没有使用保证金。 –

+0

这适用于我的情况。感谢您的时间和精力。 – Vishal

0

如果你可以改变CSS,然后更新下面的CSS部分。

img[_ngcontent-c0] { 
    /* margin: auto; */ 
    height: 300px; /* You can change as you need */ 
    /* width: 100%; */ 
    object-fit: cover; 
    -webkit-object-fit: cover; 
} 
+0

我不想指定高度,因为我想保持原始图像的宽高比。有没有其他方法可以做到这一点? – Vishal

+0

如果你不需要它,你可以删除或提供汽车.. – LKG

0

给高度carousel-item,它应该等于您的图像高度。它会正常工作

+0

我怎样才能做到这一点使用CSS?因为图像的高度设置为自动。 – Vishal

+0

或给你的图片高度:100%。 – vijayscode

+0

我不想要100%身高。我想保持高度和宽度之间的宽高比。 – Vishal