I am trying to add a dynamic background-image to a carousel div in my blade template using a for each loop but the image doesn't appear.
this is my div
div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active" style="background-image: url('{{ asset('main/img/hero/hero-1.jpg')}}')">
<div class="info">
<h2 class="text-capitalize text-white">best price & offer</h2>
<h1 class="text-uppercase py-2 fw-bold text-white">new season</h1>
<a href="{{route('shop.index')}}" class="btn" >buy now</a>
</div>
</div>
#if ($heros -> count())
#foreach ($heros as $hero)
<div class="text-center carousel-item carousel vh-100 vw-100 dynamic" style="background-image: url('{{ asset('upload/hero/'.$hero->image)}}')">
<div class="info">
<h2 class="text-capitalize text-white">best price & offer</h2>
<h1 class="text-uppercase py-2 fw-bold text-white">new season</h1>
<a href="{{route('shop.index')}}" class="btn" >buy now</a>
</div>
</div>
#endforeach
#endif
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" 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" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
However, I see the correct file path in the styles tab when i inspect the page.
Please what am I doing wrong?
I have tried other altenatives like using
style="background-image: url('{{ url('upload/hero/'.$hero->image)}}')"
instead of
style="background-image: url('{{ asset('upload/hero/'.$hero->image)}}')"
but the result is the same.
I even tried adding the background-image to the dynamic class in my css like this
<style>
.dynamic{
background-image: url('{{ asset('upload/hero/' . $hero->image) }}') !important;
}
this also did not work.
Please I need all the help I can get
Related
I have a dynamic slider with botstrap in asp.net MVC; But I can not move it in touch.I use some sample jQuery Code for enable touch but it's important to me chose first pic of Slider automatically!
this is my HTML Code For dynamic Slider.
#model IEnumerable<MyProject.Models.DataSource.Sliders>
#if (Model.Any())
{
<section class="banner parallax-fix parallaximg">
<div class="container-fluid pr">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0"
class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
#foreach (var item in Model)
{
if (item.IsFirst == true)
{
<div class="item active">
<a onclick="SliderCounter(#item.SliderID)"
href="#item.SliderLink"
target="_blank">
<img src="~/images/Slider/#item.SliderImage"
alt="#item.SliderTitle"
style="width:100%;">
</a>
</div>
}
else
{
<div class="carousel-item item">
<a onclick="SliderCounter(#item.SliderID)"
href="#item.SliderLink"
target="_blank">
<img src="~/images/Slider/#item.SliderImage"
alt="#item.SliderTitle"
style="width:100%;">
</a>
</div>
}
}
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-
slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-
slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</section>
}
if you have another way for touchable and dynamic slider please help me!
I have a twitter Bootstrap carousel that I am trying to use within wordpress and it is stacking all the pictures on top of each other and doesn't rotate.
You can view it and see what I mean here.
My code looks like this:
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="http://i0.wp.com/www.cattywampur.com/wp-content/uploads/2016/03/8566819595_0f567e8594_k.jpg" >
<div class="carousel-caption">
<h3>Traversing the Grand Canyon</h3>
</div>
</div>
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="http://i2.wp.com/www.cattywampur.com/wp-content/uploads/2016/05/26300985983_713ab03dc1_k.jpg" >
<div class="carousel-caption">
<h3>San Jacinto - Deer Springs Trail</h3>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
You only need one carousel-inner.
And one item set to active.
That way they don't stack and have the same wrapper.
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="http://i0.wp.com/www.cattywampur.com/wp-content/uploads/2016/03/8566819595_0f567e8594_k.jpg">
<div class="carousel-caption">
<h3>Traversing the Grand Canyon</h3>
</div>
</div>
<div class="item">
<img src="http://i2.wp.com/www.cattywampur.com/wp-content/uploads/2016/05/26300985983_713ab03dc1_k.jpg">
<div class="carousel-caption">
<h3>San Jacinto - Deer Springs Trail</h3>
</div>
</div>
</div>
LINK TO WEBSITE TEST PAGE:
WEBPAGE LINK
I'm trying to have a carousel with no background. So the images and indicators are just displayed as is.
Have tried this:
.carousel{
background:none;
background-color: none;
}
Which didn't make a difference, I also tried adding a placeholder as a background to see what it did:
.carousel{
background: url(http://placehold.it/620x420/);
}
This added the placeholder background but behind the shading of the carousel. I've uploaded an image here:
Hopefully someone knows what I've done wrong, thanks in advance.
EDIT: Added HTML code for carousel:
<!-- Image Gallery Start-->
<br/><br/>
<div id="Carousel" class="carousel slide" data-ride="carousel" style="max-width: 400px; margin: 0 auto">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#suniceCarousel" data-slide-to="0" class="active"></li>
<li data-target="#suniceCarousel" data-slide-to="1"></li>
<li data-target="#suniceCarousel" data-slide-to="2"></li>
<li data-target="#suniceCarousel" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img class="img-responsive center-block" src="/images/sunice/sunice1.png" width="350" alt="Chania">
</div>
<div class="item">
<img class="img-responsive center-block" src="/images/sunice/sunice2.png" width="350" alt="Chania">
</div>
<div class="item">
<img class="img-responsive center-block" src="/images/sunice/sunice1.png" width="350" alt="Chania">
</div>
<div class="item">
<img class="img-responsive center-block" src="/images/sunice/sunice2.png" width="350" alt="Chania">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#Carousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#Carousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</br></br>
<!-- Image gallery end-->
If I've understood you just want to remove the gradient the chevrons have for a background?
#Carousel .carousel-control.left,
#Carousel .carousel-control.right {
background-image: none;
}
This should be all you need. Here is an example below
#Carousel .carousel-control.left,
#Carousel .carousel-control.right {
background-image: none;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<!-- Image Gallery Start-->
<br/>
<br/>
<div id="Carousel" class="carousel slide" data-ride="carousel" style="max-width: 400px; margin: 0 auto">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#suniceCarousel" data-slide-to="0" class="active"></li>
<li data-target="#suniceCarousel" data-slide-to="1"></li>
<li data-target="#suniceCarousel" data-slide-to="2"></li>
<li data-target="#suniceCarousel" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img class="img-responsive center-block" src="http://www.newventureactive.co.uk/images/sunice/sunice1.png" width="350" alt="Chania">
</div>
<div class="item">
<img class="img-responsive center-block" src="http://www.newventureactive.co.uk/images/sunice/sunice2.png" width="350" alt="Chania">
</div>
<div class="item">
<img class="img-responsive center-block" src="http://www.newventureactive.co.uk/images/sunice/sunice1.png" width="350" alt="Chania">
</div>
<div class="item">
<img class="img-responsive center-block" src="http://www.newventureactive.co.uk/images/sunice/sunice2.png" width="350" alt="Chania">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#Carousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#Carousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</br>
</br>
<!-- Image gallery end-->
Try This
.carousel-inner .active{
background:none !important;
}
I've checked the online example, the carousel adds the class active to the current active item.
In your style.css the active class has the following style:
.active{
background: url("images/active-bg.png") repeat scroll 0 0 rgba(0, 0, 0, 0) !important;
color: #fff !important;
}
you just need to remove the background property and you'll have a transparent background for every carousel item.
Only this worked:
<a class="left carousel-control" href="#myCarousel" data-slide="prev" style="background-image:none">
<a class="right carousel-control" href="#myCarousel" data-slide="next" style="background-image:none">
Nothing else worked for me.
i have a code about bootstrap carousel and it works perfectly however I want to align it on the center of my page. i tried so many different solutions but still no avail. is there any way to align this to the center
<div class="container">
<br>
<div class = "row">
<div id="myCarousel" class="carousel slide" data-ride="carousel ">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="css/pet9.jpg" alt="Chania">
</div>
<div class="item">
<img src="css/pet10.jpg" alt="Chania">
</div>
<div class="item">
<img src="css/pet8.jpg" alt="Flower" >
</div>
</div>
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
You can surround it with the <center> tag.
Is there a possibility to stop the autoslide when im on my mobile view.
If it´s possible with css... maybe with mediaquery xs and than manipulate a carousel element ...?
<div id="carousel" class="carousel slide" data-ride="carousel">
<!-- LOGO -->
<div class="container">
<div class="row logo">
<div class="col-lg-12 col-sm-8 col-xs-12"><img class="img-responsive" src="img/logo.png" alt=""/></div>
</div>
</div>
<!-- POINTS -->
<ol class="carousel-indicators hidden-xs">
<li data-target="#carousel" data-slide-to="0" class="active"></li>
<li data-target="#carousel" data-slide-to="1"></li>
<li data-target="#carousel" data-slide-to="2"></li>
<li data-target="#carousel" data-slide-to="3"></li>
</ol>
<!-- SLIDEWRAPPER -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="img/headbild-1.jpg" alt="headbild1">
</div>
<div class="item">
<img src="img/headbild-2.jpg" alt="headbild2">
</div>
<div class="item">
<img src="img/headbild-1.jpg" alt="headbild3">
</div>
<div class="item">
<img src="img/headbild-2.jpg" alt="headbild4">
</div>
</div>
<!-- PREV/NEXT Controls -->
<div class="container hidden-xs">
<a class="left carousel-control" href="#carousel" role="button" data-slide="prev">
<span class="previcon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control pull-right" href="#carousel" role="button" data-slide="next">
<span class="nexticon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
well to stop autoslide on a mobile device you would need to adjust your javascript / the init from the carousel in a different media query.
do you have a possibility to check your media screen size in js? if yes, simply destroy your carousel (sth like $('#carousel').destroy();) and reinit without the autoslide.