如何正确调整CSS的边距?

时间:2019-06-05 09:15:50

标签: css

我有一个简单的分布式系统项目,旨在开发航空公司的预订和购买系统。在该项目中,主要目标是实现适当的功能,而不是获得最佳的可视性。但是,由于缺乏网页设计领域的经验,我确实遇到了基本问题。 您的任何兴趣将不胜感激!

在我的主页上,我试图绘制飞机布局,但问题出在边距上。我不能在飞机边界之间正确安排座位。

我丑陋的home.php的演示:
? safe call

我的home.php的体系结构:

<div class="content">
...
   <div class="airplane">
   ...
      <div class="cockpit">...</div>

      <ol class="fuselage">
         <li class="row row--1">
            <ol class="seats">
               <li class="seat">...</li>
            </ol>
         </ol>
     </ol>
  </div>
</div>

这是我的CSS代码:

div.content
{
  margin-left: 200px;
  padding: 1px 16px;
  height: auto;             
}

@media screen and (max-width: 700px)
{
  .sidebar
  {
    width: 100%;
    height: auto;
    position: relative;
  }
  .sidebar a
  {
    float: left;
  }
  div.content
  {
    margin-left: 0;
  }
}

@media screen and (max-width: 400px)
{
  .sidebar a
  {
    text-align: center;
    float: none;
  }
}

.airplane
{
  margin: 10px auto;
  max-width: 500px;
  position: relative;
  margin-left: 25px;
}

.cockpit
{
  margin-left: 25px;
  height: 250px;
  position: relative;
  overflow:hidden;
  text-align: center;
  border-bottom: 5px solid #993333;
}

.cockpit:before
{
  content: "";
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  height: 500px;
  width: 98%;                         
  border-radius: 50%;
  border-right: 5px solid #993333;
  border-left: 5px solid #993333;
}

.cockpit h2 {
  width: 70%;                         
  margin: 120px auto 35px auto;       
}

.fuselage
{
  margin-left: 25px;                  
  border-right: 5px solid #993333;
  border-left: 5px solid #993333;
}

ol
{
  list-style :none;
  padding: 0;
  margin: 0;
}

.row
{

}

.seats
{
  margin-left: 25px;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: flex-start;
  margin: 0 5px 0 250px;                
}

.seat {
  display: flex;
  flex: 0 0 25.28571428571429%;
  padding: 5px;
  position: relative;
}
.seat:nth-child(3) {
  margin-right: 15.28571428571429%;     
}

.seat input[type=checkbox] {
  position: absolute;
  opacity: 0;
}
.seat input[type=checkbox]:checked + label {
  background: yellow;
}
.seat input[type=checkbox]:disabled + label {
  background: #dddddd;
  text-indent: -9999px;
  overflow: hidden;
}
.seat input[type=checkbox]:disabled + label:after {
  content: "X";
  text-indent: 0;
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translate(-50%, 0%);
}
.seat input[type=checkbox]:disabled + label:hover {
  box-shadow: none;
  cursor: not-allowed;
}
.seat label {
  display: block;
  position: relative;
  width: 70%;
  text-align: center;
  font-size: 11px;
  font-weight: bold;
  line-height: 1.5rem;
  padding: 4px 0px;
  background: green;
  border-radius: 5px;
}
.seat label:before {
  content: "";
  position: absolute;
  width: 75%;
  height: 75%;
  top: 1px;
  left: 50%;
  transform: translate(-50%, 0%);
  background: rgba(255, 255, 255, 0.4);
  border-radius: 3px;
}
.seat label:hover {
  cursor: pointer;
  box-shadow: 0 0 0px 2px #5C6AFF;
}

2 个答案:

答案 0 :(得分:0)

您可以在代码的以下部分中固定左边距:

.seat {
    display: flex;
    flex: 0 0 25.28571428571429%;
    padding: 5px;
    margin-left: -50px;    // lay seats over plane borders
    position: relative;
}

通过这种自定义,您可以将座位放在飞机上。 此值仅用于演示目的,仅供示例

答案 1 :(得分:0)

请您尝试下面的座位类吗?

.seats
{
  margin-left: 25px;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: flex-end;
  margin: 0 5px 0 200px;              
}