html - 将 DIV 定位在一个地方,然后在多个地方使用

标签 html css

采用以下 HTML:

<div id="topbar">
  <div class="sitewidth"></div>
</div>
<div class="sitewidth"></div>
<div id="content" class="sitewidth front-page">
</div>

如何定位第二个 sitewidth,而不会对 topbar 中的 sitewidth 和下一个 div 中的 sitewidth 触发相同的效果?

请注意,我无法访问 HTML,我只能使用 CSS!

最佳答案

基于此评论

sitewidth is used on multiple places, also right after this one again. It is, however, the 2nd time it gets used and I think that's how it always is (in other words: as far as I know, nothing gets in between topbar and the second sitewidth

和这个结构

<div id="topbar">
  <div class="sitewidth"></div>
</div>
<div class="sitewidth"></div>

然后

#topbar + .sitewidth {
your styles here
}

这只会针对 sitewidth div,它紧跟 #topbar ,而不是其他。。

关于html - 将 DIV 定位在一个地方,然后在多个地方使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27404262/

相关文章:

javascript - 弹出内容有时出现在主要内容后面

javascript - 轮播外的文本保持网站响应

html - CSS 未被识别为 CSS 文件

css - 存在外部链接时,SVG css3 过渡填充不起作用

html - 为什么我的填充仅在元素处于悬停状态时显示?

html - 无限旋转 DIV 但具有绝对定位

javascript - 如何在一周中的几天之间更改照片?

html - 如何防止传单 map 元素获得焦点

javascript - html5 facebook 像按钮在本地不起作用

html - 在 Css 中添加货币值将其放入单独的行中