0

I have the following piece of code that generate a jquerymobile-style button

<a href="#" data-role="button"  
        data-theme="b" id="svbutton" style="position: absolute; top: 30%; margin-left: 0%;margin-right: 0%;  width: 80%; height: 20%; text-align: center;  font-size: 2.50em">Load Time...</a>

It is true that when the screen get re-scaled, the size of the button will change. However the size of the text does not change. Is there a way to change the size according to the size of the device-screen?

4

2 回答 2

1

您可以读取文档的宽度或按钮的宽度,然后使按钮的字体大小相对于该宽度,例如:

var buttonWidth = $('#svbutton').width();
var fontSize = buttonWidth / 10;
$('#svbutton').css('font-size', fontSize + 'px');

JSFiddle
http://jsfiddle.net/VFube/1

于 2012-06-19T18:52:05.547 回答
0

现场示例:

JS:

// For all buttons use something like this
$('.ui-btn').css('width','50%');

// For individual buttons use something like this
$('#theButton1').parent().css('width', '75%');

// Or this for HREF data-role buttons
$('#hrefButton4').css('width', '45%');

我想这就是你要找的

// this changes the height for all buttons
$('.ui-btn-text').css('font-size','50px');

// This changes the height for a single element 
$('#hrefButton3').children().children().css('font-size','30px');

HTML:

<div data-role="page" id="home"> 
    <div data-role="content">
        <input type="button" id="theButton1" value="Press Me 1" />
        <input type="button" id="theButton2" value="Press Me 2" />
        <input type="button" id="theButton3" value="Press Me 3" />
        <input type="button" id="theButton4" value="Press Me 4" />
        <br />
        <a href="#" data-role="button" id="hrefButton1">HREF Me 1</a>
        <a href="#" data-role="button" id="hrefButton2">HREF Me 2</a>
        <a href="#" data-role="button" id="hrefButton3">HREF Me 3</a>
        <a href="#" data-role="button" id="hrefButton4">HREF Me 4</a>
    </div>
</div>

有关的:

于 2012-06-20T01:11:15.760 回答