- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近开始熟悉 Web 应用程序开发并努力解决一个基本的 css 布局问题。
所需的布局是一个中心区域重叠几个背景元素。看这里:
此图像显示了所需的布局:
我也在 codepen 上破解过它: Codepen
我在中心区域周围使用html div构建背景。
<div class="page-element">
<div class="element-side"></div>
<div class="element-middle"></div>
<div class="element-side"></div>
</div>
和 css 来放置它:
.page-element {
display: flex;
}
.element-middle {
width: 90%;
}
.element-side {
flex: 1;
}
但我在那里做的方式看起来不像正确的布局样式。
在现代 css 中做这样的布局的正确方法是什么?
最佳答案
由于您的大部分结构都很好,我保留了它,主要的变化是如何创建左/右装订线和页眉/页脚上的溢出。
对于左/右排水沟,我只是删除了 side
元素,保留了 width: 90%
并使用了 margin: 0 auto
来水平居中。
对于页眉/页脚溢出,我删除了 below-nav
/footer1
元素,在主体上添加了伪元素(仅使用 CSS 完成)和一个额外的底部/页眉/页脚上的顶部填充,这样伪就不会与它们的内容重叠。
.nav1, .nav2, .nav1 > div {
display: flex;
background: #f05d23;
}
.nav-elem {
flex: 1;
}
.nav1 > div, .nav2 > div {
margin: 0 auto; /* added, center horiz. */
width: 90%;
text-align: center;
padding: 1em;
box-sizing: border-box;
}
.nav2 > div {
padding-bottom: 3em; /* added, avoid overlap */
}
.main {
position: relative;
display: flex;
background: #e4e6c3;
}
.main::before, .main::after { /* added, create overflow */
content: '';
position: absolute;
left: 5%;
width: 90%;
height: 3em;
background: #f7f7f2;
}
.main::before {
top: 100%;
}
.main::after {
bottom: 100%;
}
.main section {
margin: 0 auto; /* added, center horiz. */
width: 90%;
padding: 1em;
box-sizing: border-box;
background: #f7f7f2;
}
.footer {
display: flex;
background: #2d2a32;
}
.footer section {
margin: 0 auto; /* added, center horiz. */
width: 90%;
padding: 1em;
padding-top: 4em; /* added, avoid overlap */
box-sizing: border-box;
text-align: center;
color: #f7f7f2;
}
body {
padding: 0;
margin: 0;
}
h1, h2 {
font: bold 2em Sans-Serif;
margin: 0 0 1em 0;
}
h2 {
font-size: 1.5em;
}
p {
margin: 0 0 1em 0;
}
<div class="nav1">
<div>
<div class="nav-elem"><a href="#">Plan</a></div>
<div class="nav-elem"><a href="#">AdminPlan</a></div>
<div class="nav-elem"><a href="#">Help</a></div>
<div class="nav-elem"><a href="#">Login</a></div>
</div>
</div>
<div class="nav2">
<div>
<h1>Pageheader.</h1></div>
</div>
<div class="main">
<section>
<h1>Main Content</h1>
<p>One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by
arches into stiff sections.</p>
<p>The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. "What's happened to me? " he thought. It wasn't a dream.</p>
<p>His room, a proper human room although a little too small, lay peacefully between its four familiar walls. A collection of textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture that he had
recently cut out of an illustrated magazine and housed in a nice, gilded frame. It showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards the viewer. Gregor then
turned to look out the window at the dull weather. Drops</p>
</section>
</div>
<div class="footer">
<section>
<h2>Footer</h2>
<p>Whatever goes into a page </p>
</section>
</div>
请注意,.footer section
中 padding-top: 4em;
的填充值当然可以像这样添加到现有的速记属性中: padding: 4em 1em 1em;
(/* top | horizontal | bottom */
)
关于html - css 页面布局 - 前景 "overlying"背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45768113/
我的应用程序有一个“今日小部件”,点击它会启动包含的应用程序。问题是它似乎“过于敏感”。有时,当我只是滚动时,小部件会将其识别为点击并启动应用程序。 这是我的代码: @IBAction fun
我用的是cocos2dx。当我使用它的类时,我需要经常输入 cocos2d:: 除非我输入 using namespace cocos2d;。 如何避免必须一直重复命名空间? 最佳答案 有几种方法可以
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 2年前关闭。 Improve thi
我有一个可拖放的任务列表。它们都有一个“over”事件处理程序,以确保当另一个任务悬停在它们上方时它们会亮起。 这并没有完全按照我想要的方式工作。当我开始拖动一个任务时,其他任务不会按预期亮起,除非鼠
所以我有一个长度为 4 的数组。当我将它递增 1 并且数字变得大于数组的长度时,我希望它翻转。 例如: current_index = 3; current_index++; //current_in
有没有办法让 python 的 json.dumps “跳过”特定键,以便将某些值直接写入标签中? 例如 data = {'a_number': 42, 'a_string': 'foo'} data
我正在尝试在 FabricJS(version:1.4.0) Canvas 上监听 mouse:over 事件,但它似乎没有像我预期的那样工作。这是片段 const canvas = new fabr
我最近开始熟悉 Web 应用程序开发并努力解决一个基本的 css 布局问题。 所需的布局是一个中心区域重叠几个背景元素。看这里: 此图像显示了所需的布局: 我也在 codepen 上破解过它: Cod
function downloadAsync(url, name) { return new Promise(function(resolve, reject) { request(url
我目前正在处理一些测试用例,我经常发现在每个用例中我都会得到多个断言。例如(为简洁起见过度简化和删除评论): [Test] public void TestNamePropertyCorrectlyS
我正在为要求苛刻的应用程序开发后端,该应用程序可能会在服务器上产生非常高的流量和处理负载。为了处理数据库连接,我想出了以下两种策略: function connectToDB() { retu
我希望它定位在内容之上,所以我认为绝对定位是可行的方法,这样它就不会把其他东西推开。 但是,我想确保它位于单击它的按钮下方。如果我使用绝对位置并将 right 设置为 0(按钮位于页面的右侧,因此我将
我很头疼,因为我在尝试将混合滤镜应用于图像并显示它时遇到崩溃。我想要做的只是将一个叠加图像放在另一个图像上。 这是我的代码: - (GPUImageOutput *)myFilter { GP
在 MS SQL Server 中,我花了太多时间试图解决这个问题。我终于弄明白了,除了我不知道原因。为什么除以第 4 行中的 cast 语句会在下面起作用 SELECT cast(dbo.FAC
Racket 的文档仅部分描述了 augment和 pubment做:augment创建一个在该方法的父类(super class)版本之后执行的方法,而 pubment创建一个隐含 augment
嘿, 如何将我的链接移到一边?这可能真的很愚蠢:) 链接位于我的图片之上。任何帮助,将不胜感激。谢谢。 .plus{left:0px;height:17px;width
如何从标题运行多次的 sql 查询中获取结果?这显示了“PPP”的正确值,但过滤 AND (count(*) over (partition by TITLE)) > 1 不起作用。 我们将不胜感激。
是否有命令在不使用鼠标的情况下显示“悬停”工具提示文本? 如果我的光标当前在它上面,我希望它弹出一个键绑定(bind)。 (那个白 block 是我的光标)。 最佳答案 我可以看到你想要 Visual
我尝试在包含链接的 div 上创建鼠标悬停事件。当鼠标经过 div 时,背景会正确应用于所有 div,但是当鼠标经过链接时,背景只会应用于链接,为什么? 链接 IS 在 div 中,因此从逻辑上讲,它
当应用带有过渡动画的 3D 变换时,有没有办法从高 Angular 向前旋转到低 Angular ,这样我就可以通过向前移动 20 度而不是向后移动 340 度来从 350 度旋转到 10 度。 最佳
我是一名优秀的程序员,十分优秀!