我正在尝试制作响应水平时间轴。我正在使用Bootstrap 4进行时间表和项目。到目前为止,我已经提出了这个代码,它在响应性方面运行良好。
timeline.html
<div className="container timeline-container">
<div class="intro">
<div class="main-heading">
<div class="three-col top">
<div class="col">
<div class="sub-heading">
<div class="square">
<div class="pic">
</div>
</div>
</div>
</div>
<div class="col">
<div class="sub-heading">
<div class="square">
<div class="pic">
</div>
</div>
</div>
</div>
<div class="col">
<div class="sub-heading">
<div class="square">
<div class="pic">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="main-heading">
<div class="three-col bottom">
<div className="wrapper-bottom">
<div class="col">
<div class="timeline-dot">
</div>
<div class="sub-heading">
<div class="square">
<div class="pic">
</div>
</div>
</div>
</div>
<div class="col">
<div class="timeline-dot">
</div>
<div class="sub-heading">
<div class="square">
<div class="pic">
</div>
</div>
</div>
</div>
<div class="col">
<div class="timeline-dot">
</div>
<div class="sub-heading">
<div class="square">
<div class="pic">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
style.css文件
.container.timeline-container{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
* {
box-sizing: border-box;
}
.intro {
position: relative;
}
.square {
width: 100px;
height: 100px;
margin: 25px;
transform:rotate(45deg);
overflow: hidden;
}
.pic {
background: url(http://placekitten.com/g/150/150);
width: 150px;
height: 150px;
margin: -25px;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
.timeline-dot {
width: 10px;
height: 10px;
border-radius: 20px;
margin: 0 auto;
background: #CF4532;
margin-top: -6px;
}
.main-heading {
text-align: center;
font-size: 30px;
line-height: 30px;
position: relative;
}
.three-col.bottom{
border-top: 2px solid #4A4A4A;
}
.three-col:after {
display: block;
clear: both;
content: '';
}
.three-col .col {
float: left;
width: 33.33%;
position: relative;
padding: 0 20px;
}
.sub-heading {
position: relative;
display: inline-block;
padding: 20px 0;
}
我的时间表看起来像这样:
我想改变两件事:
2)使图片方块响应。
我试过让父母div
喜欢
.sub-heading {
position: relative;
display: inline-block;
padding: 20px 0;
width: 400px;
height: 400px;
}
和图片广场
.square {
width: 100%;
height: 100%;
margin: 25px;
transform:rotate(45deg);
overflow: hidden;
}
但它不起作用。任何建议表示赞赏。
1)您可以在每列上使用css ::after
伪类来实现。从.three-col.bottom
移除边框顶部,并使用.col
将边框添加到顶行的每个::after
。
请注意css:
.three-col.top .col::after {
content: "";
position: absolute;
display: block;
left: 0;
right: 0;
bottom: 0;
border-bottom: 2px solid #4A4A4A;
}
.three-col.top .col:first-child::after {
left: 50%;
}
.three-col.top .col:last-child::after {
right: 50%;
}
2)删除方形div,你不需要它。同时将.pic样式更改为
.pic {
background: url(http://placekitten.com/g/150/150);
width: 60px;
height: 60px;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
margin: 25px;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
对于响应式设计,您需要使用css媒体查询
所以你可以尝试这样的事情:
@media (min-width: 800px) {
.pic {
width: 150px;
height: 150px;
}
}
@media (min-width: 1024px) {
.pic {
width: 200px;
height: 200px;
}
}
@media (min-width: 1200px) {
.pic {
width: 250px;
height: 250px;
}
}
完整代码:
.container.timeline-container{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
* {
box-sizing: border-box;
}
.intro {
position: relative;
}
.square {
width: 100px;
height: 100px;
margin: 25px;
transform:rotate(45deg);
overflow: hidden;
}
.pic {
background: url(http://placekitten.com/g/150/150);
width: 60px;
height: 60px;
-ms-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
margin: 25px;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.timeline-dot {
width: 10px;
height: 10px;
border-radius: 20px;
margin: 0 auto;
background: #CF4532;
margin-top: -6px;
}
.main-heading {
text-align: center;
font-size: 30px;
line-height: 30px;
position: relative;
}
.three-col:after {
display: block;
clear: both;
content: '';
}
.three-col .col {
float: left;
width: 33.33%;
position: relative;
padding: 0 20px;
}
.sub-heading {
position: relative;
display: inline-block;
padding: 35px 0;
}
.three-col.top .col::after {
content: "";
position: absolute;
background: #000;
display: block;
left: 0;
right: 0;
bottom: 0;
border-bottom: 2px solid #4A4A4A;
}
.three-col.top .col:first-child::after {
left: 50%;
}
.three-col.top .col:last-child::after {
right: 50%;
}
@media (min-width: 576px) {
.pic {
width: 100px;
height: 100px;
}
}
@media (min-width: 800px) {
.pic {
width: 150px;
height: 150px;
}
}
@media (min-width: 1024px) {
.pic {
width: 200px;
height: 200px;
}
}
@media (min-width: 1200px) {
.pic {
width: 250px;
height: 250px;
}
}
<div className="container timeline-container">
<div class="intro">
<div class="main-heading">
<div class="three-col top">
<div class="col">
<div class="sub-heading">
<div class="pic">
</div>
</div>
</div>
<div class="col">
<div class="sub-heading">
<div class="pic">
</div>
</div>
</div>
<div class="col">
<div class="sub-heading">
<div class="pic">
</div>
</div>
</div>
</div>
</div>
<div class="main-heading">
<div class="three-col bottom">
<div className="wrapper-bottom">
<div class="col">
<div class="timeline-dot">
</div>
<div class="sub-heading">
<div class="pic">
</div>
</div>
</div>
<div class="col">
<div class="timeline-dot">
</div>
<div class="sub-heading">
<div class="pic">
</div>
</div>
</div>
<div class="col">
<div class="timeline-dot">
</div>
<div class="sub-heading">
<div class="pic">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>