这个问题涉及到这个jsFiddle中显示的情况。
如您所见,目前包含
如您所见,目前包含
svg
元素(白色背景)的div
(又名.svg-container
;橙色背景)比它需要的宽度多约70像素。我能否在不使用任何JS的情况下使该“缩小以适应”其内容?
编辑:为了明确起见,其余元素的形状和定位应保持不变。唯一需要改变的是
现在,请允许我提供源代码:
编辑:为了明确起见,其余元素的形状和定位应保持不变。唯一需要改变的是
.svg-container
的形状,并且这应该是这样的:其右侧的橙色边沿与其他三个边沿的宽度相同。最终结果应该看起来像这样。(当然,为了创建第二个jsFiddle,我不得不显式设置.svg-container
的宽度,这不是我要寻找的解决方案。我正在寻找的CSS可以将其转化为“在超出内容的右边缘时扩展与其他三个边缘相同的数量”)。
现在,请允许我提供源代码:
*{
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
margin:0;
font-family:consolas,monaco,courier,monospace;
}
.centered{
max-width:280px;
background-color:red;
padding:15px;
margin:0 auto;
}
.content{
width:100%;
color:#8f8;
background-color:#333;
}
table td:first-child{
width:75px;
}
.svg-container{
line-height:0;
background-color:orange;
}
svg{
margin:1px;
}
rect {
shape-rendering:crispEdges;
stroke:none;
fill:white;
}
td{
vertical-align:top;
}
<div class="centered">
<div class="content">
<table><tr>
<td>
<div><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam elementum, lectus ut consectetur mattis,</p></div>
</td>
<td>
<div class="svg-container">
<svg width="50" height="50"><rect width="50" height="50"></rect></svg><svg width="50" height="50"><rect width="50" height="50"></rect></svg><svg width="50" height="50"><rect width="50" height="50"></rect></svg><svg width="50" height="50"><rect width="50" height="50"></rect></svg><svg width="50" height="50"><rect width="50" height="50"></rect></svg><svg width="50" height="50"><rect width="50" height="50"></rect></svg>
</div>
</td>
</tr></table>
</div> <!-- .content -->
</div> <!-- .centered -->
width=50
,或在.svg-container
上设置width: 50px
。 - brouxhaha