2013-10-15 35 views
2

我試圖在我的選擇中居中文本。我使用文本對齊方式在safari中工作:-webkit-center; (text-align:center;什麼都不做)。但是當我運行文本對齊:-webkit-center;在我的phonegap webview中,文本並不居中。在webview中選擇中心文本ios

有沒有人在手機中的webview中的選擇框中居中文本?

Ps。中心是水平中心,而不是垂直Ds。

謝謝!

回答

2

對我來說同樣的問題,我解決了這個問題在android中使用text-align-last: center;,但還沒有解決方案的ios webview。

0

只需添加我在webview上發現的解決方案。如果您沒有找到任何解決方案,您可以在angularjs上使用這個技巧或使用js將選定值與div上的文本進行映射,此解決方案是完全符合角度的CSS,但需要選擇和div之間的映射:

var myApp = angular.module('myApp', []); 
 

 
myApp.controller('selectCtrl', ['$scope', 
 
    function($scope) { 
 
    $scope.value = ''; 
 
    } 
 
]);
.ghostSelect { 
 
    opacity: 0.1; 
 
    /* Should be 0 to avoid the select visibility but not visibility:hidden*/ 
 
    display: block; 
 
    width: 200px; 
 
    position: absolute; 
 
} 
 
.select { 
 
    border: 1px solid black; 
 
    height: 20px; 
 
    width: 200px; 
 
    text-align: center; 
 
    border-radius: 5px; 
 
    display: block; 
 
}
<!doctype html> 
 
<html lang="en"> 
 

 
<head> 
 
    <meta charset="UTF-8"> 
 
    <title>Example - example-guide-concepts-1-production</title> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
</head> 
 
<body ng-app="myApp"> 
 
    <div ng-app ng-controller="selectCtrl"> 
 
    <div class=select> 
 
     <select ng-model="value" class="ghostSelect"> 
 
     <option value="Option 1">Option 1</option> 
 
     <option value="Option 2">Option 2</option> 
 
     <option value="Option 3">Option 3</option> 
 
     </select> 
 
     <div>{{value}} 
 
     </div> 
 
    </div> 
 
    </div> 
 
</body>

希望爲我花了一天的時間找到PhoneGap的這一解決方案,這可能是有用的人。