I need to change the margin-left that is applied to my main {% block content %}
in my base.html
template (that contains my navbar and other common elements) based on if the viewer is using mobile or desktop.
My current base.html
is like:
<div class="content container-fluid">
<div class="row">
<div class="col-md-8">
{% block content %}
{% endblock %}
</div>
</div>
</div>
with a css file containing:
.content {
margin-left: 40px;
}
.content_mobile {
margin-left: 10px;
}
Given that in other parts of my application I've accomplished something similar by using the following dedicated Bootstrap classes, my first thought was to do the same using something like:
<div class=".visible-xs-block, hidden-xs">
<div class="content container-fluid">
<div class="row">
<div class="col-md-8">
<!-- This is hidden from mobile view -->
{% block content %}
{% endblock %}
</div>
</div>
</div>
</div>
<div class=".visible-lg-block, hidden-lg .visible-md-block, hidden-md .visible-sm-block, hidden-sm">
<div class="content_mobile container-fluid">
<div class="row">
<div class="col-md-8">
<!-- This is hidden from all other views (including desktop) -->
{% block content %}
{% endblock %}
</div>
</div>
</div>
</div>
But Django raises an exception because it can only render 1 {% block content %}
per template!
Any ideas how I can do this without using multiple blocks?
The four margin properties for each side of the box and the margin shorthand were all defined in CSS1. The CSS2. 1 specification has an illustration to demonstrate the Box Model and also defines terms we still use to describe the various boxes.
The short answer is no, as long as you are only using negative CSS margins to bring elements closer together than their box model properties would allow.
One way to do this is to add margins, which will create space around one or more sides of the element. A simple margin declaration might look like this: margin: 10px; That declaration means that the margin box should extend 10px in all four directions—left, right, up, and down—beyond the size of the border box.
Define some width on your container and set margin top & bottom to some desired value and left & right values to auto so that it will always split the remaining space on the both sides equally.
example :
<div class="content">Some thing </div>
you want to give different margin based on size of display
than do this
In your common css :
@media (max-width: 480px) {
.content{
margin-left: 20px;
}
}
@media (max-width: 320px) {
.content{
margin-left: 10px;
}
}
and
@media (min-width:320px) { /* smartphones, portrait iPhone, portrait 480x320 phones (Android) */ }
@media (min-width:480px) { /* smartphones, Android phones, landscape iPhone */ }
@media (min-width:600px) { /* portrait tablets, portrait iPad, e-readers (Nook/Kindle), landscape 800x480 phones (Android) */ }
@media (min-width:801px) { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
@media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
@media (min-width:1281px) { /* hi-res laptops and desktops */ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With