我是新手的超文本标记语言,css和js目前试图创建一个课程项目的个人网站.其中一个页面包含一个带有日期和信息的时间表.我使用了W3School的教程,但请在jsfiddle:http://jsfiddle.net/gua0nkj6/1/中找到代码

问题是,前3个日期看起来很好,但随后的任何日期相对于时间线都没有对齐.

另见下图(超文本标记语言和css):

<!DOCTYPE html>

<html lang="en">
    <head>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
        <link href="styles.css" rel="stylesheet">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>About me page</title>
    </head>
    <body class="about-me">
          <div class="timeline">
            <div class="container-timeline left-side">
                <div class="content-timeline">
                    <h2 class="timeline-heading">2011</h2>
                    <p class="timeline-text">Lorem ipsum.</p>
                </div>
            </div>
            <div class="container-timeline right-side">
                <div class="content-timeline">
                    <h2 class="timeline-heading">2012</h2>
                    <p class="timeline-text">Lorem ipsum.</p>
                </div>
            </div>
            <div class="container-timeline left-side">
                <div class="content-timeline">
                    <h2 class="timeline-heading">2013</h2>
                    <p class="timeline-text">Lorem ipsum.</p>
            </div>
            <div class="container-timeline right-side" style="border: 4px solid black;">
                <div class="content-timeline">
                    <h2 class="timeline-heading">2014</h2>
                    <p class="timeline-text">Lorem ipsum.</p>
                </div>
            </div>
         </div>
    </body>
</html>


/* Boilerplate CSS for box sizing and body */
* {
  box-sizing: border-box;
}

body {
  background-color: beige;
  font-family: Georgia, Times, Courier;
}

/* Special thanks to W3Schools for the
timeline tutorial: https://www.w3schools.com/howto/howto_css_timeline.asp */
/* Container around content */
.timeline {
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
}

.timeline::after {
  content: '';
  position: absolute;
  width: 6px;
  background-color: #327c9c;
  top: 0px;
  bottom: 0px;
  left: 50%;
}

.container-timeline {
  padding: 10px 40px;
  position: relative;
  background-color: inherit;
  width: 50%;
}

/* The circles on the timeline */
.container-timeline::after {
  content: '';
  position: absolute;
  width: 25px;
  height: 25px;
  right: -15px;
  background-color: white;
  border: 3px solid #327c9c;
  top: 19.2px;
  border-radius: 50%;
  z-index: 1;
}

.left-side {
  left: 0;
}

.right-side {
  left: 50%;
}


/* Add arrows to the left container (pointing right) */
.left-side::before {
  content: " ";
  height: 0;
  position: absolute;
  top: 22px;
  width: 0;
  z-index: 1;
  right: 30px;
  border: medium solid white;
  border-width: 10px 0 10px 10px;
  border-color: transparent transparent transparent white;
}

/* Add arrows to the right container (pointing left) */
.right-side::before {
  content: " ";
  height: 0;
  position: absolute;
  top: 22px;
  width: 0;
  z-index: 1;
  left: 30px;
  border: medium solid white;
  border-width: 10px 10px 10px 0;
  border-color: transparent white transparent transparent;
}

/* Fix the circle for containers on the right side */
.right-side::after {
  left: -9px;
}

/* The actual content */
.content-timeline {
  padding: 20px 30px;
  background-color: #327c9c;
  position: relative;
  border-radius: 6px;
}

/* Media queries - Responsive timeline on screens less than 600px wide */
@media screen and (max-width: 600px) {

  /* Place the timelime to the left */
  .timeline::after {
    left: 25px;
  }

  /* Full-width containers */
  .container-timeline {
    width: 100%;
    padding-left: 70px;
    padding-right: 25px;
  }

  /* Make sure that all arrows are pointing leftwards */
  .container-timeline::before {
    left: 60px;
    border: medium solid white;
    border-width: 10px 10px 10px 0;
    border-color: transparent white transparent transparent;
  }

  /* Make sure all circles are at the same spot */
  .left-side::after,
  .right-side::after {
    left: 15px;
  }

  /* Make all right containers behave like the left ones */
  .right-side {
    left: 0%;
  }
}

/* format the timeline boxes */
.timeline-heading {
  color: white;
  border-bottom: 1px solid white;
  font-family: Courier;
}

.timeline-text {
  color: white;
  font-family: Georgia;
}

我的最终结果如下所示,我在最后一个元素中添加了一个边框来突出显示该问题.

Output

如有需要,敬请惠顾!

推荐答案

你的问题已经解决了.希望你能受益

