- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试使用 flexbox 生成以下布局。
顶部黑条、中间部分和底部黑条都是 flex 元素,它们是 body 标签内包装 div 的子项,如下所示。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic' rel='stylesheet' type='text/css'>
<link href="~/Styles/bootstrap.min.css" rel="stylesheet" />
<link href="~/Styles/font-awesome.min.css" rel="stylesheet" />
<link href="~/Styles/ppt_site.css" rel="stylesheet" />
</head>
<body>
<div class="wrapper">
<div id="topRow">
</div>
<div id="centralRow">
<div id="sidebarColumn">
</div>
<div id="contentColumn">
</div>
</div>
<div id="bottomRow">
</div>
</div>
@Section['customScripts']
<script src="~/Scripts/siteGlobals.js"></script>
<script src="~/requireconfig"></script>
<script data-main="~/scripts/NewTemplatesAppLoader.js" src="~/requirejs"></script>
</body>
</html>
控制这一切的样式表如下
.wrapper, html, body {
height: 100%;
margin: 0;
}
.wrapper {
display: flex;
-ms-flex-direction: column;
-webkit-flex-direction: column;
flex-direction: column;
}
#topRow {
background-color: black;
color: white;
}
#centralRow {
-ms-flex: 1;
-webkit-flex: 1;
flex: 1;
display: flex;
-ms-flex-direction: row;
-webkit-flex-direction: row;
flex-direction: row;
}
#bottomRow {
background-color: #333333;
color: white;
}
#sidebarColumn {
background-color: #B83B1D;
color: white;
}
#contentColumn {
-ms-flex: 1;
-webkit-flex: 1;
flex: 1;
background-color: #F7F7F7;
color: black;
padding: 10px;
overflow-y: auto;
}
就主要布局而言,这一切都完美无缺,但是如果您查看图像,您会注意到红色边栏是顶部带有黄色边框的区域。
该区域注定是一个 div,它会拉伸(stretch)上面 CSS 中红色区域(侧边栏列)的整个高度,但尽管我可能会尝试,但我无法让它做我需要的事情。
理想情况下,我希望它是一个 div,这是一个 flex 容器,然后我可以将 4 个 flex 元素放入其中,并且每个元素都占用四分之一的可用空间,但是因为带有黄色边框的 div似乎看不到父容器的高度(红色侧边栏,它本身是一个 flex 元素)然后它只会占据其内容周围空间的高度。
我试过将它包裹在更多的 div 中并定位这些 div,我在更多的 div 中包裹了更多的 flexbox ,我尝试了 block 、内联、表格单元格以及我能想到的几乎所有其他东西。
无论我尝试什么,我似乎都无法让黄色边框容器与其父级高度相同。
有什么想法吗?
所提出的 2 个解决方案确实有效,就其本身而言,它们也像我预期的那样有效。
然而,在我的特殊情况下,它们不起作用。
我正在使用 NancyFX 及其 super 简单的 View 引擎,我正在使用 KnockoutJS 来编写“Web 组件”,这样我就可以重复使用我的作品。
如果我编辑我的“主模板”,并将 div 直接插入标记中,嵌套在 #sidebarColumn 下面,我会根据需要获得 4 个大小相等的 div。
但是,实际需要发生的是以下情况,我的模板如下所示:
<div class="wrapper">
<div id="topRow">
@Section['topbarContent']
</div>
<div id="centralRow">
<div id="sidebarColumn">
@Section['sidebarContent']
</div>
<div id="contentColumn">
@Section['bodyContent']
</div>
</div>
<div id="bottomRow">
@Section['bottombarContent']
</div>
</div>
如果我删除“@Section['sidebarContent']”并将 div 直接放入它们中,它们就可以工作。
如果我将 div 直接放在使用模板的“页面”中,如下所示:
@Master['shared/ppt_layout.html']
@Section['topbarContent']
<toptoolbar></toptoolbar>
@EndSection
@Section['sidebarContent']
<div>aaa</div>
<div>aaa</div>
<div>aaa</div>
<div>aaa</div>
@EndSection
@Section['bodyContent']
<h1>Body Content</h1>
<p class="lead">I am the test page that uses a wide sidebar component</p>
<p>If you notice however, I also have a top toolbar with title added to me, and a footer bar.</p>
<p>We all use the same template however....</p>
@EndSection
@Section['bottombarContent']
<footerbar></footerbar>
@EndSection
@Section['customScripts']
@EndSection
这也行得通,但如果我将标记放在一个剔除组件中,即使只是页面中的直接 div,我也会得到我最初注意到的效果。
因此,出于某种原因,添加内容、使用敲除组件正是导致问题的原因。
即使我尝试在组件内构建一个新的 flex 布局,在垂直方向上什么也做不了,但在水平方向上一切都完美无缺。
例如,页脚栏被分为左右两部分,完全没有问题,但垂直对齐被取消了。
最佳答案
所以,经过几天的折磨,我终于弄清楚了问题所在。
我在我的元素中使用 knockout.js,特别是 knockout 组件,它们之间的障碍导致了问题。
对于那些以前没有使用过 KO 组件的人来说,这是一个非常简单的过程。您构建一个 JS View 模型和一小段 HTML 来提供组件显示界面。
然后你使用:
ko.components.register("myComponent", {
viewModel: "Components/myComponent.js",
template: "Components/myComponent.html"
});
ko.applyBindings();
注册您的组件。
一旦组件被注册,你就可以简单地通过放置来使用它
<myComponent></myComponent>
您希望将其添加到网页中的任何位置。
现在一切都很好,但是......当 KO 实例化组件时,它会保留自定义标签。
所以如果你想象你的组件看起来像这样
<div>
<div>Item...</div>
<div>Item...</div>
<div>Item...</div>
<div>Item...</div>
</div>
你的页面看起来像
<body>
<div>
<myComponent></myComponent>
</div>
</body>
那么最终的输出会是这样
<body>
<div>
<myComponent>
<div>
<div>Item...</div>
<div>Item...</div>
<div>Item...</div>
<div>Item...</div>
</div>
</myComponent>
</div>
</body>
鉴于上述 CSS 中的规则,我的和两个响应者都以包装器 div 为目标,该规则永远不会匹配目标 div 以在其上启用 flex。
关键(正如我通过反复试验发现的那样)是使用自定义标签名称,例如:
#sidebarColumn > narrowsidebar {
width: 70px;
flex: 1;
display: flex;
flex-direction: column;
}
然后,从该父级继承进一步的 flex 操作。
然而,它仍然没有解释,为什么当你在组件内部从头开始做一个完整的 flexbox 布局时(即在主网页和/或模板中没有任何 flex 操作),它仍然有垂直问题对齐,据我所知,KO 对应该导致此行为的 dom 没有做任何事情。
然而,对于我最初的问题,通过自定义标记定位可以让我到达我需要去的地方。
美女
关于html - 在 flexbox 元素中获取 100% 高度的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36553820/
大家好, 我看到了来自 java 项目中的 jsp 页面。 想问一下这些html标签有什么区别。 请多多指教。 示例代码如下: 最佳答案 使用struts-html标签库,其中只是普
我有一个页面,我正在从电子邮件中读取 HTML。 有时,来自电子邮件的文本包含 HTML 和 CSS,它完全改变了我的页面样式。 我不希望我的页面样式因此受到影响。我如何严格阅读特定 div(框)内的
我知道有类似的问题,但我想对我的特定代码进行一些输入。 我有一个图像,我将其切成 9 块,并创建了一个 3x3 HTML 表来显示它。 但是我的表在行之间有空格,但在列之间没有空格。我没有使用任何 C
编辑:Waylan 的回答成功了!谢谢! 我正在尝试压缩文档的 .html 文件以发送给客户。目标是获得与浏览实际网站相同的体验。 打开 .html 文件时,单击的任何链接都会转到父文件夹,而不是特定
编辑:Waylan 的回答成功了!谢谢! 我正在尝试压缩文档的 .html 文件以发送给客户。目标是获得与浏览实际网站相同的体验。 打开 .html 文件时,单击的任何链接都会转到父文件夹,而不是特定
这是 question 的扩展.我正在尝试解析嵌入在 Blogger 博客的 XML 备份中的 HTML 片段,并用 InDesign 标签重新标记它们。 Blogger 并未对其任何帖子的 HTML
我知道在 html 中元素之间的换行符被视为空格,但我认为当您尝试使用响应式布局时这非常可怕。 例如,这里我们有预期和正确的行为,但要获得它,我必须删除元素之间的 html 中的换行符: https:
我正在尝试将文本文件显示为 html。我正在使用 ionic 。我正在发送一个 html 格式的响应,但在一个文本文件中发送到配置文件页面。它在 .ts 页面的变量名中。 @Component({
假设我有一个 html 文档: test 我想在浏览器中显示该代码。然后我会创建类似的东西: <html>test<html> 为了在中间制作 gubbins,我有一个函数
HTML 元素和 HTML 标签有什么区别?渲染有什么区别吗?使用标签或元素时有什么特殊注意事项吗? 最佳答案 是一个标签,特别是一个开始标签 也是一个标签,一个结束标签 This is a para
我有这个表格的模态形式。该表正在填充大量数据,但我不想分页。相反,我想以模式形式降低表格的高度并为表格添加溢出。下面是我的代码,但它不起作用。 请问我该如何实现? CSS #table{
我记得有一个 Linux 命令可以从给定的 URL 返回 HTML 代码。您可以将 URL 作为此命令的参数,然后返回 HTML 代码,而不是在浏览器中输入 URL。 哪个命令执行此操作? 最佳答案
我有一个 html 页面,我想在其中包含另一个有很多链接的 html 页面。我能够使用 iframe 实现它,但我希望 iframe 内的页面具有与原始页面相同的文本和链接颜色属性,我不想要滚动条,我
我正在使用 HTML 写一本书。如果我把它写在一个 html 文件中,整个代码就会变长,所以我想将每一章保存到不同的文件中,然后将它们加载到主 html 中。我的意思是有像 chapter1.html
在显示之前,我必须将一个网站重定向到另一个网站。我试过使用 .htaccess,但它给我带来了问题。我也使用过 javavscript 和 meta,但在加载我要从中传输的页面之前它不起作用。帮助?
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
如何打印“html”标签,包括“”?如何在不使用文本区域和 Javascript 的情况下对任何标签执行此操作? 最佳答案 使用HTML character references : <html
我需要将 Ruby on Rails 应用程序中的 html.slim 文件转换为 html.erb。有什么简单的方法吗?我尝试了 Stack Overflow 和其他网站中列出的许多选项。但对我没有
这个问题在这里已经有了答案: Is it necessary to write HEAD, BODY and HTML tags? (6 个答案) 关闭 8 年前。 我在 gitHub 上找到了这个
如果不允许通过 JavaScript 进行额外的 DOM 操作,我正在寻找可以加载外部资源的元素列表。我正在尝试使用 HTML 查看器托管来自第三方的电子邮件,当发生这种情况时,我需要删除任何自动加载
我是一名优秀的程序员,十分优秀!