开发者

How to set an auto width to a div that is a background for a button

开发者 https://www.devze.com 2023-03-16 15:17 出处:网络
I am attempting to put a div around the buttons in my app. The divs should have a 5px padding around the button. However, the div keeps spanning the entire width of the page unless i set the width wit

I am attempting to put a div around the buttons in my app. The divs should have a 5px padding around the button. However, the div keeps spanning the entire width of the page unless i set the width with a number. Obviously it would be much easier to have an 'auto' width for every div instead of specifying width for each individua开发者_运维知识库l button. Is there any way to do this?

stylesheet:

.button_div {width: auto; height: auto; border-radius: 10px; padding: 5px;}

view:

<div class="button_div">

Thanks!


The 'auto' width for a div is for the div to take up the full width. Div's are block-level by default.

To get a div to collapse down to the size of its contents, you need to either float it, or set the display to inline-block.


why dont you use

<button class="someClass"/>

.someClass {padding: 5px;}
0

精彩评论

暂无评论...
验证码 换一张
取 消