LoginSignup
12
10

More than 5 years have passed since last update.

スマホでselectのテキストは左右中央にできるのか

Last updated at Posted at 2014-07-14

ぐぐったらtext-align: -webkit-center;で左右中央にできるというのでやってみたけれど、iOS7・iOS8で効かなかった・・・

参考:http://www.yoheim.net/blog.php?q=20121007

bugfix

試行錯誤したら動いた。
※iPhoneと同じCSSだとAndroidで動かない(labelクリックしてもselectが開かない?)。

<label>
    <select>
        <option>選択1だよ〜</option>
        <option>選択2だよ〜</option>
        <option>選択3だよ〜</option>
    </select>
</label>
select { //Android
    text-align: center;
}

@media screen and (max-device-width: 480px) { //iPhone
    label {
        display: -webkit-box;
        display: box;
        box-pack:center;
        -webkit-box-pack:center;
        background-color: #fff;
        border: 1px solid #CCC;
        border-radius: 6px;
        cursor: pointer;
    }

    select {
        border: none;
    }
}

デモ:http://jsdo.it/Ituki/tsIQ

12
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
10