在Google chrome中,按F12并打开切换设备工具栏。 您将在第二个复选框中看到复选框和标题不在同一行。 我想保留引导样式表,如何使复选框和标题位于同一行?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" />
</head>
<body>
<input name="agreement" type="checkbox" >
<label for="agreement">XXXXXXXXXXXXXXXXXXXXXXXXXXXX</label>
<br >
<input name="promotion" type="checkbox">
<label for="promotion">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</label><br>
</body>
</html>
答案 0 :(得分:0)
您应该使用“ div”标签将它们包装起来
<div class="chkbox1">
<input name="agreement" type="checkbox" >
<label for="agreement">XXXXXXXXXXXXXXXXXXXXXXXXXXXX</label>
</div>
<div class="chkbox1">
<input name="promotion" type="checkbox">
<label for="promotion">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</label></div>
使用“ div”标签,您甚至可以给它实际的CSS,并且不需要“ br”标签来分隔
答案 1 :(得分:0)
按如下所示更改html标记,并在css下应用:
label {
position: relative;
padding-left: 20px;
}
label input {
position: absolute;
top: 0;
left: 0;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" />
</head>
<body>
<label>
<input name="agreement" type="checkbox">
<span>XXXXXXXXXXXXXXXXXXXXXXXXXXXX</span>
</label>
<br>
<label>
<input name="promotion" type="checkbox">
<span>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</span>
</label><br>
</body>
</html>
答案 2 :(得分:0)
此代码将起作用。尝试以下操作:-
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" />
</head>
<style>
.promotion{
display: inline;
word-break: break-all;
}
</style>
<body>
<input name="agreement" type="checkbox" >
<label for="agreement">XXXXXXXXXXXXXXXXXXXXXXXXXXXX</label>
<br>
<input name="promotion" type="checkbox">
<label class="promotion" for="promotion">XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</label><br>
</body>
</html>
您可以在此处阅读有关断字的信息: https://developer.mozilla.org/en-US/docs/Web/CSS/word-break