CSS非常棘手的问题:Xhtml的高度问题
好吧,问题很简单:
我有一个可变宽度和高度的 div,我想在它旁边放置另一个“元素”,它基本上是一个由 3 个组件组成的条形(顶部固定、中间可变高度、底部固定) )就像任何滚动条一样。而且,就像任何滚动条一样,我希望始终是它“附加”到的 div 的大小,无论其大小以及何时调整大小。
下面的代码就是这样做的(我还没有找到更好的方法,如果你找到了,请告诉我:))
但现在这就是窍门。如果您将文件名从 test.html 更改为 test.xhtml(就是这样!),它将停止工作。查看示例(在 Firefox 中)并亲自查看(在 Chrome 中它可以工作)
http://stefan .apsaa.eu/test/test.html - 然后只需在 test.html 前面放一个“x”,然后再次按 Enter 键......在 Firefox 中......
所以。如果你们知道如何修复它,或者知道一种同时适用于 xhtml 和 html 的更好方法,我将不胜感激
只是说清楚:我想要一个可变的宽度和高度:)(滚动条仅作为示例给出)
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE xhtml PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg" xml:lang="en-ca">
<head>
<style>
.handle{
width : 5px;
height : 100% !important;
margin : 0;
padding : 0;
overflow : hidden;
}
.handle a{
position : relative;
display : inline-block !important;
height : 100% !important;
text-decoration : none;
}
.handle a:hover{
height : 100% !important;
}
.handle-top{
background : url(images/borders/standard/border-top.png) no-repeat 0 0;
height : 100% !important;
}
.handle-middle{
background : url(images/borders/standard/border-mid.png) repeat-y 0 0;
height : 100% !important;
}
.handle-bottom{
background : url(images/borders/standard/border-bot.png) no-repeat 0 100%;
height : 100% !important;
}
</style>
</head>
<body>
<table cellspacing="0" cellpadding="0" class="wrapper" style="margin: 0px;">
<tbody>
<tr>
<td class="handle">
<a href="#">
<div class="handle-top">
<div class="handle-bottom">
<div class="handle-middle">!</div>
</div>
</div>
</a>
</td>
<td width="100%" class="contentHolder">
<div class="section tCollapsible" style="margin: 0px;">
<h4>This is a DIV</h4>
Test<br />asdsa
</div>
</td>
</tr>
</tbody>
</table>
</body>
</html>
Ok so the question is simple:
I have a variable width and height div and I want to position next to it another "element" which is basically a bar made up of 3 components (top-fixed, middle-variable height, bottom-fixed) just like any scrollbar. And, just like any scrollbar, i want to to always be the size of the div it is "attached" to, regardless of its size and when it resizes.
The code bellow does that (i haven't found a better way, if you do, please tell me :) )
But now here's the trick. If you change the name of the file from test.html to test.xhtml (that's it!) it stops working. Check out the example (in Firefox) and see for yourselves (in Chrome it works)
http://stefan.apsaa.eu/test/test.html - then simply put an "x" in front of the test.html and hit enter again.... in firefox....
so. if you guys know how to fix it, or know a better way that works with both xhtml and html, i'd be grateful
Just to be clear: I want a VARIABLE WIDTH and HEIGHT :) (the scrollbar was given just as an example)
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE xhtml PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:svg="http://www.w3.org/2000/svg" xml:lang="en-ca">
<head>
<style>
.handle{
width : 5px;
height : 100% !important;
margin : 0;
padding : 0;
overflow : hidden;
}
.handle a{
position : relative;
display : inline-block !important;
height : 100% !important;
text-decoration : none;
}
.handle a:hover{
height : 100% !important;
}
.handle-top{
background : url(images/borders/standard/border-top.png) no-repeat 0 0;
height : 100% !important;
}
.handle-middle{
background : url(images/borders/standard/border-mid.png) repeat-y 0 0;
height : 100% !important;
}
.handle-bottom{
background : url(images/borders/standard/border-bot.png) no-repeat 0 100%;
height : 100% !important;
}
</style>
</head>
<body>
<table cellspacing="0" cellpadding="0" class="wrapper" style="margin: 0px;">
<tbody>
<tr>
<td class="handle">
<a href="#">
<div class="handle-top">
<div class="handle-bottom">
<div class="handle-middle">!</div>
</div>
</div>
</a>
</td>
<td width="100%" class="contentHolder">
<div class="section tCollapsible" style="margin: 0px;">
<h4>This is a DIV</h4>
Test<br />asdsa
</div>
</td>
</tr>
</tbody>
</table>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的服务器正在为具有普通“.html”扩展名的文件发送“Content-Type”“text/html”,并为“.xhtml”文件发送“application/xhtml+xml”。这导致 Firefox 更加严格地对待文档。
W3C 验证器投诉您的页面。
Your server is sending a "Content-Type" of "text/html" for the file with a plain ".html" extension, and "application/xhtml+xml" for the ".xhtml" file. That's causing Firefox to treat the document more strictly.
The W3C validator complains about your page.
如果你有这样的标记:
像这样的 CSS 应该可以工作:
更新:
好的,以下是如何修改它,使其可变高度(被滚动条的东西混淆了):
更新 2: :
使用您发布的相同 CSS 类更新了示例
If you have markup like this:
CSS like this should work:
Update:
OK, here's how to modify it so it's variable-height (was confused by the scroll bar thing):
Update 2:
Updated sample using the same CSS classes you posted: