RogerWu
RogerWu

Reputation: 71

how to let jquery mobile controlgroup width 100%?

i'm useing jquery mobile to do a demo... i want to let the width of localnav be 100%... but i don't know how to do that... code here...

<ul data-role="controlgroup" data-type="horizontal" class="localnav">
    <li><a href="#" data-role="button" data-transition="fade" class="ui-btn-active">111</a></li>
    <li><a href="#" data-role="button" data-transition="fade">222</a></li>
    <li><a href="#" data-role="button" data-transition="fade">333</a></li>
</ul>

help me pls...thank you...

Upvotes: 7

Views: 18264

Answers (4)

Kyle Duncan
Kyle Duncan

Reputation: 59

Take a look at JQuery Mobile's navbar Though it's normally used in a header/footer, it can be used elsewhere. It will produce a full-width bar containing your buttons.

       <div data-role="navbar">
            <ul>
                <li><a href="#" data-icon="plus" data-role="button">Button1</a></li>
                <li><a href="#" data-icon="minus" data-role="button">Button2</a></li>
                <li><a href="#" data-icon="check" data-role="button">Button3</a></li>
            </ul>
        </div>

Upvotes: 5

joey_g216
joey_g216

Reputation: 796

Here's what I did. Worked well.

CSS:

<style>
    .ui-grid-a, .ui-grid-a .ui-controlgroup-controls {width: 100%}
    #homePageButton {width:49%;float:left;margin-left:1%}
    #logOutButton {width:49%}
    #footer {height:45px}
</style>

HTML:

<div data-role="footer" data-position="fixed" id="footer">
    <div data-role="controlgroup" data-type="horizontal" class="ui-grid-a">
        <a href="#" data-role="button" data-icon="home" id="homePageButton">Home Page</a>
        <a href="#" data-role="button" data-icon="forward" data-iconpos="right" id="logOutButton">Log Out</a>
    </div>
</div>

Result: enter image description here

Upvotes: 5

bazzargh
bazzargh

Reputation: 1842

I'm using a grid to do this, and one extra css rule:

.ui-controlgroup-horizontal > div > .ui-btn {
    width: 99%
}​​​​​​​​​ 

The reason I'm doing this is that the markup like this:

<div class="ui-grid-a" data-role="controlgroup" data-type="horizontal">
    <div class="ui-block-a">
         <button type="submit" data-theme="c">Cancel</button>
    </div>
    <!-- etc -->
</div>

Is transformed by jquery into markup like this (inspect it in Chrome or Firebug):

   <div class="ui-grid-a ui-corner-all 
       ui-controlgroup ui-controlgroup-horizontal" 
       data-role="controlgroup" data-type="horizontal">
       <div class="ui-block-a">
           <div data-corners="true" data-shadow="true" 
             data-iconshadow="true" data-inline="null" 
             data-wrapperels="span" data-icon="null" data-iconpos="null" 
             data-theme="c" data-mini="false" 
             class="ui-btn ui-btn-up-c ui-corner-left" 
             aria-disabled="false">
               <span class="ui-btn-inner ui-corner-left">
                   <span class="ui-btn-text">Cancel</span>
               </span>
               <button type="submit" data-theme="c" class="ui-btn-hidden" aria-disabled="false">Cancel</button>
           </div>
       </div>
       <!-- etc -->
   </div>

As you can see, the .ui-btn we want to be 100% wide is inside ui-block-a (or ui-block-b, ui-block-c, etc.), and our horizontal control group has gained the class .ui-controlgroup-horizontal, hence the rule: .ui-btn children of divs children of .ui-controlgroup-horizontal are made (nearly) 100%. I stop short of 100% because this chops the rounded corners on the right hand button for me. By using .ui-controlgroup-horizontal on the top class, and not (say) ui-grid-a, this rule works for different grid sizes.

Upvotes: 1

Nirmal Patel
Nirmal Patel

Reputation: 5168

Not sure why you are trying to wrap a <ul> as a controlgroup. But you can have a full-width ControlGroup with the following approach:

<div data-role="controlgroup" data-type="horizontal" class="localnav">
    <a href="#" data-role="button" data-transition="fade" class="ui-btn-active">111</a>
    <a href="#" data-role="button" data-transition="fade">222</a>
    <a href="#" data-role="button" data-transition="fade">333</a>
</div>

And in CSS, split the width equally among the number of <a> elements:

a{width:33%;}

Sample jsfiddle: http://jsfiddle.net/pAuqm/1/

If you want to continue with <ul> based structure; you could have full width controlgroup with following CSS:

li{
    display: inline;
}
a{width:33%;}

Sample jsfiddle: http://jsfiddle.net/pAuqm/3/

Upvotes: 2

Related Questions