如何更改 jQuery Mobile 翻转开关大小

问题描述 投票:0回答:1

我需要一个具有自定义宽度和高度的 jQuery Mobile 翻转开关。我设法通过将翻转开关包装在 div 中并应用以下 CSS 来更改它的大小:

   #flipswitchWrapper .ui-flipswitch {
       position:absolute;
       width:400px;
       height:100px;
   }

   #flipswitchWrapper .ui-flipswitch-active {
       padding-left:0px;
   }

   #flipswitchWrapper .ui-flipswitch .ui-flipswitch-on,
   #flipswitchWrapper .ui-flipswitch.ui-flipswitch-active .ui-flipswitch-on{
       width:98px;
       height:98px;
   }

   #flipswitchWrapper .ui-flipswitch.ui-flipswitch-active .ui-flipswitch-on {
       padding-top:0px;
       margin-left:300px;
   }

但是文本位置不正确。在这里检查 jsfiddle:

https://jsfiddle.net/dinkoivanov/8czs4qzn/

我想我可能没有做正确的事情。您能否建议这在 jQuery Mobile 中是否可行?

jquery css jquery-mobile jquery-mobile-flipswitch
1个回答
4
投票

here所示,您可能需要在CSS中引入

  • 自定义缩进
  • 自定义宽度

因为自定义标签的长度与实际标签的长度不同 标准标签

您可以通过更正 CSS 中的缩进来定位文本

#flipswitchWrapper .ui-flipswitch .ui-flipswitch-on,
#flipswitchWrapper .ui-flipswitch.ui-flipswitch-active .ui-flipswitch-on{
    width:98px;
    height:98px;
    text-indent: -20em;
}

#flipswitchWrapper .ui-flipswitch.ui-flipswitch-active .ui-flipswitch-on {
    padding-top:0px;
    margin-left:300px;
    text-indent: -18em;
}

更新:https://jsfiddle.net/8czs4qzn/1/

将文本放置在中间(请参阅下面的评论):

#flipswitchWrapper .ui-flipswitch {
    position:absolute;
    width:400px;
    height:100px;
    line-height: 100px;
}
#flipswitchWrapper .ui-flipswitch-active {
    padding-left:0px;
}
#flipswitchWrapper .ui-flipswitch .ui-flipswitch-on, #flipswitchWrapper .ui-flipswitch.ui-flipswitch-active .ui-flipswitch-on {
    width:98px;
    height:98px;
    text-indent: -20em;
}
#flipswitchWrapper .ui-flipswitch.ui-flipswitch-active .ui-flipswitch-on {
    padding-top:0px;
    margin-left:300px;
    text-indent: -18em;
    line-height: inherit;
}

#flipswitchWrapper .ui-flipswitch-off {
    line-height: inherit;
}

标签垂直对齐:https://jsfiddle.net/8czs4qzn/3/

© www.soinside.com 2019 - 2024. All rights reserved.