如何使此元素居中
How to center this element
<div id="1" style="display:block">
<div class="radio">
<label><input type="radio" name="o1"> <input type="text" class="form-control" id="opt1"></label>
</div>
<div class="radio">
<label><input type="radio" name="o2"><input type="text" class="form-control" id="opt2"></label>
</div>
<div class="radio">
<label><input type="radio" name="o3"><input type="text" class="form-control" id="opt3"></label>
</div>
<div class="radio">
<label><input type="radio" name="o4"><input type="text" class="form-control" id="opt4"></label>
</div>
</div>
目前,它出现在屏幕的左侧。请看一看。谢谢。
尝试添加一些CSS代码
#mydiv{
text-align:center
}
<div id="mydiv">
<div class="radio">
<label><input type="radio" name="o1"><input type="text" class="form-control" id="opt1"></label>
</div>
<div class="radio">
<label><input type="radio" name="o2"><input type="text" class="form-control" id="opt2"></label>
</div>
<div class="radio">
<label><input type="radio" name="o3"><input type="text" class="form-control" id="opt3"></label>
</div>
<div class="radio">
<label><input type="radio" name="o4"><input type="text" class="form-control" id="opt4"></label>
</div>
</div>
首先,如果你想用id='1'居中div,它需要一个父元素.HTML
<div id='parent'>
<div id="myDiv" style="display:block">
<div class="radio">
<label>
<input type="radio" name="o1">
<input type="text" class="form-control" id="opt1">
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="o2">
<input type="text" class="form-control" id="opt2">
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="o3">
<input type="text" class="form-control" id="opt3">
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="o4">
<input type="text" class="form-control" id="opt4">
</label>
</div>
</div>
</div>
.CSS
#parent {
display: flex;
justify-content: center;
}
JSFIDDLE https://jsfiddle.net/g8oLjnus/了解有关弹性框 https://css-tricks.com/snippets/css/a-guide-to-flexbox/的更多信息
如果您使用以下方法之一,则可以使用它将其居中 50% 将放置文本或输入框的开头。 PX表示您必须手动排列。 将其插入 或 CSS 文件下 #mydiv. 为此,请将您的 ID 更改为 Mydiv 或其他内容。
left:50px;
left:50%
我已将id
更改为myid
; 并添加了父div
<div class="parent">
<div id="myid" style="display:block">
<div class="radio">
<label><input type="radio" name="o1"> <input type="text" class="form- control" id="opt1"></label>
</div>
<div class="radio">
<label><input type="radio" name="o2"><input type="text" class="form-control" id="opt2"></label>
</div>
<div class="radio">
<label><input type="radio" name="o3"><input type="text" class="form-control" id="opt3"></label>
</div>
<div class="radio">
<label><input type="radio" name="o4"><input type="text" class="form-control" id="opt4"></label>
</div>
</div>
</div>
.parent
类必须是:
.parent{position: relative;}
#myid
必须是
#myid{
position: absolute;
left: 50%;
transform: translateX(-50%);
}
希望是作品:)
相关文章:
- 我可以使此幻灯片图像自动播放吗?
- 我如何使此联系表格工作
- 动态修改一个元素,使其与给定的选择器匹配
- 如何使此链接列表受cookie支持
- 为什么我需要在setTimeout中有匿名函数才能使此代码工作
- 选择一个元素,使其最近的具有特殊属性的父元素具有特殊值
- 当可见时,我如何使此对话框阻止访问页面的其余内容
- 如何添加效果,以便将鼠标悬停在 SVG 元素上使其变大
- 如何使此SetInterval在悬停关闭时停止
- 如何预加载这些图像以使此功能更平滑
- 如何使此循环工作?它's返回未定义的语言js
- 如何使此代码缩放到不同的窗口大小
- 如何使此应用程序与移动浏览器协同工作
- 如何使此IF语句发挥作用
- 如何使此pub/sub代码可读性更强
- 如何使此表单验证脚本在返回之前循环通过整个表单部分
- 我不确定我缺少什么才能使此应用程序在Websockets上在Google Cloud上正常工作
- 如何使此代码更干燥?(滚动播放多个 css 动画)
- 如何使此多边形呈现为完整的形状而不是新月形
- 如何使此元素居中