Inline CSS background: url () not working in Jinja2 template
I am having an issue where Bootustrap Carousel is responsive and scales the height and width of dynamic images. One workaround I found was to use: background: url(path_to_image.jpg) no-repeat center center;
which works fine.
Now I am trying to include the code in my Flask / Jinja application:
#hp {
height: 250px;
width: 100%;
background-color: gray;
/* background: url(https://ununsplash.imgix.net/photo-1427348693976-99e4aca06bb9) no-repeat center center; */
background-size: cover;
}
<div id="hp" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#hp" data-slide-to="0" class="active"></li>
<li data-target="#hp" data-slide-to="1"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<!-- Wrap slides 1 -->
<div class="item active">
<div style="background: url(https://ununsplash.imgix.net/photo-1427348693976-99e4aca06bb9) no-repeat center center / cover;">
</div>
</div>
<!-- Wrap slides 2 -->
<div class="item"></div>
</div>
<!-- codes for Controls follows -->
</div>
For real code, I've tried the following options:
<img src="{{url_for('.static', filename='img/works2_big.jpg')}}" class="center-block">
and this one:
<div style="background: url(../static/img/works2_big.jpg) no-repeat center center;">
</div>
I even went ballistic on this one:
<div style="background: url({{url_for('.static', filename='img/works2_big.jpg')}}) no-repeat center center"></div>
no show yet. I am using a Flask project with my static file which is well defined and contains my working css and js files.
main = Blueprint('main', __name__, template_folder='templates', static_folder='static')
Is there any other way I can correctly insert this inline css into jinja?
+2
source to share