簡體   English   中英

如果我們有極長的水平滾動頁面,如何在最后一個元素的末尾添加邊距/填充,即空間?

[英]How to add margin/padding i.e space right to the end of the last element if we have extremely long horizontal scrolling page?

如何在最后一個元素的右側添加一些空間,即在我們的例子中,在第 20 個 100px*100px 的框相互對齊之后。 jsfiddle

html

<div class="container">
  <div class="element" v-for="element in 20" :key="element">{{ element }}</div>
</div>

css

.container {
  display: flex;
  flex-direction: row;
  padding-right: 50px;   // not working
  margin-right: 50px;    // not working
}

.element {
  margin: 16px;
  min-width: 100px;
  height: 100px;
  background-color: #ddd;
  border-radius: 10px;
}

我添加了一個

display: inline-flex;

to.container 然后它就可以工作了

你可以在這里看到它: https://jsfiddle.net/q2f6710x/4/

你可以添加一個

overflow: auto;

到#app

使其可滾動: https://jsfiddle.net/2uex398f/

嘗試添加到您的容器 class 也 justify-content:center。

.container {
  display: flex;
  flex-direction: row;
  justify-content:center;
}

您可以隨時將引導程序添加到您的代碼中,

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>

或者在這個網站上https://getbootstrap.com/docs/4.3/getting-started/download/

如果添加引導程序,則可以使用諸如

class="mr-1"

或者

class="pr-1"

其中 1 可以替換為任意數字以增加填充或邊距

您還可以保留所有先前的樣式。

您是否嘗試將這些屬性標記為重要?

.container {
  display: flex;
  flex-direction: row;
  padding-right: 50px !important;   // not working
  margin-right: 50px !important;    // not working
}

暫無
暫無

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

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