簡體   English   中英

如何在我的CSS中正確調整邊距?

[英]How can I properly adjust margins in my css?

我有一個簡單的分布式系統項目,旨在開發航空公司的預訂和購買系統。 在這個項目中,主要目標是實現適當的功能,而不是實現最佳的可視性。 但是,由於我缺乏網頁設計領域的經驗,我確實遇到了基本的問題。 任何您的興趣將不勝感激!

在我的主頁上,我嘗試繪制飛機布局,但問題是邊緣。 我無法正確安排飛機邊界之間的座位。

演示我丑陋的home.php:
在此輸入圖像描述

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

您可以在代碼的以下部分中修復剩余邊距:

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

通過此自定義,您可以將座位放在飛機上。 此值僅用於演示目的,並作為示例

你能不能試試下面的座位;

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM