我有以下的标记格式:
现在,由标记提供的原始
第一种格式: http://jsfiddle.net/projeqht/NCfym/ 第二种格式: http://jsfiddle.net/projeqht/NCfym/1 我的问题是:
为什么格式化的HTML标记输出的CSS间距与完全相同的单行HTML标记不同?
<!-- .section markup with line breaks and indentation (normal formatted coding) -->
<form id="form" name="form">
<div class="section">
<input type="checkbox" class="switch" />
<select class="overlays" name="overlays">
<option value="test">Test</option>
</select>
<input type="text" class="parameters" />
</div>
</form>
<span id="plus">+</span>
我需要编写一些 jQuery 代码,以便根据需要像这样添加更多的 .section
:
$('#plus').click(function () {
$('#form').append('<div class="section"><input type="checkbox" class="switch" /><select class="overlays" name="overlays"><option value="test">Test</option></select><input type="text" class="overlay_parameters" name_parameters" /></div>');
});
但是我注意到每当我添加 .section
时,CSS 的边距/填充有点偏差。
然后,我意识到如果我使用以下格式:
<!-- .section markup all in one line -->
<form id="form" name="form">
<div class="section"><input type="checkbox" class="switch" /><select class="overlays" name="overlays"><option value="test">Test</option></select><input type="text" class="parameters" /></div>
</form>
<span id="plus">+</span>
现在,由标记提供的原始
.section
与通过JQUERY附加的.section
具有相同的CSS间距。第一种格式: http://jsfiddle.net/projeqht/NCfym/ 第二种格式: http://jsfiddle.net/projeqht/NCfym/1 我的问题是:
为什么格式化的HTML标记输出的CSS间距与完全相同的单行HTML标记不同?