2017-05-01 10 views
0

ラベルとテキストがあります。どのように水平に並べて並べることができますか?<label>とテキストをhtmlで並べて並べる方法

現在のところ、テキストはラベルの下に並んでいます(画像のように)。私はラベルの中央にテキストを揃えたいと思います。

私はそれを変更する必要がどこに私のhtmlコードが

<div> 
    <label class="switchnmn"> 
     <input type="checkbox" checked> 
     <div class="slidernmn round"></div> 
    </label> 
     <b style="font-size:15px">I am able to accept customer's any request date.</b>  
</dlv> 

私のCSSファイルが

.switchnmn { 
    position: relative; 
    display: inline-block; 
    width: 60px; 
    height: 34px; 
} 

.switchnmn input {display:none;} 

.slidernmn { 
    position: absolute; 
    cursor: pointer; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0; 
    background-color: #ccc; 
    -webkit-transition: .4s; 
    transition: .4s; 
} 

.slidernmn:before { 
    position: absolute; 
    content: ""; 
    height: 26px; 
    width: 26px; 
    left: 4px; 
    bottom: 4px; 
    background-color: white; 
    -webkit-transition: .4s; 
    transition: .4s; 
} 

input:checked + .slidernmn { 
    background-color: #2196F3; 
} 

input:focus + .slidernmn { 
    box-shadow: 0 0 1px #2196F3; 
} 

input:checked + .slidernmn:before { 
    -webkit-transform: translateX(26px); 
    -ms-transform: translateX(26px); 
    transform: translateX(26px); 
} 

/* Rounded sliders */ 
.slidernmn.round { 
    border-radius: 34px; 
} 

.slidernmn.round:before { 
    border-radius: 50%; 
} 

あるのですか?

enter image description here

答えて

1

あなたはラベルaとbの要素にvertical-align: middleを追加することができます。

.switchnmn { 
 
    position: relative; 
 
    display: inline-block; 
 
    width: 60px; 
 
    height: 34px; 
 
} 
 

 
.switchnmn input {display:none;} 
 

 
.slidernmn { 
 
    position: absolute; 
 
    cursor: pointer; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    bottom: 0; 
 
    background-color: #ccc; 
 
    -webkit-transition: .4s; 
 
    transition: .4s; 
 
} 
 

 
.slidernmn:before { 
 
    position: absolute; 
 
    content: ""; 
 
    height: 26px; 
 
    width: 26px; 
 
    left: 4px; 
 
    bottom: 4px; 
 
    background-color: white; 
 
    -webkit-transition: .4s; 
 
    transition: .4s; 
 
} 
 

 
input:checked + .slidernmn { 
 
    background-color: #2196F3; 
 
} 
 

 
input:focus + .slidernmn { 
 
    box-shadow: 0 0 1px #2196F3; 
 
} 
 

 
input:checked + .slidernmn:before { 
 
    -webkit-transform: translateX(26px); 
 
    -ms-transform: translateX(26px); 
 
    transform: translateX(26px); 
 
} 
 

 
/* Rounded sliders */ 
 
.slidernmn.round { 
 
    border-radius: 34px; 
 
} 
 

 
.slidernmn.round:before { 
 
    border-radius: 50%; 
 
} 
 
label, b { 
 
    vertical-align: middle; 
 
}
<div> 
 
    <label class="switchnmn"> 
 
    <input type="checkbox" checked> 
 
    <div class="slidernmn round"></div> 
 
    </label> 
 
    <b style="font-size:15px">I am able to accept customer's any request date.</b> 
 
</div>

+0

をありがとうございました。 cssではなく、html内で行うことが可能ですか? – batuman

+0

cssでインラインスタイルとして書くことができます。 –

1

以下に示すようにdisplay: inline-block;vertical-align: middle;として3つのすべての要素を定義します。

.x > * { 
 
    display: inline-block; 
 
    vertical-align: middle; 
 
} 
 

 
.switchnmn { 
 
    position: relative; 
 
    display: inline-block; 
 
    width: 60px; 
 
    height: 34px; 
 
} 
 

 
.switchnmn input { 
 
    display: none; 
 
} 
 

 
.slidernmn { 
 
    position: absolute; 
 
    cursor: pointer; 
 
    top: 0; 
 
    left: 0; 
 
    right: 0; 
 
    bottom: 0; 
 
    background-color: #ccc; 
 
    -webkit-transition: .4s; 
 
    transition: .4s; 
 
} 
 

 
.slidernmn:before { 
 
    position: absolute; 
 
    content: ""; 
 
    height: 26px; 
 
    width: 26px; 
 
    left: 4px; 
 
    bottom: 4px; 
 
    background-color: white; 
 
    -webkit-transition: .4s; 
 
    transition: .4s; 
 
} 
 

 
input:checked+.slidernmn { 
 
    background-color: #2196F3; 
 
} 
 

 
input:focus+.slidernmn { 
 
    box-shadow: 0 0 1px #2196F3; 
 
} 
 

 
input:checked+.slidernmn:before { 
 
    -webkit-transform: translateX(26px); 
 
    -ms-transform: translateX(26px); 
 
    transform: translateX(26px); 
 
} 
 

 

 
/* Rounded sliders */ 
 

 
.slidernmn.round { 
 
    border-radius: 34px; 
 
} 
 

 
.slidernmn.round:before { 
 
    border-radius: 50%; 
 
}
<div class="x"> 
 
    <label for="y" class="switchnmn"> 
 
     <input type="checkbox" id="y" checked> 
 
     <div class="slidernmn round"></div> 
 
    </label> 
 
    <b style="font-size:15px">I am able to accept customer's any request date.</b> 
 
    </dlv>

関連する問題