有没有办法创建一个具有最大宽度限制的自扩展图层,其中包含左对齐文本
HTML:
<div class="SummaryTable">
<div class="AddressContainer">
<div class="Address">
<b>Ship To: </b>
<ul>
<li>John Smith</li>
<li>45 Holland drv.</li>
</ul>
</div>
<div class="Address">
<b>Bill To: </b>
<ul>
<li>John Smith</li>
<li>P.O Box 456</li>
</ul>
</div>
</div>
</div>
CSS:
.SummaryTable
{
width: 650px;
text-align:center;
}
.SummaryTable .AddressContainer
{
width:650px;
}
.SummaryTable .Address
{
width:323px;
background-color:Yellow;
float:left;
border: 1px solid black;
height:200px;
}
.Address ul
{
width:130px;
min-width:130px;
max-width: 280px;
margin-left:auto;
margin-right:auto;
background-color:Green;
text-align:left;
padding:0px;
}
.Address li
{
list-style-type: none;
}
- 我想将绿色框\元素(ul)保持在323px宽/200px或自动高(.Address)层的水平和中心位置垂直。
- 我通过设置
fixed width + margin:0px auto
实现了的水平居中,但地址的长度各不相同,我不只想要一些固定大小的框其中一个较长的地址将显示在(收货地址\收单地址)标题下方的中心,而另一个较短的地址将看起来不合适,因为文本左对齐。
我想看到
- 中的文本拉伸到
绿色框,直到最大宽度设置(例如 280px),并且绿色框,无论其大小如何,都将在
.Address
层中保持水平和垂直居中,并因此位于Ship To\Bill To
标题下。 这样做的主要原因是,较短的地址看起来会在固定宽度
ul
元素中向左偏移,如果我使宽度小于换行符,则会出现较长的地址,从而扩展第一个以及姓氏和/或地址,共两行。在ul
元素中使用居中对齐的文本 -当然解决了这个问题,但我需要左对齐文本。
HTML:
<div class="SummaryTable">
<div class="AddressContainer">
<div class="Address">
<b>Ship To: </b>
<ul>
<li>John Smith</li>
<li>45 Holland drv.</li>
</ul>
</div>
<div class="Address">
<b>Bill To: </b>
<ul>
<li>John Smith</li>
<li>P.O Box 456</li>
</ul>
</div>
</div>
</div>
CSS:
.SummaryTable
{
width: 650px;
text-align:center;
}
.SummaryTable .AddressContainer
{
width:650px;
}
.SummaryTable .Address
{
width:323px;
background-color:Yellow;
float:left;
border: 1px solid black;
height:200px;
}
.Address ul
{
width:130px;
min-width:130px;
max-width: 280px;
margin-left:auto;
margin-right:auto;
background-color:Green;
text-align:left;
padding:0px;
}
.Address li
{
list-style-type: none;
}
- I want to keep the green box\element (ul) centred in the 323px wide/200px or Auto high (.Address) layer both horizontally and vertically.
- I have achieved horizontal centering of
<ul>
by settingfixed width + margin:0px auto
, but addresses vary in length and I don't just want some fixed size box where one longer address would appear centred under (Ship To\Bill To) heading and another shorter one will look out of place since text is aligned to the left. I want to see the text in the
<li>
stretch to the<ul>
green box up to the maximum-width setting (e.g 280px) and the green box, whatever its size will be to remain centered horizontally and vertically in the.Address
layer and consequently under theShip To\Bill To
headings.Main reason for this is that shorter addresses would look offset to the left in a fixed width
ul
element and if I make the width small than a line break would ensue for longer address, spreading the first and last name and or address over two lines. Using centrally aligned text in theul
element
-Of course solves this problem, but I need left aligned text.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DEMO jsBin
如果我很好地理解你的问题,
这里是修改后的 CSS:
我删除了一些 margin-reft/right:auto、widths、min-width、max width 并格式化了您的
.summaryTable
css“外观”。稍微玩一下display
属性就可以了。这是使用 jQuery 的演示: 使用 jQ 演示 jsBin
DEMO jsBin
If I understood well your question
Here is the modified CSS:
I removed some margin-reft/right:auto, widths, min-width, max width and formatted a bit your
.summaryTable
css 'appearances'. Than a bit of playing withdisplay
property have done the trick.Here is a demo using jQuery : demo jsBin with jQ