使用jinja2时删除div之间的空白

2024-09-26 22:45:58 发布

您现在位置:Python中文网/ 问答频道 /正文

因此,如果两个内联div用新行相邻,就会创建空白。 但我的问题是我有一堆jinja2代码,所以我不能把div放在同一行。在

我想把divs内联,这样它们就可以并排出现,中间没有空格。我的布局是动态生成的。这是现在的样子enter image description here

容器是900px宽的,所以我试图使每个数据div都是300px,这样每行可以有3个字段。在

我希望它看起来像: enter image description here

以下是标题和字段的代码:

HTML/Jinja2

        <div class="section">

            <div class="sectionTitle">
                <label class="print_h3">{{ title }} Info</label><br />
            </div>

            <div class="print_dataDiv">
                <label class="print_inputBoxLabels">Model</label>
                <select name="model" class="print_inputBoxes">
                </select>
            </div>
            <div class="print_dataDiv">
                <label class="print_inputBoxLabels">Substation</label>
                <select name="substation" class="print_inputBoxes">
                </select>
            </div>
            {% for field in field_list %}
                <div class="print_dataDiv">
                    <label class="print_inputBoxLabels">{{field.field_name}}</label>
                    <input class="print_inputBoxes" name="field_{{field.field_id}}_{{field.device_id}}" value="{{field.field_value}}" type="input">
                </div>
            {% endfor %}
        </div>

CSS(in order as they appear in the code):
.section{
    width: 100%;
    height: auto;
    border: solid 1px;
}
.sectionTitle{
    width: 100%;
    text-align: center;
    height: 30px;
    border: solid 1px;
    background: #B3B3B3;
    border-left: none;
    border-right: none;
    //margin-bottom: 5px;
}
.print_dataDiv {
    height: 30px;
    width: 300px;
    display: inline-block;
    border: solid 2px;
}
.print_inputBoxLabels{
    width: 140px;
    height: 30px;
    display: block;
    text-decoration: none;
    float: left;
    font-size: 80%;
    margin-left: 2px;
    margin-left: 2px;
}
.print_inputBoxes{
    width: 130px;
    height: 30px;
    display: inline-block;
    float: right;
    outline:none;
}

编辑:这是我的jinja2代码的一个更大的例子,它阻止div在同一行上排列

^{pr2}$

Tags: namedivnonefieldwidthleftselectlabel
2条回答

for块很容易。。。不幸的是,并不是所有的块表达式都适用于此

{% for field in field_list -%}
    <div>...</div>
{%- endfor %}

http://jinja.pocoo.org/docs/dev/templates/#whitespace-control

You can also strip whitespace in templates by hand. If you add a minus sign (-) to the start or end of a block (e.g. a For tag), a comment, or a variable expression, the whitespaces before or after that block will be removed

试试这个:

{% for field in field_list %}<! 
         ><div class="print_dataDiv">
                <label class="print_inputBoxLabels">{{field.field_name}}</label>
                <input class="print_inputBoxes" name="field_{{field.field_id}}_{{field.device_id}}" value="{{field.field_value}}" type="input">
            </div><! 
 >{% endfor %}

或者,将font-size:0给父对象。在

相关问题 更多 >

    热门问题