简体   繁体   中英

How can I properly adjust margins in my css?

I have a simple distributed system project which aims to develop airlines booking and purchase system. In this project, the main goal is to achieve proper functionalities, not to achieve best visuality. However, I have really basic problem due to my lack of experience in web design area. Any kind of interest of you will be appreciated!

In my home page, I tried to draw an airplane layout but the problem is margins. I can not arrange properly the seats in between plane borders.

Demonstration of my ugly home.php:
在此输入图像描述

Architecture of my 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>

Here is my CSS code:

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;
}

You can fix your margin-left in the following part of your code:

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

With this customization, you can lay your seats over the plane. This value is for demonstration purposes only and as an example

Could you please try seats class in below;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM