编程语言
首页 > 编程语言> > javascript-如何将自定义CSS正确添加到Bootstrap模式

javascript-如何将自定义CSS正确添加到Bootstrap模式

作者:互联网

我正在为名为Brackets的文本编辑软件编写扩展程序,Brackets使用Bootstrap来设置Modal和CSS的样式.
我试图将自定义CSS添加到Modal,以便可以重新格式化,移动和调整Modal上不同元素的大小,例如复选框和下拉菜单,以使其看起来更整洁.

每当我尝试通过使用内置标签或链接的CSS将CSS添加到Modal时,Modal均无法正确加载.
模态负载,然后整个屏幕覆盖在其上面的不透明黑色薄膜,模态变得无法使用.

因此,我可以推断出我没有正确添加CSS,因为删除我添加的CSS时Modal会纠正行为.

如何向此Bootstrap模式添加自定义CSS样式?

<div id='templates_modal' class='template modal'>
<div class='modal-header'>
    <button type='button' class='close' data-dismiss='modal'><span aria-hidden='true'>&times;</span></button>
    <h1 class='dialog-title'>{{TITLE_H1}}</h1>
</div>
<p style='display: none; color: red; font-weight: bold;' id='templates_warning'>{{DOCTYPE_ALERT}}</p>
<p style='display: none; color: red; font-weight: bold;' id='templates_warning'>{{CONTENT_ERROR}}</p>
<p style='display: none; color: red; font-weight: bold; padding: 10px;' id='templates_error'>{{NO_FILE_OPEN_ERROR}}</p>
<div class='modal-body'>
    <h4>{{LANGUAGE_SELECTION}}</h4>
    <p>{{LANGUAGE_DESCRIPTION}}</p>
    <select id='languages'>
        <option value=''>{{SELECT_LABEL}}</option>
        <option value='english'>en</option>
        <option value='german'>de</option>
        <option value='spanish'>es</option>
        <option value='french'>fr</option>
        <option value='italian'>it</option>
        <option value='chinese'>zh-cn</option>
    </select>
    <h4>{{CHARSET_SELECTION}}</h4>
    <p>{{CHARSET_DESCRIPTION}}</p>
    <select id="charset">
        <option value=''>{{SELECT_LABEL}}</option>
        <option value='utf8'>UTF-8</option>
        <option value='utf16'>UTF-16</option>
    </select>

    <h4>{{TITLE_H4}}</h4>
    <select id="doctype">
        <option value=''>{{SELECT_LABEL}}</option>
        <option value='html5'>HTML5</option>
        <option value='html4loose'>HTML4 Transitional</option>
        <option value='html4strict'>HTML4 Strict</option>
        <option value='xhtml1loose'>XHTML 1 Trasitional</option>
        <option value='xhtml1strict'>XHTML 1 Strict</option>
        <option value='xhtml11'>XHTML 1.1</option>
    </select>

    <h4>{{SECTION_TEMPLATES}}</h4>
    <p>{{SECTION_TEMPLATES_DESC}}</p>
    <ul class="checkbox-grid" id="libraries">
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>' id="angularjs" value="angularjs" /><label for="angularjs"> Angular JS | 1.3.15</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.10.1/angular-material.min.js"></script>' id="angularmaterial" value="angularmaterial" /><label for="angularmaterial"> Angular Material | 0.10.0</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>' id="dojo" value="dojo" /><label for="dojo"> Dojo | 1.10.4</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/ext-core/3.1.0/ext-core.js"></script>' id="extcore" value="extcore" /><label for="extcore"> Ext Core | 3.1.0</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>' id="jquery111" value="jquery111" /><label for="jquery111"> jQuery | 1.11.3</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>' id="jquery214" value="jquery214" /><label for="jquery214"> jQuery | 2.1.4</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>' id="jquerymobile" value="jquerymobile" /><label for="jquerymobile"> jQuery Mobile | 1.4.5</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>' id="jqueryui" value="jqueryui" /><label for="jqueryui"> jQUery UI | 1.11.4</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/mootools/1.5.1/mootools-yui-compressed.js"></script>' id="mootools" value="mootools" /><label for="mootools"> MooTools | 1.5.1</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.2.0/prototype.js"></script>'  id="prototype"value="prototype" /><label for="prototype"> Prototype | 1.7.2.0</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js"></script>' id="script_aculo_us" value="script_aculo_us" /><label for="script_aculo_us"> script.aculo.us | 1.9.0 (Requires Prototype)</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/spf/2.2.0/spf.js"></script>' id="spf" value="spf" /><label for="spf"> SPF | 2.2.0</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>' id="swfobject" value="swfobject" /><label for="swfobject"> SWFObject | 2.2</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/threejs/r69/three.min.js"></script>' id="threejs" value="threejs" /><label for="threejs"> three.js | r69</label></li>
        <li><input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.5.18/webfont.js"></script>' id="webfontloader" value="webfontloader" /><label for="webfontloader"> Web Font Loader | 1.5.18</label></li>
    </ul>
    <div class='modal-footer'>
        <a id='templates_modalGenBtn generate_html_btn' href='#' class='dialog-button btn btn-danger'>{{GENERATE_BUTTON}}</a>
        <a id='templates_modalBtn' href='#' class='dialog-button btn btn-danger' data-dismiss='modal'>{{CANCEL_BUTTON}}</a>
    </div>
</div>
</div>

解决方法:

模态载荷,然后整个屏幕在其上都得到不透明的黑色胶片,模态变得无法使用.

您缺少2 div< div class =“ modal-dialog”>和< div class ='modal-content'>

