Javascript 带YUI的圆形输入框
是否可以使用YUI将所有输入框更改为圆角?我不能使用背景图像,因为输入将是可变宽度的,并且我不能添加环绕它们的div,因为生成了一些输入元素。此外,我不能使用边界半径或任何moz/webkit变体,因为它需要在IE6中显示相同Javascript 带YUI的圆形输入框,javascript,css,yui,Javascript,Css,Yui,是否可以使用YUI将所有输入框更改为圆角?我不能使用背景图像,因为输入将是可变宽度的,并且我不能添加环绕它们的div,因为生成了一些输入元素。此外,我不能使用边界半径或任何moz/webkit变体,因为它需要在IE6中显示相同 任何指针都值得欣赏,谢谢。可能是一个选择器,用于查找输入,然后用输入周围的div替换它们?在那里,YUI当然可以用于动态转换输入元素,如果需要,添加包装器div以支持您选择使用的方法 下面是一个文本-类型输入的圆角实现,使用角的背景图像: <html> &
任何指针都值得欣赏,谢谢。可能是一个选择器,用于查找输入,然后用输入周围的div替换它们?在那里,YUI当然可以用于动态转换
输入
元素,如果需要,添加包装器div
以支持您选择使用的方法
下面是一个文本
-类型输入
的圆角实现,使用角的背景图像:
<html>
<head>
<title>Stack Overflow 1471254</title>
<link rel="stylesheet" type="text/css" href="roundMyCorners.css">
<script type="text/javascript" src="http://yui.yahooapis.com/3.0.0b1/build/yui/yui-min.js"></script>
</head>
<body>
<p>Here is an input box: <input type="text" value="type stuff" class="roundMyCorners"> Thanks!</p>
<script type="text/javascript">
YUI({combine: true, timeout: 10000}).use("node", function(Y) {
Y.all('body input.roundMyCorners').each(function(rcInput) {
var outerDiv = Y.Node.create('<div class="roundMyCornersOuterDiv"></div>');
outerDiv.appendChild(Y.Node.create('<div class="tl"></div>'));
outerDiv.appendChild(Y.Node.create('<div class="tr"></div>'));
outerDiv.appendChild(rcInput.cloneNode());
outerDiv.appendChild(Y.Node.create('<div class="bl"></div>'));
outerDiv.appendChild(Y.Node.create('<div class="br"></div>'));
rcInput.get('parentNode').replaceChild( outerDiv, rcInput );
});
});
</script>
</body>
</html>
当然,tl
、tr
、bl
、br
甚至roundMyCornersOuterDiv
类的样式都可以通过JavaScript设置。为了清晰起见,我把它们留在了CSS中
请注意,如果要更改所有input
元素,只需将初始选择器从“body input.roundMyCorners
”更改为“input
”。但是,我不认为这对复选框和收音机类型的input
有效,因此如果您希望避免在所有地方都打上类名,那么“input[type=“text”]
”可能是一个更好的选择器
另一个注意事项是:由于input
是一个内联元素,所以我希望包装器div
是inline块
。这对我们来说是必不可少的。不幸的是,这需要一些专有的调整
最后,如果您不想对CSS大惊小怪或维护自己的YUI/jQuery/任何代码,您可以尝试或,这是声称自动完成这类工作的JavaScript库,至少对于div
s。您的里程可能会有所不同
.roundMyCorners {
width: 12em;
border: none;
font-weight: bold;
color: white;
background-color: #3f6daf;
}
.roundMyCornersOuterDiv {
position: relative;
display: -moz-inline-stack; /* inline-block for older Gecko */
display: inline-block;
*zoom: 1; /* force hasLayout for IE */
*display: inline; /* rendered as inline-block in IE after hasLayout */
vertical-align: middle;
padding: 6px;
color: white;
background-color: #3f6daf;
}
.roundMyCornersOuterDiv .tl {
position: absolute;
width: 6px;
height: 6px;
background: url(http://www.bestinclass.com/images/ui/rounded/colhead-tl.png) top left no-repeat;
top: 0;
left: 0;
}
.roundMyCornersOuterDiv .tr {
position: absolute;
width: 6px;
height: 6px;
background: url(http://www.bestinclass.com/images/ui/rounded/colhead-tr.png) top right no-repeat;
top: 0;
right: 0;
}
.roundMyCornersOuterDiv .bl {
position: absolute;
width: 6px;
height: 6px;
background: url(http://www.bestinclass.com/images/ui/rounded/colhead-bl.png) bottom left no-repeat;
bottom: 0;
left: 0;
}
.roundMyCornersOuterDiv .br {
position: absolute;
width: 6px;
height: 6px;
background: url(http://www.bestinclass.com/images/ui/rounded/colhead-br.png) bottom right no-repeat;
bottom: 0;
right: 0;
}