我想用按鈕元素來替換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來添加外部容器是不可能的。一直在修補它。按鈕元素會縮小以適應其內容,除非它給出了明確的維度。 –