user2076941
user2076941

Reputation: 153

center text in select in webview ios

Im trying to center text in my select. I've got it working in safari using text-align:-webkit-center; (text-align:center; does nothing). But when I run text-align:-webkit-center; in my phonegap webview, the text isnt centered.

Has anyone manged to center text in a select box in a webview in phonegap?

Ps. Center is center horizontal, not vertical Ds.

Thanks!

Upvotes: 2

Views: 1449

Answers (2)

jup31
jup31

Reputation: 53

Just adding the solution I found to do that on webview. If you didn't find any solution, you can use this trick on angularjs or using js to map selected value with a text on the div, this solution is full css compliant on angular but need a mapping between select and 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>

Hope this could be useful for someone as it took me one day to find this solution on phonegap.

Upvotes: 0

jup31
jup31

Reputation: 53

Same issue for me, I solved this issue in android using text-align-last: center; but not yet a solution for ios webview.

Upvotes: 2

Related Questions