没有< div class =“ modal-dialog”>和< div class ='modal-content'>

Fiddle

<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#templates_modal">Open Modal</button>
<div id='templates_modal' class='template modal'>
<div class="modal-dialog">
    <div class='modal-content'>
    <div class='modal-header'>
        <button type='button' class='close' data-dismiss='modal'><span aria-hidden='true'>&times;</span>
        </button>
         <h1 class='dialog-title'>{{TITLE_H1}}</h1>

    </div>
    <p style='display: none; color: red; font-weight: bold;' id='templates_warning'>{{DOCTYPE_ALERT}}</p>
    <p style='display: none; color: red; font-weight: bold;' id='templates_warning'>{{CONTENT_ERROR}}</p>
    <p style='display: none; color: red; font-weight: bold; padding: 10px;' id='templates_error'>{{NO_FILE_OPEN_ERROR}}</p>
    <div class='modal-body'>
         <h4>{{LANGUAGE_SELECTION}}</h4>

        <p>{{LANGUAGE_DESCRIPTION}}</p>
        <select id='languages'>
            <option value=''>{{SELECT_LABEL}}</option>
            <option value='english'>en</option>
            <option value='german'>de</option>
            <option value='spanish'>es</option>
            <option value='french'>fr</option>
            <option value='italian'>it</option>
            <option value='chinese'>zh-cn</option>
        </select>
         <h4>{{CHARSET_SELECTION}}</h4>

        <p>{{CHARSET_DESCRIPTION}}</p>
        <select id="charset">
            <option value=''>{{SELECT_LABEL}}</option>
            <option value='utf8'>UTF-8</option>
            <option value='utf16'>UTF-16</option>
        </select>
         <h4>{{TITLE_H4}}</h4>

        <select id="doctype">
            <option value=''>{{SELECT_LABEL}}</option>
            <option value='html5'>HTML5</option>
            <option value='html4loose'>HTML4 Transitional</option>
            <option value='html4strict'>HTML4 Strict</option>
            <option value='xhtml1loose'>XHTML 1 Trasitional</option>
            <option value='xhtml1strict'>XHTML 1 Strict</option>
            <option value='xhtml11'>XHTML 1.1</option>
        </select>
         <h4>{{SECTION_TEMPLATES}}</h4>

        <p>{{SECTION_TEMPLATES_DESC}}</p>
        <ul class="checkbox-grid" id="libraries">
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>' id="angularjs" value="angularjs" />
                <label for="angularjs">Angular JS | 1.3.15</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.10.1/angular-material.min.js"></script>' id="angularmaterial" value="angularmaterial" />
                <label for="angularmaterial">Angular Material | 0.10.0</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>' id="dojo" value="dojo" />
                <label for="dojo">Dojo | 1.10.4</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/ext-core/3.1.0/ext-core.js"></script>' id="extcore" value="extcore" />
                <label for="extcore">Ext Core | 3.1.0</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>' id="jquery111" value="jquery111" />
                <label for="jquery111">jQuery | 1.11.3</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>' id="jquery214" value="jquery214" />
                <label for="jquery214">jQuery | 2.1.4</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>' id="jquerymobile" value="jquerymobile" />
                <label for="jquerymobile">jQuery Mobile | 1.4.5</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>' id="jqueryui" value="jqueryui" />
                <label for="jqueryui">jQUery UI | 1.11.4</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/mootools/1.5.1/mootools-yui-compressed.js"></script>' id="mootools" value="mootools" />
                <label for="mootools">MooTools | 1.5.1</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.2.0/prototype.js"></script>' id="prototype" value="prototype" />
                <label for="prototype">Prototype | 1.7.2.0</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js"></script>' id="script_aculo_us" value="script_aculo_us" />
                <label for="script_aculo_us">script.aculo.us | 1.9.0 (Requires Prototype)</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/spf/2.2.0/spf.js"></script>' id="spf" value="spf" />
                <label for="spf">SPF | 2.2.0</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>' id="swfobject" value="swfobject" />
                <label for="swfobject">SWFObject | 2.2</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/threejs/r69/three.min.js"></script>' id="threejs" value="threejs" />
                <label for="threejs">three.js | r69</label>
            </li>
            <li>
                <input type="checkbox" name="lib_checkboxes" data-script='<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.5.18/webfont.js"></script>' id="webfontloader" value="webfontloader" />
                <label for="webfontloader">Web Font Loader | 1.5.18</label>
            </li>
        </ul>
        <div class='modal-footer'> <a id='templates_modalGenBtn generate_html_btn' href='#' class='dialog-button btn btn-danger'>{{GENERATE_BUTTON}}</a>
 <a id='templates_modalBtn' href='#' class='dialog-button btn btn-danger' data-dismiss='modal'>{{CANCEL_BUTTON}}</a>
        </div>
     </div>
     </div>
    </div>
</div>

Fiddle

使用bootstrap predefined classes设置样式,使用grid system设置模式内部的格式

Fiddle

而且您可以像添加内联样式< p style ='display:none;一样添加自定义css.红色; font-weight:bold;' id ='templates_warning'> {{DOCTYPE_ALERT}}< / p>或者将自定义选择器添加到样式表中,最好添加自定义选择器,因为稍后您可以使用media queries根据屏幕尺寸调整模式内容.

例如

<p class="nodisplay" id='templates_warning'>{{DOCTYPE_ALERT}}</p>

并在样式表中

.nodisplay {
    display: none;
    color: red;
    font-weight: bold;
}

Fiddle

标签:adobe-brackets,html,javascript,jquery
来源: https://codeday.me/bug/20191119/2038365.html