【发布时间】:2017-01-18 00:43:47
【问题描述】:
我有一个第二行菜单,我想使用 flexbox 居中。我是 flexbox 新手,有几个问题:
- 当我在 DreamWeaver CS6 中验证 HTML 时,它无法识别元素 top_row、left_button 和 right_button。然而,我遵循了一些关于 flexbox 的示例,表明这是一种正确的格式。我对这些元素定义做错了什么?
- 如何让宽度为 875 像素的“主菜单”行在我展开窗口以使其更宽和更窄时保持居中?现在它保持左对齐。
- 如何让left_button(主页)在窗口变宽和变窄时与主菜单的左侧对齐?现在它保持左对齐。
- 当窗口变宽和变窄时,如何让 right_button(后退)与主菜单的右侧对齐?现在它与扩大或缩小窗口的右侧对齐。
- 如何获得“文本装饰:无;”属性才能工作,以便按钮上没有下划线?
这是我第一次尝试使用 flexbox 时的示例代码。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {
background: #EEE8AA;
}
#main {
margin: 0px;
padding: 0px;
display: flex;
flex-flow: row;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
line-height: 25px;
text-align: center;
max-width: 875px;
align-items: center;
justify-content: space-between;
}
#main > top_row {
background: #BDB76B;
display: flex;
justify-content: center;
align-items: center;
width: 875px;
height: 25px;
}
#main > left_button {
margin: 5px;
background: #BDB76B;
order: 1;
position: absolute;
left: 0;
width: 150px;
text-decoration: none;
}
#main > right_button {
margin: 5px;
background: #BDB76B;
order: 3;
position: absolute;
right: 0;
width: 150px;
text-decoration: none;
}
</style>
<title>Sample Title</title>
</head>
<body>
<div id="main">
<top_row>Main Menu</top_row>
</div>
<br />
<div id="main">
<left_button><a href="http://www.msn.com/">Home</a>
</left_button>
<right_button><a href="#" onclick="history.go(-1)">Back</a>
</right_button>
</div>
</body>
</html>
当它工作时,我会将<style> 标记信息移动到一个 CSS 文件中。
感谢您查看此内容。
【问题讨论】:
-
这真的很宽泛,而且显然不仅仅是一个单独的问题,甚至是“几个问题”。但是我会回答你的#1,其余的你可能想用minimal examples 使用codepen 或jsfiddle 或其他东西在你得到#1 的平方之后分解成更简洁的问题。无论如何,您的 #1 是预期的,因为您尚未通过 document.registerElement 注册您的自定义 html 标签,所以无论您放入什么都不知道您在说什么,包括您的所见即所得编辑器......干杯! :)