【发布时间】:2017-07-24 16:20:44
【问题描述】:
编辑:根据正确答案修改标题,以帮助谷歌搜索
在下面的代码中,在404.pug 页面中包含我的header.pug 后,404.pug 页面中的h2 标记不断成为h1 标记的子级。这是我正在使用的代码:
Header.pug
doctype
html
head
meta(charset='utf-8')
title Express Guestbook
link(href="to/bootstrap.min.css", rel="stylesheet")
body.container
h1 Express Guestbook
a.btn.btn-primary.pull-right(href="/new-entry") Write in Guestbook
//- putting this div here so that whatever code 'include'-s this
//- header, will be a child of this div
div
404.pug
include header.pug
//- This part becomes child of <a> tag, instead of <div>
h2 404! Page not found
include footer.pug
谁能解释一下
- 为什么会这样?而且,
- 可能展示一种方法来保持
h2标记作为h1的同级而不成为a标记的子级?
现在解决此问题的一种可能方法是使用嵌套 div(一个 div 在另一个 div 中)而不是只有一个 div,如下所示:
body.container
h1 Express Guestbook
a.btn.btn-primary.pull-right(href="/new-entry") Write in Guestbook
//- ugly hack
div: div
但这感觉不太好..
【问题讨论】: