gpt4 book ai didi

javascript - 使div与文本在同一行,放在哪里显示:inline-block?

转载 作者:太空宇宙 更新时间:2023-11-03 23:05:09 26 4
gpt4 key购买 nike

上下文:

我正在使用开/关开关按钮,我希望帮助文本与开关位于同一行。

现在看起来是这样的:

enter image description here

我希望它看起来像这样:

enter image description here

我在谷歌上搜索过我可以use this是我的 div 样式:

display:inline-block;

我的代码:

html {
position: relative;
min-height: 100%;
}

body {
margin: 0 0 100px;
/* bottom = footer height */
padding: 25px;
}

footer {
background-color: #5B8CA8;
position: absolute;
left: 0;
bottom: 0;
height: 110px;
width: 100%;
overflow:hidden;
}

div.upp {
background-color: #5B8CA8;
position: absolute;
left: 0;
top: 0;
height: 39px;
width: 100%;
overflow:hidden;
}

.onoffswitch {
position: relative;
width: 55px;
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select: none;
}

.onoffswitch-checkbox {
display: none;
}

.onoffswitch-label {
display: block;
overflow: hidden;
cursor: pointer;
border: 2px solid #999999;
border-radius: 20px;
}

.onoffswitch-inner {
display: block;
width: 200%;
margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}

.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block;
float: left;
width: 50%;
height: 23px;
padding: 0;
line-height: 23px;
font-size: 11px;
color: white;
font-family: Trebuchet, Arial, sans-serif;
font-weight: bold;
box-sizing: border-box;
}

.onoffswitch-inner:before {
content: "PÅ";
padding-left: 7px;
background-color: #5B8CA8;
color: #FFFFFF;
}

.onoffswitch-inner:after {
content: "AV";
padding-right: 10px;
background-color: #EEEEEE;
color: #999999;
text-align: right;
}

.onoffswitch-switch {
display: block;
width: 15px;
margin: 4px;
background: #FFFFFF;
position: absolute;
top: 0;
bottom: 0;
right: 28px;
border: 2px solid #999999;
border-radius: 20px;
transition: all 0.3s ease-in 0s;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}

.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
<p>
Help Text
</p>
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitchT1" unchecked onclick="javascript:toggle1();">
<label class="onoffswitch-label" for="myonoffswitchT1">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>

我的问题:

在我的 div 样式中,我应该把 display:inline-block; 放在哪里?

最佳答案

p 和 div 都应该有 inline-block 样式。

当然,在实际元素中我不会放置样式属性——而是使用 css 类。

<p style="display: inline-block">
Help Text
</p>
<div class="onoffswitch" style="display: inline-block">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitchT1" unchecked onclick="javascript:toggle1();">
<label class="onoffswitch-label" for="myonoffswitchT1">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>

关于javascript - 使div与文本在同一行,放在哪里显示:inline-block?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35012558/

26 4 0