分组按钮不适合整个宽度

时间:2012-09-27 17:02:00

标签: html css jquery-mobile

<div data-role="header" id="commonHead">
    <div data-role="navbar">
        <h3 id="pageHeaderH1" alt="my root way to home" style="text-align:center;">myRWTH</h3> 
        <div data-role="controlgroup"  data-type="horizontal">
            <a href="index.html" data-role="button">Yes</a>
            <a href="index.html" data-role="button">No</a>
            <a href="index.html" data-role="button">Maybe</a>
        </div>
     </div>
</div> 

这是我的代码,但按钮不适合内容宽度,但是与左侧对齐。我不明白为什么我不工作。有什么想法吗?

更新:我不知道为什么,但它不起作用。我的解决方法如下

<div data-role="header" id="commonHead" data-theme="b" >
    <div data-role="navbar" data-iconpos="right">
        <h3 id="pageHeaderH1" alt="my root way to home" style="text-align:center;" data-mini="true">myRWTH</h3> 
        <ul>     
         <li><a href="#popupBasic" data-rel="popup" data-type="vertical"  data-icon="gear" data-iconpos="bottom">Anzeigeoptionen</a>    
            <div data-role="popup" id="popupBasic" data-theme="b">
                <a id="ownPosition" data-role="button" data-icon="home" data-inline="true">Eigene Position</a>
                <a id="ownPosition" data-role="button" data-icon="minus" data-inline="true">Mensen</a>
                <a id="ownPosition" data-role="button" data-icon="minus" data-inline="true">HSP</a>
                <a id="ownPosition" data-role="button" data-icon="minus" data-inline="true">Gebäude</a>
                <a id="ownPosition" data-role="button" data-icon="minus" data-inline="true">Haltestellen</a>
                <a id="ownPosition" data-icon="delete" data-icon="home" data-inline="true">Alle ausblenden</a>
            </div> 
        </li>
         </ul>
     </div>
</div> 

3 个答案:

答案 0 :(得分:0)

这样做的方法很多,其中之一是:

<div data-role="header" id="commonHead">
    <div data-role="navbar">
        <h3 id="pageHeaderH1" alt="my root way to home" style="text-align:center;">myRWTH</h3> 
        <div data-role="controlgroup"  data-type="horizontal">
            <div style="width: 33%; float: left; text-align: center">
            <a href="index.html" data-role="button">Yes</a>
            </div>
            <div style="width: 33%; float: left; text-align: center">
            <a href="index.html" data-role="button" style="width: 33%">No</a>
            </div>
            <div style="width: 33%; float: left; text-align: center">
            <a href="index.html" data-role="button" style="width: 33%">Maybe</a>
            </div>
        </div>
     </div>
</div> ​

答案 1 :(得分:0)

尝试单独向按钮添加data-type="horizontal"Manual

 <div data-role="header" id="commonHead">
 <div data-role="navbar">
    <h3 id="pageHeaderH1" alt="my root way to home" style="text-align:center;">myRWTH</h3> 
    <div data-role="controlgroup" >
        <a href="index.html" data-role="button" data-type="horizontal">Yes</a>
        <a href="index.html" data-role="button" data-type="horizontal">No</a>
        <a href="index.html" data-role="button" data-type="horizontal">Maybe</a>
    </div>
 </div>

答案 2 :(得分:0)

你可能需要调整它,这是一个黑客:

JS:

// override the jQM CSS
var cbnb = $('#customButtonNavbar');
var numberOfButtons = ($('.customButton').length > 0) ? $('.customButton').length:1;
var widthOfButtons = (Math.round(100 / numberOfButtons));

cbnb.children('.ui-controlgroup-controls').attr('style', 'width:100%;');
cbnb.children().children().attr('style', 'width:'+widthOfButtons+'%;');

HTML:

<div data-role="header" id="commonHead">
    <div data-role="navbar">
        <h3 id="pageHeaderH1" alt="my root way to home" style="text-align:center;">myRWTH</h3> 
        <div data-role="controlgroup" data-type="horizontal" id="customButtonNavbar">
            <a href="index.html" data-role="button" class="customButton">Yes</a>
            <a href="index.html" data-role="button" class="customButton">No</a>
            <a href="index.html" data-role="button" class="customButton">Maybe</a>
        </div>
     </div>
</div>​