我对css比较新,对不起,如果这很简单的话。我一直在寻找一个多小时的解决方案,似乎无法弄明白。我想垂直对齐时间轴面板和时间轴图像。请注意,h4可以有多行,从而改变时间轴面板的高度。
由于 的修改
我想我没有正确解释自己。这是我正在建设的页面。你可以在about部分看到它。 http://belyza.com/test437/ 我现在为文本添加了一个上边距,但是当文本在较小的屏幕上变成多行时,这对于响应主题不起作用。
.timeline {
list-style: none;
padding: 0;
position: relative
}
.timeline>li {
margin-bottom: 10px;
position: relative;
min-height: 50px
}
.timeline>li .timeline-panel {
position: relative;
text-align: center;
}
.timeline>li .timeline-image {
left: 50%;
margin-left: 15px;
width: 50px;
height: 50px;
position: absolute;
z-index: 100;
background-color: #E80B10;
color: #fff;
border-radius: 100%;
border: 5px solid #ff9600;
text-align: center
}
.timeline>li .timeline-image h4 {
font-size: 10px;
margin-top: 12px;
line-height: 14px
}
.timeline .timeline-heading h4 {
margin-top: 0;
color: inherit
}
.timeline .timeline-heading h4.subheading {
text-transform: none
}
.timeline .timeline-body>p,
.timeline .timeline-body>ul {
margin-bottom: 0
}
<ul class="timeline">
<li>
<div class="timeline-image">
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4>test</h4>
</div>
</div>
</li>
</ul>
答案 0 :(得分:0)
不是100%确定最终目标是什么样的。我假设你想在某些文字上方留一个圆圈。
由于您为.timeline-image
设置了宽度,因此您可以继续使用auto
作为左右边距,一个版本为margin: 0 auto;
。然后,我从position: absolute;
删除了z-index: 100;
,left: 50%;
和.timeline-image
。
如果您不熟悉它的工作原理,使用绝对定位可以做一些奇怪的事情。
.timeline {
list-style: none;
padding: 0;
}
.timeline > li {
margin-bottom: 10px;
}
.timeline-panel {
position: relative;
text-align: center;
}
.timeline-image {
margin: 0 auto;
width: 50px;
height: 50px;
background-color: #E80B10;
color: #fff;
border-radius: 100%;
border: 5px solid #ff9600;
text-align: center
}
.timeline-image h4 {
font-size: 10px;
margin-top: 12px;
line-height: 14px margin-top: 0;
color: inherit
}
<ul class="timeline">
<li>
<div class="timeline-image">
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4>test</h4>
</div>
</div>
</li>
</ul>
如果您要在圆圈左侧查找单行文本,则需要稍微重新排列标记。在.timeline-image
之后放置.timeline-heading
。将这两个设置为display: inline-block; vertical-align: middle;
并将.timeline-heading
设置为line-height: 60px;
(.timeline-image
的总高度。)
.timeline {
list-style: none;
padding: 0;
}
.timeline > li {
margin-bottom: 10px;
}
.timeline-panel {
position: relative;
text-align: center;
}
.timeline-heading {
display: inline-block;
line-height: 60px;
vertical-align: middle;
}
.timeline-image {
display: inline-block;
width: 50px;
height: 50px;
background-color: #E80B10;
color: #fff;
border-radius: 100%;
border: 5px solid #ff9600;
text-align: center;
vertical-align: middle;
}
.timeline-image h4 {
font-size: 10px;
margin-top: 12px;
line-height: 14px margin: 0;
color: inherit
}
<ul class="timeline">
<li>
<div class="timeline-panel">
<div class="timeline-heading">
<h4>test</h4>
</div>
<div class="timeline-image"></div>
</div>
</li>
</ul>
答案 1 :(得分:0)
如果你想使用flexbox,你可以这样设置:
修改强>
好的,现在我确切地看到了你要做的事情我编辑了代码,我认为这就是你要找的。 p>
.timeline {
list-style: none;
padding: 0;
}
.timeline>li {
align-items: center;
display: flex;
justify-content: center;
margin-bottom: 10px;
min-height: 50px
}
.timeline-panel-left:after,
.timeline-panel-right:before {
content: "";
flex: 1 calc(50% - 80px);
max-width: calc(50% - 80px);
}
.timeline-panel-left {
text-align: right;
}
.timeline>li .timeline-panel {
flex: 1 calc(50% - 80px);
max-width: calc(50% - 80px);
}
.timeline>li .timeline-image {
margin-left: 15px;
margin-right: 15px;
width: 50px;
height: 50px;
background-color: #E80B10;
color: #fff;
border-radius: 100%;
border: 5px solid #ff9600;
}
.timeline .timeline-heading h4 {
margin: 0;
color: inherit
}
<ul class="timeline">
<li class="timeline-panel-left">
<div class="timeline-panel">
<div class="timeline-heading">
<h4>SERVICE DE RÉPARATION</h4>
</div>
</div>
<div class="timeline-image">
</div>
</li>
<li class="timeline-panel-right">
<div class="timeline-image">
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4>DIAGNOSTIQUE</h4>
</div>
</div>
</li>
</ul>
答案 2 :(得分:0)
添加了display:inline-block
和vertical-align:middle
。评论了不必要的属性。 Display:flex
不支持较低版本的IE。
.timeline {
list-style: none;
padding: 0;
position: relative
}
.timeline>li {
margin-bottom: 10px;
min-height: 50px;
text-align: center;
}
.timeline>li .timeline-panel {
position: relative;
text-align: center;
display: inline-block;
vertical-align: initial;
}
.timeline>li .timeline-image {
/* left: 50%; */
/* margin-left: 15px; */
width: 50px;
height: 50px;
/* position: absolute; */
/* z-index: 100; */
background-color: #E80B10;
color: #fff;
border-radius: 100%;
border: 5px solid #ff9600;
text-align: center;
display: inline-block;
vertical-align: middle;
}
.timeline>li .timeline-image h4 {
font-size: 10px;
margin-top: 12px;
line-height: 14px
}
.timeline .timeline-heading h4 {
margin-top: 0;
color: inherit
}
.timeline .timeline-heading h4.subheading {
text-transform: none
}
.timeline .timeline-body>p,
.timeline .timeline-body>ul {
margin-bottom: 0
}
&#13;
<ul class="timeline">
<li>
<div class="timeline-image">
</div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4>test</h4>
</div>
</div>
</li>
</ul>
&#13;