CSS: Inline element stretch to fill available horizontal space of container

前端 未结 3 1358
情书的邮戳
情书的邮戳 2021-02-05 07:16

For example I have a 200px div containing three buttons, the text is only minimal so the buttons don\'t fill the horizontal space available. Is it possible to..

3条回答
  •  梦毁少年i
    2021-02-05 08:13

    Can't you just set the widths like so...

    
    
    
    
    test css button stretch
    
    
    
    
    

    last button stretch...


    first button stretch...


    middle button stretch...

    This seems to get the desired effect, is fluid (if the div button container's width is changed or set to a %), and works in IE, Firefox and Opera.

    edit: removed the redundant btn class; bumped up the width % for the stretch class; added the doctype. Left the types on, could technically haved removed for just an example, but meh.

    @rpflo: the types are in there because my buttons in this example are not submit buttons. If these were part of a form and were submitting, I'd have left them off since the default is type=submit. (W3C HTML BUTTON)

提交回复
热议问题