/* Boilerplate CSS for box sizing and body */
* {
   box-sizing: border-box;
 }
 
 body {
   background-color: beige;
   font-family: Georgia, Times, Courier;
 }
 
 /* Special thanks to W3Schools for the
 timeline tutorial: https://www.w3schools.com/howto/howto_css_timeline.asp */
 /* Container around content */
 .timeline {
   position: relative;
   max-width: 1200px;
   margin: 0 auto;
 }
 
 .timeline::after {
   content: '';
   position: absolute;
   width: 6px;
   background-color: #327c9c;
   top: 0px;
   bottom: 0px;
   left: 50%;
 }
 
 .container-timeline {
   padding: 10px 40px;
   position: relative;
   background-color: inherit;
   width: 50%;
 }
 
 /* The circles on the timeline */
 .container-timeline::after {
   content: '';
   position: absolute;
   width: 25px;
   height: 25px;
   right: -15px;
   background-color: white;
   border: 3px solid #327c9c;
   top: 19.2px;
   border-radius: 50%;
   z-index: 1;
 }
 
 .left-side {
   left: 0;
 }
 
 .right-side {
   left: 50%;
 }
 
 
 /* Add arrows to the left container (pointing right) */
 .left-side::before {
   content: " ";
   height: 0;
   position: absolute;
   top: 22px;
   width: 0;
   z-index: 1;
   right: 30px;
   border: medium solid #327c9c;
   border-width: 10px 0 10px 10px;
   border-color: transparent transparent transparent #327c9c;
 }
 
 /* Add arrows to the right container (pointing left) */
 .right-side::before {
   content: " ";
   height: 0;
   position: absolute;
   top: 22px;
   width: 0;
   z-index: 1;
   left: 30px;
   border: medium solid #327c9c;
   border-width: 10px 10px 10px 0;
   border-color: transparent #327c9c transparent transparent;
 }
 
 /* Fix the circle for containers on the right side */
 .right-side::after {
   left: -16px;
 }
 
 /* The actual content */
 .content-timeline {
   padding: 20px 30px;
   background-color: #327c9c;
   position: relative;
   border-radius: 6px;
 }
 
 /* Media queries - Responsive timeline on screens less than 600px wide */
 @media screen and (max-width: 600px) {
 
   /* Place the timelime to the left */
   .timeline::after {
     left: 25px;
   }
 
   /* Full-width containers */
   .container-timeline {
     width: 100%;
     padding-left: 70px;
     padding-right: 25px;
   }
 
   /* Make sure that all arrows are pointing leftwards */
   .container-timeline::before {
     left: 60px;
     border: medium solid white;
     border-width: 10px 10px 10px 0;
     border-color: transparent white transparent transparent;
   }
 
   /* Make sure all circles are at the same spot */
   .left-side::after,
   .right-side::after {
     left: 15px;
   }
 
   /* Make all right containers behave like the left ones */
   .right-side {
     left: 0%;
   }
 }
 
 /* format the timeline boxes */
 .timeline-heading {
   color: white;
   border-bottom: 1px solid white;
   font-family: Courier;
 }
 
 .timeline-text {
   color: white;
   font-family: Georgia;
 }
<!DOCTYPE html>

<html lang="en">

<head>
   <meta charset="UTF-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta author="Aminul Islam">

   <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
   <link href="styles.css" rel="stylesheet">
   <title>About me page</title>
</head>

<body class="about-me">
   <div class="timeline">
      <div class="container-timeline left-side">
         <div class="content-timeline">
            <h2 class="timeline-heading">2011</h2>
            <p class="timeline-text">Lorem ipsum.</p>
         </div>
      </div>
      <div class="container-timeline right-side">
         <div class="content-timeline">
            <h2 class="timeline-heading">2012</h2>
            <p class="timeline-text">Lorem ipsum.</p>
         </div>
      </div>
      <div class="container-timeline left-side">
         <div class="content-timeline">
            <h2 class="timeline-heading">2013</h2>
            <p class="timeline-text">Lorem ipsum.</p>
         </div>
      </div>
      <div class="container-timeline right-side">
         <div class="content-timeline">
            <h2 class="timeline-heading">2014</h2>
            <p class="timeline-text">Lorem ipsum.</p>
         </div>
      </div>
   </div>


   <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
</body>

</html>

Javascript相关问答推荐

如何在使用fast-xml-parser构建ML时包括属性值?

如何使用侧边滚动按钮具体滚动每4个格?

Cypress -使用commands.js将数据测试id串在一起失败,但在将它们串在一起时不使用命令有效

如何才能拥有在jQuery终端中执行命令的链接?

docx.js:如何在客户端使用文档修补程序

react—router v6:路由没有路径

TypeScript索引签名模板限制

MathJax可以导入本地HTML文档使用的JS文件吗?

如何将innerHTML字符串修剪为其中的特定元素?

当用户点击保存按钮时,如何实现任务的更改?

SPAN不会在点击时关闭模式,尽管它们可以发送日志(log)等

更新Redux存储中的对象数组

匹配一个或多个可选重复的特定模式

重新呈现-react -筛选数据过多

按特定顺序将4个数组组合在一起,按ID分组

从异步操作返回对象

将以前缓存的 Select 器与querySelector()一起使用

material UI自动完成全宽

无法向甜甜圈图表上的ChartJSImage添加可见标签

检测带有委托的元素内部的点击,以及元素何时按其类名被选中