我想用按钮元素来替换div元素,以提高可访问性,但我需要按钮来布局像divs用来做。 (注意这只需要在webkit中工作)强制按钮元素布局像div
div取父容器的宽度,而按钮仅占用显示其内容所需的位置。
我该如何改变这种情况?
我不想设置类似width:100%的东西,因为如果您在容器中使用多于一个按钮并显示:webkit-box div很好地布局以使用剩余空间。
这里是一个小例如:
<!DOCTYPE html>
<html>
<head>
<title>button test</title>
<style>
.mybutton{
display: block;
border: 1px solid red;
-webkit-appearance: none;
-webkit-border-radius: 6px;
background-color: transparent;
-webkit-gradient(linear,left bottom,left top,color-stop(0, #A8ACB9),color-stop(1, #eee));
text-align: center;
}
</style>
</head>
<body>
<div class="mybutton">Div Button</div>
<button class="mybutton">Button</button>
</body>
</html>
我不能添加容器。我需要按钮在我的小示例中布局相同,而不更改dom结构 –
似乎不改变DOM来添加外部容器是不可能的。一直在修补它。按钮元素会缩小以适应其内容,除非它给出了明确的维度。 –