- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
编辑:目标浏览器为IE10以上;无需与其他浏览器兼容。
在页面的 header
中,我有 3 个元素(这也是顺序):
Here is a JSFiddle对于那些等不及的人 ;)
header
本身是 60px
高,元素应该垂直居中并且“ float ”在左边。我无法在它们上使用 float: left
让它工作,因为我不是很擅长纯 CSS 布局,所以我实用地插入了一个 table
来实现它工作。
除了一个烦人的 1px
大问题外,它的工作原理是:li
项(即可点击的菜单栏项)有一个 1px
从页面顶部偏移,因此在 header
内没有完美对齐,而是延伸到 #content
。所以我的问题是:
table
的边界问题,但看起来并非如此.可能是因为 line-height
?table
,我怎么能实现我想要的布局,因为我经常读到它是一种非常糟糕的风格?<这是我使用的 HTML:
<body>
<header>
<table>
<tr>
<td style="vertical-align: middle">
<img class="logo" src="http://doc.jsfiddle.net/_downloads/jsfiddle-logo-white.png" />
</td>
<td>
<label class="title">Title</label>
</td>
<td>
<div class="menu">
<ul>
<li>Home</li>
<li>Test
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</li>
<li>About</li>
</ul>
</div>
</td>
</tr>
</table>
</header>
<div id="content"></div>
<footer>Footer</footer>
</body>
这是 CSS:
/* ------ General layout ------ */
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
font-family: Verdana;
font-size: 12px;
}
header {
width: 100%;
height: 60px;
background-color: #eeeeee;
position: fixed;
top: 0;
}
#content {
width: 90%;
margin: 0 auto;
padding-top: 70px;
/* header height + 10 */
padding-bottom: 50px;
/* footer height + 10 */
}
footer {
width: 100%;
height: 40px;
line-height: 40px;
background-color: #eeeeee;
position: fixed;
bottom: 0;
text-align: center;
}
.logo {
resize: both;
height: 30px;
margin-left: 20px;
margin-right: 20px;
}
.title {
font-weight: bold;
color: green;
margin-right: 20px;
}
/* ------ CSS-based menu bar attempt ------ */
table {
width: 100%;
height: 100%;
border-collapse: collapse;
}
table td:last-child {
width: 100%;
}
.menu ul {
line-height: 60px;
text-align: left;
margin: 0;
padding: 0;
list-style: none;
}
.menu ul li {
display: inline-block;
margin-right: -4px;
position: relative;
padding: 0 20px;
cursor: pointer;
transition: all 0.2s;
}
.menu ul li:hover {
background: #555;
color: #fff;
}
.menu ul li ul {
padding: 0;
position: absolute;
top: 100%;
left: 0;
width: 160%;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
transition: opacity 0.2s;
}
.menu ul li ul li {
background: #555;
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
}
.menu ul li ul li:hover {
background: #666;
}
.menu ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
最佳答案
如果您检查您的页面(使用 Firebug、Chrome 开发者工具或类似的东西),您可以看到 td
里面堆放了您的 li
元素(以及你所有其他的 td
s) 都有一个 1px 的填充,这是困扰你的像素的来源。恐怕我不能真正告诉你这个填充是从哪里来的,因为我在检查器中看不到它的规则,所以我假设它只是表/tds 的默认呈现。您可以添加如下规则来覆盖它:
td {
padding: 0;
}
理想情况下,您还应该在表格上使用 CSS 类,并在 CSS 中使用它以仅针对这些特定的 td
,以防您需要将不同的规则应用于页面中的另一个表格。
关于html - 表格内基于 CSS 的菜单栏 : li's are 1px off; problems with the table border?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30297331/
我很绝望,现在已经两天(!!)天都没有解决方案来解决以下问题。 更新 Lion 后,我想使用最新版本的 rvm 安装额外的 rubies。 这是我之后调用 bundler 时发生的情况: /Users
我的问题: ajax 调用的无限循环会产生问题吗? 假设有这样的代码: ajaxcall(); function ajaxcall(){ jQuery.ajax({ typ
这是一个有趣的小项目,我已经开始尝试并最大限度地提高赢得办公室曲棍球池的机会。我试图找到最好的方法来选择 20 名能够在最高工资帽内给我最多分数的球员。 例如,假设原始数据由 玩家姓名 位置(前锋,后
我有一个总数为540000的数字列表。我想将此列表分为3个列表,每个列表总共180000。最有效的编程方法是这样做,假设数字列表是一个平面文件,每个数字为线? 最佳答案 听起来像Knapsack pr
抱歉,也许因为我不是英语,我不知道,但我找不到解决几个问题的任何资源;也许我用的词不正确.. 我想了解有关 iPhone 4 和 5 不同分辨率的更多信息。 首先:如果我开发针对 iPhone 4 分
在全局配置缓存后,如 docs ,如果我在 app.module 之外使用 CacheInterceptor,它会抛出错误。 app.module.ts const cacheConfig = {
我无法让 g:each 工作。我正在尝试遍历任何内容,但它永远不起作用 = 不生成任何 html。 索引.gsp Item ${i.name} 用户 Controller .g
在我的 XAML 文件中,我有一个这样声明的 ListBox:
想知道你是否可以帮助我: 我有一个名为initializeAll的方法: public final void initializeAll() { //other stuff........ rand
我尝试过使用 XML 和 JAVA 在我的 Android Activity 中创建一个 ImageView。这两次,我都能够获取我一天前创建的所有其他 PNG 资源以显示在 ImageView 中。
我需要你的帮助。这是什么意思? Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'
这是一段代码 function test() { this.value = "foo"; } $(document).ready(function () { test();
这是一些非常基础的东西。渲染期间引发异常:java.util.Locale.toLanguageTag()Ljava/lang/String; XML: 问题似乎出在 Edit
除其他来源外,我还使用 Stackoverflow 上的各种帖子,尝试实现我自己的 PHP 分类器,以将推文分类为正面、中性和负面类别。在编码之前,我需要弄清楚流程。我的思路和例子如下:
在过去的几周里,每当我在 Eclipse 上使用 SVN 插件时,我都会收到以下错误: Certificate Problem There is a problem with the site's s
我被拒绝运行以下功能(位于 /var/www/mysite/public_html/app/Controllers/Script.php) $structure = '/var/www/mysite/
我正在使用 ctags 为我的 Emacs 创建标签以使用 cygwin 从中读取符号。 Emacs 说 “访问标签表缓冲区:文件/home/superman/tags 不是有效的标签表” 这是我查找
我知道作为一种函数式语言,XSL 没有像传统的 for 循环(而是 for-each)那样的东西。 我正在尝试从可变数量的元素开始创建一个具有固定数量 (7) 的表。总之,我有
我正在使用RavenDB进行一些测试,以基于iphone应用程序存储数据。该应用程序将发送一个带有GPS key 的5个GPS坐标的字符串。我在RavenDB中看到每个文档约为664-668字节。这是
我无法理解我的应用程序的行为。我想创建一个简单的窗口 (1000x700px),分为两部分(分别为 250px 和 750px 宽度)。我尝试了以下代码: import java.awt.Color;
我是一名优秀的程序员,十分优秀!