我代码中的一个元素正在充当其上方另一行代码的子元素,而我正尝试重新编写代码,因此该元素独立存在。这是我的Codepen的链接:
https://codepen.io/DevinCassidy/pen/pBNNKY
我尝试了一个分页符,并在其周围包含了另一个div元素。
\\\
<div>
<h2 id="Price">Price</h2>
<section id="pricing">
<div id="online">
<div class="level">Online
</div>
<h2>$1,599.00</h2>
<ol>
<li>Plus Free Shipping</li>
</ol>
<button class="btn">Select</button>
<br>
<div id="in-store">
<div class="level">In-Store
</div>
<h2>$1,599.00</h2>
<ol>
<li>*Out the door!*</li>
</ol>
<button class="btn">Select</button>
</section>
\\\\\\
答案 0 :(得分:2)
之所以这样做,是因为它们 是嵌套的
经过清理的正确缩进代码如下:
<div>
<h2 id="Price">Price</h2>
<section id="pricing">
<div id="online">
<div class="level">Online</div>
<h2>$1,599.00</h2>
<ol>
<li>Plus Free Shipping</li>
</ol>
<button class="btn">Select</button>
<br>
<div id="in-store">
<div class="level">In-Store</div>
<h2>$1,599.00</h2>
<ol>
<li>*Out the door!*</li>
</ol>
<button class="btn">Select</button>
</div><!-- this div was missing -->
</div><!-- this div was missing -->
</section>
</div><!-- this div was missing -->
通过缩进,您会发现实际上<div id="in-store">
是<div id="online">
的子代。你应该这样做
<div>
<h2 id="Price">Price</h2>
<section id="pricing">
<div id="online">
<div class="level">Online</div>
<h2>$1,599.00</h2>
<ol>
<li>Plus Free Shipping</li>
</ol>
<button class="btn">Select</button>
</div><!-- inserted because <div id="online" should be closed -->
<!-- <br> not needed, because <div>s are block elements -->
<div id="in-store">
<div class="level">In-Store</div>
<h2>$1,599.00</h2>
<ol>
<li>*Out the door!*</li>
</ol>
<button class="btn">Select</button>
</div>
</section>
</div>
我分叉了您的Codepen,并进行了一些更正:https://codepen.io/HerrSerker/pen/7cec5ac558e7c4fdaecbd8ac1d269178
<img>
元素;错误:<img src=""></img>
<img src=""/>
或仅<img src="">
<br>
在元素之间留出空间。为此使用CSS margin
<br>
标签不会关闭<div>
元素。只有</div>
可以v
)您的HTML代码区域,然后从下拉菜单中选择整洁的HTML 。