[英]border around inner divs in a outer div container
I have the code at the following link jsFiddle . 我在以下链接jsFiddle中有代码。 I want border just around the inner content, instead of stretching it. 我希望边框仅围绕内部内容,而不是拉伸边框。
Tried the following: 尝试了以下内容:
That did not work. 那没有用。 It should work in IE8 and above, Chrome and FF. 它应该可以在IE8及更高版本,Chrome和FF中使用。
HTML: HTML:
<div class="ptr" >
<div><span>Program Type</span></div>
<div>
<input type="radio" id="dc" checked>
<span>Cust</span>
<input type="radio" id="tu">
<span>User</span>
<input type="radio" id="b">
<span>All</span>
</div>
<div style="clear:both; line-height:0"> </div>
</div>
CSS: CSS:
div.ptr {
border: 1px solid #bbccbb;
}
Divs are display:block
elements by default. 默认情况下,div是display:block
元素。 So it will always take up the whole width available, unless you set otherwise. 因此,除非另行设置,否则它将始终占用可用的整个宽度。 One way for that is to set it display:inline-block
一种方法是将其设置为display:inline-block
div.program-type-row {
border: 1px solid #bbccbb;
display: inline-block;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
}
http://jsfiddle.net/3oxrdyug/13/ http://jsfiddle.net/3oxrdyug/13/
EDIT 编辑
According to your comments bellow, you really need a wrapper to set the border around the content, despite the container's width... So wrap the content in a div, and set the border
and display:inline
properties to this wrapper, and center it setting the container as text-align: center;
根据您在下面的评论,您确实需要一个包装器来设置内容周围的边框,尽管容器的宽度...所以将内容包装在一个div中,并设置border
和display:inline
属性到该包装器中并居中将容器设置为text-align: center;
http://jsfiddle.net/3oxrdyug/14/ http://jsfiddle.net/3oxrdyug/14/
HTML: HTML:
<div name="userTypeOptions" class="program-type-row" >
<div id="wrapper">
<div><span class="form-field label">Program Type</span></div>
<div>
<input type="radio" id="dwcust" name="userType" checked />
<span class="form-field label">DW Customer</span>
<input type="radio" id="tusr" name="userType" />
<span class="form-field label">Trail User</span>
<input type="radio" id="both" name="userType" />
<span class="form-field label">All</span>
</div>
<div style="clear:both; line-height:0"> </div>
</div>
</div>
CSS: CSS:
div.program-type-row {
text-align: center;
}
#wrapper {
border: 1px solid #bbccbb;
box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-box-sizing:border-box;
display: inline-block;
}
You should make a wrapper, containing the radio buttons. 您应该制作一个包含单选按钮的包装器。 Then give the wrapper 'display:table;' 然后给包装器“ display:table;” and the radio buttons 'display:table-cell' CSS-properties. 以及单选按钮“ display:table-cell”的CSS属性。
Your code would be as followed: 您的代码如下:
HTML HTML
<div class="wrapper">
<input type="radio">Button 1
<input type="radio">Button 2
<input type="radio">Button 3
</div>
CSS CSS
.wrapper{
display:table;
border:1px solid black;
}
input[type="radio"] {
display:table-cell;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.