我有一个jsfiddle here我的问题。我想在ul中均匀分布未知数量的li
s。但是正如你可以从小提琴中看到的那样,中间的li并不直接位于标题之下,因此它没有正确居中。此外,如果您检查每个li
,它们的宽度也不同。
如何修复它以使中间li
始终位于中间,以便与标题对齐?
答案 0 :(得分:3)
方法#01:
在Set rng = ActiveSheet.Range("A" & x & ":C" & (x + 4))
' in brackets (Left, Top, Widht, Height) >> modify according to your needs
Set cht = ActiveSheet.ChartObjects.Add(550, 100 * (i - 4), 300, 100)
With cht
.Chart.SetSourceData Source:=rng
.Chart.PlotBy = xlColumns
.Chart.ChartType = xlBarStacked
.Chart.HasAxis(xlValue) = False
.Chart.HasLegend = False
.Chart.HasTitle = True
.Chart.ChartTitle.Text = Application.Sheets(i).Name
.Chart.ChartTitle.Font.Size = 10
.Chart.Axes(xlValue).HasMajorGridlines = False
.Chart.Parent.Name = Application.Sheets(i).Name
End With
cht.Activate
ActiveChart.ChartGroups(1).GapWidth = 10
With ActiveChart.Axes(xlCategory).TickLabels.Font
.Bold = msoFalse
.Size = 8
End With
Set cht_Series = cht.Chart.SeriesCollection(1)
cht_Series.Format.Fill.ForeColor.RGB = RGB(255, 255, 255)
Set cht_Series = cht.Chart.SeriesCollection(2)
cht_Series.Format.Fill.ForeColor.RGB = RGB(134, 188, 37)
的样式中添加table-layout: fixed
。
.strweak-list

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
.strweak-header {
text-align: center;
}
.strweak-list {
table-layout: fixed;
display: table;
width: 100%;
list-style: none;
}
.cell {
display: table-cell;
text-align: center;
}

方法#02:
你也可以使用css FlexBox:
<h5 class='strweak-header'>strongAgainst</h5>
<ul class="strweak-list">
<li class="cell">water</li>
<li class="cell">ghost</li>
<li class="cell">ground</li>
</ul>
&#13;
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
ader {
text-align: center;
}
.strweak-header {
text-align: center;
}
.strweak-list {
text-align: center;
list-style: none;
display: flex;
}
.strweak-list li {
flex-basis: 33.33%;
}
&#13;
答案 1 :(得分:2)
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
.strweak-header {
text-align: center;
}
.strweak-list {
display: flex;
justify-content: space-around;
width: 100%;
list-style: none;
}
<h5 class='strweak-header'>strongAgainst</h5>
<ul class="strweak-list">
<li>water</li>
<li>ghost</li>
<li>ground</li>
</ul>
这是你在flexbox中的方法。希望能帮助到你!干杯!