圆角输入按钮、绝对定位、液体宽度
我意识到有很多圆形按钮问题,但我的需求相当具体,并且其他地方还没有得到解答。
这是我的要求:
- 使用绝对定位的按钮
- 仅客户端技术(无法在服务器端更改 HTML)
- 适用于输入类型 = 按钮和输入类型 = 提交(不需要按钮元素)
- 固定高度,液体宽度
- 支持 IE7 或更高
版本在我看来,绝对定位+客户端只会使大多数圆角技术无法使用。
有图像或没有图像并不重要(无论哪种方式都可以)。允许使用 JavaScript。
编辑:更改问题以反映实际问题:我认为我需要的一个 HTML 元素并不是真正的要求。
I realize there are lots of rounded buttons questions, but my needs are fairly specific, and this hasn't been answered elsewhere.
Here's my requirements:
- Works with absolutely positioned buttons
- Client side only techniques ( can't change HTML on server side )
- Works on input type=button and input type=submit (button element not needed)
- Fixed height, liquid width
- Supports IE7 or better
The absolute positioning + client side only makes most rounded corner techniques unusable in my opinion.
Images or no images does not matter (either way is fine). JavaScript is allowed.
EDIT: Changed question to reflect actual problem: the one HTML element I thought I needed wasn't really the requirement.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于IE来说这是不可能的。这就是为什么你在其他地方找不到它。您唯一可以做的就是使用静态背景图像,但这会拉伸不同的宽度。
It's not possible for IE. That's why you can't find it anywhere else. The only thing you could do is use a static background image, but that will stretch for different widths.
我最终为按钮使用了多个背景。
CSS3 浏览器的多个背景可以处理这个问题,在 IE 中,我使用 DXTransform 过滤器添加第二个图像(请参阅 此处)。实际使用的技术是相当标准的滑动门样式设置,并进行了一些更改,以考虑到您无法将 IE 中的第二个图像放置在左上角以外的位置。
对于 FF 3.5 及更低版本,我使用了 border-radius,因为 3.6 中才出现多个背景。
悬停/活动图像运行良好,而且全部采用 CSS,这是一个额外的好处。
I ended up using multiple backgrounds for the buttons.
CSS3 multiple backgrounds for browsers that could handle that, and in IE I used the DXTransform filter to add a second image (see here). The actual technique used was a pretty standard sliding door style setup, with some changes to account for the fact that you couldn't position the second image in IE other than at the top left.
For FF 3.5 and lower I used border-radius, since multiple backgrounds only came in 3.6.
Hover/active images worked fine, and it's all in CSS, which was a bonus.
由于允许使用 javascript(根据您的评论之一),我不认为以下操作会对性能产生重大影响:
div
包装input
元素input
的定位属性并将其复制到div
包装器,position: staticinput
的定位code>Css:
假设您的 javascript 为您提供以下 html:
您将需要设置输入样式以消除边框等(我还发现我在 Firefox 中的测试要求我设置
vertical-align: top
,但不确定是否有必要。对于 IE6-7,实际上,您必须在input
之前和之后添加额外的 div,因为它们无法识别:before
和:after
伪类。Since javascript is allowed (based on one of your comments), I don't see how it would be a big performance hit to:
input
elements withdiv
input
and copy them to thediv
wrapperinput
using an inlineposition: static
Css:
Assuming your javascript gives you this html:
You will need to style the input to get rid of borders, and such (I also found that my test in Firefox required me to set
vertical-align: top
, but not sure if that is necessary. For IE6-7, you would actually have to add extra div's before and after theinput
since they do not recognize the:before
and:after
pseudo-classes.