2012-02-24 43 views
6

我遇到了一個奇怪的行爲與jQuery Mobile中的文本輸入的寬度有關 - 它太簡單了。奇怪的寬度的文本輸入在jQuery Mobile

<div data-role="page"> 
    <div data-role="header"> 
     <h1>Test</h1> 
    </div> 

    <div data-role="content"> 
     <input type="text" value="192.168.1.1"></input> 

     <a data-role="button">Connect</a> 
    </div> 
</div> 

也可以通過在jsFiddle中減小browserwindow的寬度來重現此行爲。

的jsfiddle:
http://jsfiddle.net/QxYMa/

這是正常的行爲,或只是一個錯誤?我該如何「糾正」,以便文本輸入和按鈕具有相同的寬度?

+2

IMG鏈路斷開時 – nickdos 2012-02-24 19:49:11

回答

6

輸入和按鈕有一些不同的CSS自動應用到它。我增加了以下CSS這似乎讓CSS對他們倆的明顯是一致的:

<div data-role="page"> 
    <div data-role="header"> 
     <h1>Test</h1> 
    </div> 

    <div data-role="content"> 
     <input type="text" value="192.168.1.1" style="width:100%;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing: border-box;"/> 
     <br/> 
     <a data-role="button" style="width:100%;margin:0">Connect</a> 
    </div> 
</div> 

這樣看來,在輸入框的模式被關閉,並且按鈕利潤率爲關閉。 這裏是一個很好的文章,談論盒模型似乎在這方面略顯淡化:http://www.jefftk.com/news/2012-02-18.html

希望這有助於!

+0

我會帶班取代內嵌樣式。 – jrummell 2012-02-24 20:01:34

+1

謝謝!這實際上是一篇非常有趣的文章,你在文章中已經鏈接過。我已經修復了代碼中的兩個小錯別字,它實際上可行 - 但不知何故,我覺得它有點「黑客」。我會等一會兒,也許別人有更好的解決方案。 – 2012-02-24 20:17:29

1

在我的核心jquery mobile structure.css開始之前,我添加了一個更完整的CSS重置。這可能會幫助你。

/* CSS Reset*/html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td {margin:0;padding:0;border:0;outline:0; font-size:100%;vertical-align:baseline; background:transparent}body {line-height:1}ol,ul {list-style:none}blockquote,q {quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus {outline:0}ins {text-decoration:none}del {text-decoration:line-through}table {border-collapse:collapse;border-spacing:0} 
+0

我已經添加了它,並沒有幫助:http://jsfiddle.net/eKkjp/ - 無論如何,你從哪裏得到了reset.css,我實際上使用了Eric Meyer的一個。 – 2012-02-26 11:27:14

+0

這是我發現的一個修改版本,後面最初是基於Eric的。我相信我刪除了一些我從不傾向於使用的東西。 – imaginethepoet 2012-02-27 02:12:50

+0

您可能還想要直接修改輸入尺寸。我通過向想要改變尺寸的元素添加類值來做到這一點。奇怪的是我實際上認爲其中一些太小 - 所以我增加了它們的高度。 – imaginethepoet 2012-02-27 02:14:25

1

就像一個例子你可以添加一個新的主題。在下面的例子中,我添加了一個主題F.向主題添加更多css,然後在您的輸入元素上調用data-theme =「f」。然後,您可以將它設計爲您的內容。有一點需要注意。您可能需要使用!important來覆蓋由JQM設置的基本大小。

.ui-bar-f input { 
    font-family: 'HelveticaNeueLTStd55Roman', Helvetica, Arial, sans-serif; 
    width:250px !important; 
} 
+0

你能否提供一個基於設備尺寸的工作jsFidde寬度?使用固定寬度不適合我。 – 2012-02-28 21:07:31

+0

您試圖設定哪個設備 - 您可能需要按百分比進行設置 - 或根據設備的最小/最大值。 – imaginethepoet 2012-02-28 21:10:40

+0

基於Android的中高端設備以及後來的iOS設備。 – 2012-02-29 14:44:58

0

輸入字段只是想成爲全角。設置寬度:80px但是會限制它們的寬度。用普通和迷你版本的線條看這個小提琴。

http://jsfiddle.net/den232/WzH3Y/

.floatleft { 
    float:left; 
} 
.floatright { 
    float:right; 
} 
.forceinline{ /* Prevent fieldcontain from doing a BLOCK thing */ 
    display:inline !important; 
} 
.textwidth { /* limit width of input fields */ 
    width:80px; 
} 
.closespacing { /* controls spacing between elements */ 
    margin:0px 5px 0px 0px; 
} 
.bigselect { /* centers select with big buttons */ 
    padding: 0px; 
    margin:2px 5px 0px 0px; 
} 
.biginputheight { /* matches text input height to big buttons */ 
    padding-top:10px !important; 
    padding-bottom:12px !important; 
} 
.miniinputheight { /* matches text input height to minibuttons */ 
    padding-top:5px !important; 
    padding-bottom:5px !important; 
} 
<div data-role="page" class="type-home"> 

<ul data-role="listview"> 
    <li data-role="fieldcontain">first LI line</li> 
    <li data-role="fieldcontain"> 

    <div class='floatleft closespacing'> 
     Big Buttons<br>More Text 
    </div> 


    <div class='floatleft textwidth'> 
     <input type="text" placeholder="left" class='biginputheight'></input> 
    </div> 

    <div class='floatright textwidth'> 
     <input type="text" placeholder="right" class='biginputheight'></input> 
    </div> 

    </li> 
    <li data-role="fieldcontain"> 

    <div class='floatleft closespacing'>  
     Small Buttons 
    </div> 


    <div class='floatleft textwidth'> 
     <input type="text" placeholder="e2" class='miniinputheight'></input> 
    </div> 


    <div class='floatright closespacing'> 
     <div class='floatright closespacing'>  
     e3 Text<br>on right 
     </div> 
     <div class='floatright textwidth'> 
     <input type="text" placeholder="e3" class='miniinputheight'></input> 
     </div> 
    </div> 
    </li> 
    <li data-role="fieldcontain">last LI line</li> 

</ul><!-- /listview --> 

+0

很多與文本輸入有關的東西已經在最新版本的jquery mobile中發生了變化 - 因此問題不再相關,因爲它現在應該可以工作。儘管如此,你的答案並沒有以任何方式回答原始問題。 – 2012-10-24 06:49:27