我有以下代码,我想在父div内居中对齐span和div。我怎样才能实现它?如果我给出左位置和绝对位置,在平板电脑上对齐方式会发生变化,需要进行媒体查询。没有这个,我有什么办法可以解决它吗?
<div>
<span data-toggle="toggle">
<input class="button" data-on="On" data-off="Off" type="checkbox">
<div class="toggle-group">
<label class="btn btn-primary toggle-on">
On
</label>
<label class="btn btn-default toggle-off active">
Off
</label>
<span class="toggle-handle btn btn-default"></span>
</div>
</div>
</div>
使用 text-align: center
.wrapper > span{display:block; text-align:center}
.wrapper > div{text-align:center}
.wrapper > div > div{display: inline-block}
演示已更新
在单行中获取子跨度和div
.wrapper{text-align:center}
.wrapper div{display:inline-block}
演示 2
你想要这个吗?
div.btn-default {
text-align: center;
}
div.toggle-group {
display: inline-block;
}
<div> <span class="band-charging-icon charge-not-created" title="Nothing created/set (reservation not checked in)" ng-class="{'charge-not-created':!guest.chargingAccoundId || !guest.chargeAccountAvailable, 'charge-pin-set':guest.chargingAccoundId && guest.chargeAccountAvailable && guest.pinAvailable, 'charge-pin-not-set':guest.chargingAccoundId && guest.chargeAccountAvailable && !guest.pinAvailable}"></span>
<div class="toggle btn btn-default off disabled" title="Charging Privileges Off" ng-click="guest.chargingAccoundId && guest.chargeAccountAvailable && toggler()(guest)" ng-class="{'btn-default off disabled': !guest.chargeAccountAvailable || !guest.chargingAccoundId, 'btn-default off': (guest.chargingAccoundId && guest.chargeAccountAvailable && !guest.chargingPrivileges), 'btn-primary': (guest.chargingAccoundId && guest.chargeAccountAvailable && guest.chargingPrivileges)}"
data-toggle="toggle">
<input class="magic-band-charge-toggle-button" data-on="On" data-off="Off" type="checkbox">
<div class="toggle-group">
<label class="btn btn-primary toggle-on" ng-class="{'active': guest.chargingPrivileges}">On</label>
<label class="btn btn-default toggle-off active" ng-class="{'active': !guest.chargingPrivileges}">Off</label><span class="toggle-handle btn btn-default"></span>
</div>
</div>
</div>