简体   繁体   English

如何在 Vuetify 中删除填充或边距?

[英]How to remove padding or margin in Vuetify?

The doc tells me I can use a helper class to change padding/margin.该文档告诉我我可以使用辅助类来更改填充/边距。 I want to remove padding from an input field, so the class I need is pa-0 ( {property}{direction}-{size} ):我想从输入字段中删除填充,所以我需要的类是pa-0 ( {property}{direction}-{size} ):

<v-text-field v-model="mon" pa-0 solo></v-text-field>

JSFiddle here JSFiddle在这里

Doesn't work.不起作用。 Any idea?任何的想法?

EDIT: I realise I obtain a completely different markup in my JSFiddle compared to my local setup, which compounds my confusion:编辑:我意识到与我的本地设置相比,我在我的 JSFiddle 中获得了一个完全不同的标记,这加剧了我的困惑:

Markup generated by Vuetify locally (here I want to remove vertical padding inside the <input> element and horizontal padding on <div class="v-input__slot"> element):由 Vuetify 本地生成的标记(这里我想删除<input>元素内的垂直填充和<div class="v-input__slot">元素上的水平填充):

<div class="v-input v-text-field v-text-field--enclosed v-text-field--outline v-input--is-label-active v-input--is-dirty theme--light">
  <div class="v-input__control">
    <div class="v-input__slot" style="">
      <div class="v-text-field__slot">
        <input type="text" pa-0="">
      </div>
    </div>
    <div class="v-text-field__details">
      <div class="v-messages theme--light">
        <div class="v-messages__wrapper"></div>
      </div>
    </div>
  </div>
</div>

Markup generated by Vuetify on JSFiddle using the exact same line of Vuetify code ( <v-text-field v-model="mon" pa-0 outline></v-text-field> ): Vuetify 在 JSFiddle 上使用完全相同的 Vuetify 代码行( <v-text-field v-model="mon" pa-0 outline></v-text-field> )生成的标记:

<div class="input-group input-group--text-field">
  <div class="input-group__input">
    <input outline="" pa-0="" tabindex="0" type="text">
  </div>
  <div class="input-group__details">
    <div class="input-group__messages"></div>
  </div>
</div>

The lack of examples throughout the docs REALLY doesn't help.整个文档中缺少示例真的无济于事。

使用hide-details选项: <v-text-field hide-details></v-text-field>删除底部边距,因为用于显示详细信息的详细信息字段(如果可用)而出现。

use spacing helpers :使用间距助手

class="ma-0" removes margins class="ma-0"删除边距
class="pa-0" removes padding class="pa-0"删除填充
class="ma-0 pa-0" removes both class="ma-0 pa-0"删除两者

Note that these are also props but only for some (grid) components so for example:请注意,这些也是道具,但仅适用于某些(网格)组件,例如:
<v-text-field class="pa-0"></v-text-field> will work, <v-text-field class="pa-0"></v-text-field>会起作用,
and <v-text-field pa-0></v-text-field> will not work.并且<v-text-field pa-0></v-text-field>将不起作用。

Classes are added on top-level element so if in some components you can't remove child-element(s) spacing with these classes, then likely you need to target relevant elements with CSS.类添加在顶级元素上,因此如果在某些组件中您无法使用这些类删除子元素间距,那么您可能需要使用 CSS 定位相关元素。


To avoid using !important , add custom class on the component and inspect element which you want to edit and then check what's used for targeting it - for example .v-input__slot (we only need highlighted target):为了避免使用!important ,在组件上添加自定义类并检查要编辑的元素,然后检查用于定位它的内容 - 例如.v-input__slot (我们只需要突出显示的目标):

在此处输入图片说明

Then replace it like so ( custom-text-field is arbitrary custom class applied to the component)然后像这样替换它( custom-text-field是应用于组件的任意自定义类)

.custom-text-field.v-text-field.v-text-field--enclosed .v-input__slot {
  padding: 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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