将代码重写到Bootstrap 3.3.7

时间:2018-07-13 07:31:59

标签: html css twitter-bootstrap

我使用的Bootstrap不正确,因此我正在重写代码。我可以理解,遵循以下结构很重要:container > row > col。我正在使用卡片,因此,当视口在768px以下时,块元素将是卡片。演示可以在这里查看:

在我正确使用Bootstrap之前:Before rewrite

在我重写正确的Bootstrap之后:After rewrite to bootstrap

在我重写以正确使用Bootstrap之后,块元素在彼此之上飞行。如我所见-它是类:<div class="index-content">导致了此问题。如果该类低于row,则它可以工作,但是如果我将<div class="index-content">设置在<div class="col-sm-4">内,则这些块会飞来飞去。

有人知道我该如何解决这个问题?

我曾经工作过的原始代码如下:

<div class="row">
    <div class="index-content">
        <div class="container">
            <div class="col-sm-4 small-padding right bottom">
                <div class="card">
                    <img src="https://image.ibb.co/iiWA2T/bmw_1.jpg"></img>
                    <div class="card-content">
                        <h4>BMW NEW MODELS</h4>
                        <a href="#" class="blue-button">Read More</a>
                    </div>
                </div>
            </div>
            <div class="col-sm-8 small-padding left">
                <div class="card">
                    <img src="https://image.ibb.co/nJ97Go/bmw.jpg"></img>
                    <div class="card-content">
                        <h4>BMW NEW MODELS</h4>
                        <!-- <p>Brødtekst</p> -->
                        <a href="#" class="blue-button">Read More</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

重写为正确的Bootstrap后:

<div class="container">
    <div class="row">
        <div class="col-sm-4 small-padding right bottom">
            <div class="index-content">
                <div class="card">
                    <img src="https://image.ibb.co/iiWA2T/bmw_1.jpg"></img>
                    <div class="card-content">
                        <h4>BMW NEW MODELS</h4>
                        <a href="#" class="blue-button">Read More</a>
                    </div>
                </div>
            </div>
            <div class="col-sm-8 small-padding left">
                <div class="card">
                    <img src="https://image.ibb.co/nJ97Go/bmw.jpg"></img>
                    <div class="card-content">
                        <h4>BMW NEW MODELS</h4>
                        <!-- <p>Brødtekst</p> -->
                        <a href="#" class="blue-button">Read More</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
      /* Card and Button */
    .index-content a:hover {
      color: black;
      text-decoration: none;
    }

    .index-content {
      /*margin-bottom: 20px;*/
      /*padding: 50px 0px;*/
    }

    .index-content .row {
      margin-top: 20px;
    }

    .index-content a {
      color: black;
    }

    .index-content .card {
      background-color: #FFFFFF;
      padding: 0;
      -webkit-border-radius: 4px;
      -moz-border-radius: 4px;
      border-radius: 4px;
      box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    }

    .index-content .card:hover {
      box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
      color: black;
    }

    .index-content .card img {
      width: 100%;
      border-top-left-radius: 4px;
      border-top-right-radius: 4px;
      height: 350px;

    }

    .index-content .card h4 {
      margin: 20px;
    }

    .index-content .card p {
      margin: 20px;
      opacity: 0.65;
    }

    .index-content .blue-button {
      width: 100px;
      -webkit-transition: background-color 1s, color 1s;
      /* For Safari 3.1 to 6.0 */
      transition: background-color 1s, color 1s;
      min-height: 20px;
      background-color: #002E5B;
      color: #ffffff;
      border-radius: 4px;
      text-align: center;
      font-weight: lighter;
      margin: 0px 20px 15px 20px;
      padding: 5px 0px;
      display: inline-block;
    }

    .index-content .blue-button:hover {
      background-color: #dadada;
      color: #002E5B;
    }

    @media (max-width: 768px) {
      .index-content .col-lg-4 {
        margin-top: 20px;
      }
    }

    @media (min-width: 768px) {
      .card {
        position: relative;
      }
      .card-content {
        position: absolute;
        bottom: 0;
        width: 100%;
        background: rgba(0, 0, 0, 0.5);
      }
      .card-content h4,
      .card-content p {
        color: white;
        width: 100%;
        float: left;
        margin: 0 0 5px;
      }
      .card-content a {
        float: right;
      }
      .index-content .card h4,
      .index-content .card p {
        padding: 15px 20px;
        margin: 0;
      }
      .index-content .card p {
        padding: 0 20px 15px;
        margin: 0;
      }
    }

    /* GRID ELEMENTS */
        /* Set width between block elements */
        .small-padding.top {
           padding-top:10px;
        }

        .small-padding.bottom {
            padding-bottom:10px;
        } 
        .small-padding.left {
            padding-left:5px;
        }

        .small-padding.right {
            padding-right:5px;
        }
        /* Media quries */
        @media only screen and (max-width: 768px) {
            .small-padding.bottom {
            padding-bottom:10px;
        } 

        }
        @media only screen and (max-width: 768px) {

        .row [class*="col-"] {
          padding-left: 5px;
          padding-right: 5px;
      }

        }
    </style>

1 个答案:

答案 0 :(得分:0)

<body>
    <div>

        <!-- search bar -->
        <div>
            <h1>List of Vehicles </h1>
            <mat-form-field style="margin: 0 0 15px 0;" class="example-full-width">
                <input matInput #message maxlength="256" placeholder="Search for vehicle.." [ngModel]="message.value" (keyup)='filter(message.value)'>
                <mat-hint align="start">
                    <strong>Type vehicle name</strong>
                </mat-hint>
            </mat-form-field>
        </div>

        <!-- map, showing the position of the vehicles -->
        <div id="mapid">
        </div>

        <!-- progressbar -->

        <mat-progress-bar *ngIf="disabled" mode="indeterminate" class="progressbar"></mat-progress-bar>



        <!-- list of alarms of selected vehicle -->
        <div class="details">
            <mat-nav-list>
                <h3>List of alarms: ..... </h3>
                <mat-list-item *ngFor=".... ">
                    <p matLine style="white-space: normal">
                        <span [ngClass]="...."> .... </span> :
                        <span style="font-weight: bold;"> Description: </span> ....
                        <br/>
                        <span style="font-weight: bold;"> Details: </span> ....</p>
                </mat-list-item>
            </mat-nav-list>

            <mat-nav-list>
                <h3>Signal Information: .... </h3>
                <mat-list-item *ngFor=".... ">
                    <p matLine>
                        <span style="font-weight: bold"> .... </span>
                    </p>
                </mat-list-item>
            </mat-nav-list>
        </div>

        <!-- list of vehicles -->
        <aside class="vehiclelist">
            <mat-nav-list matSort (matSortChange)="sortData($event)">
                <th mat-sort-header="timestamp">Latest alarm</th>
                <th mat-sort-header="status">Status</th>
                <mat-list-item *ngFor="...." class="vehicles">
                    <span [ngClass]=....>
                    </span>
                    <p matLine> .... </p>
                    <button mat-icon-button id="btn" *ngIf=...>
                        <mat-icon>info</mat-icon>
                    </button>
                </mat-list-item>
            </mat-nav-list>
        </aside>
    </div>

</body>