[英]How to create a border around elements in flex box
The border I'm drawing now fills the whole width of the screen. 我正在绘制的边框现在填满了屏幕的整个宽度。 I would like it to shrink to the size of the child elements.
我希望它缩小到子元素的大小。
I have tried adding a border property to the flexbox, but as I said, it fills the whole screen. 我尝试将边框属性添加到flexbox,但是正如我所说,它会填满整个屏幕。
<div class="mainThing">
<div class="thing_row">
<div class="thing_img">
<img src="url" height="60">
</div>
<div class="thing_texts">
<div class="noa_txt">NOW ON AIR</div>
<div class="main_txt">The Royal Sunrise</div>
<div class="peeps_txt">Meth, Pavan, Thinula and Jayavi</div>
</div>
</div>
</div>
.thing_row{
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
border: solid black;
flex-basis: content;
}
I expected the border to be drawn, tightly fitting the child elements but it fills up the whole width of the screen. 我希望画出边框,使其与子元素紧密匹配,但它会填满屏幕的整个宽度。
With display:flex
the element defaults to its native width of 100%, 使用
display:flex
元素默认为其原始宽度100%,
Use display:inline-flex
on the .thing-row
....and it will collapse to the size of it's children. 在
.thing-row
....上使用display:inline-flex
,它会折叠成它的孩子的大小。
.thing_row { display: inline-flex; flex-direction: row; align-items: flex-start; justify-content: flex-start; border: 1px solid black; flex-basis: content; }
<div class="mainThing"> <div class="thing_row"> <div class="thing_img"> <img src="http://www.fillmurray.com/60/60" height="60"> </div> <div class="thing_texts"> <div class="noa_txt">NOW ON AIR</div> <div class="main_txt">The Royal Sunrise</div> <div class="peeps_txt">Meth, Pavan, Thinula and Jayavi</div> </div> </div> </div>
You're missing the border-width
. 您错过了
border-width
。
Try this one or have a look on here: https://www.w3schools.com/css/css_border.asp 试试这个或在这里看看: https : //www.w3schools.com/css/css_border.asp
border-style: solid;
border-width: 5px;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.