I'm trying to override min-height property of a class named application--wrap but the code only works when declared into CSS style:
Code that works:
<style lang="css" scoped>
.application--wrap{
min-height: 0px;
}
</style>
Code that doesn't works:
<style lang="sass" scoped>
.application--wrap
min-height: 0px;
</style>
"Full" code:
<v-app>
<div class="container-fluid centerTable">
<v-data-table
v-bind:headers="headers"
:items="listLayers"
:rows-per-page-items= "[5, 10]"
:custom-sort="customSort"
:loading="loading"
v-bind:pagination.sync="pagination"
class="elevation-1 layersTable"
>
</v-app>
The class that i'm trying to override it's created on render by the Vuetify.
Related
Summary: I need to style the contents of a <slot>, from the child component. I'm using scoped css and the styles don't apply:
I have the following two components:
<!-- Parent.vue -->
<template>
<h1>{{ msg }} from Parent</h1>
<Child>
<h1>{{ msg }} from Child</h1>
</Child>
</template>
...
<style scoped>
h1 {
color: green;
}
</style>
<!-- Child.vue -->
<template>
<slot></slot>
</template>
...
<style scoped>
h1 {
color: red;
}
</style>
I want the 2nd <h1> to be red, but it's green, since the component is rendered with something like:
<h1 data-v-452d6c4c data-v-2dcc19c8-s>Hello from Child</h1>
<style>
h1[data-v-452d6c4c] {
color: green;
}
h1[data-v-2dcc19c8] {
color: red;
}
</style>
data-v-452d6c4c comes from Parent, and data-v-2dcc19c8-s from Child
If the second attribute, in the <h1> tag, was just data-v-2dcc19c8 the style I wanted would be applied, but since it has that -s suffix (slot?), it doesn't.
I could probably find some other solution with a class or something, but I rarely use <slot> and I want to understand the inner workings. That -s tells me that what I'm trying to do can be dealt with the help of the framework, what am I missing?
A working sample:
https://codesandbox.io/s/condescending-brown-ilfwn
Use the new :slotted selector in Vue 3:
Child.vue
<template>
<slot></slot>
</template>
<script>
export default {
name: "Child",
};
</script>
<style scoped>
:slotted(h1) {
color: red !important;
}
</style>
In Vue 3, child scoped styles don't affect slotted content by default.
In your particular example, the !important modifier is also necessary because the parent also defined an h1 style which would take precedence otherwise
I have using Nuxt.js and Vuetify.js in my project.
I need to adjust v-divider width, so I tried to write css in my code.
But it didn't work.
Does anyone teach me how to change v-divider width in Vuetify components?
<template>
<divider class="test"/>
</template>
<style lang="scss" scoped>
.test{ width:100px}
</style>
vuetify <v-divider> uses border properties. So instead of width you should specify borders.
const opts = {}
Vue.use(Vuetify)
new Vue ({
el: '#app',
vuetify: new Vuetify(opts),
})
.test {
border-width: 4px !important;
border-color: black !important;
height: 100%;
}
body, .container, html {
width:100%;
height: 100%;
}
<link href="https://cdn.jsdelivr.net/npm/vuetify/dist/vuetify.min.css" rel="stylesheet">
<div id="app" class="container">
<v-app>
<v-divider class="test" vertical></v-divider>
</v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify/dist/vuetify.js"></script>
Just a typo of <divider/> instead of <v-divider/>.
Alternatively (and not really recommended), you can set the width by specifying the width attribute of <v-divider/> since it uses <hr/> element. However, this approach seems to be deprecated and the best approach is to style it using css.
<v-divider width="100"/>
I am using b-tooltip tags of BootstrapVue to show information. I want to increase the width of b-tooltip (for long text message), text alignment, etc . How can i do it (basically how can i style it)?
<b-button id="tooltip-target-1">
Hover Me
</b-button>
<b-tooltip target="tooltip-target-1" triggers="hover">
I am tooltip <b>component</b> content!
</b-tooltip>
If you're using SCSS in your project, then the easiest way for a global solution would be to modify the SCSS variables to your liking.
If you want to only apply styles to a specific tooltip, or apply something there isn't a variable for. You can use the custom-class prop on b-tooltip to supply it with a custom class, which allows you to style it to your liking.
If you're placing this CSS in a scoped style tag <style scoped> you will need to use a deep selector to target the subcomponents such as .tooltip-inner.
new Vue({
el: '#app',
})
.custom-tooltip > .tooltip-inner{
/* Removes the default max-width */
max-width: none;
/* Apply whatever other styles you want */
font-size: 150%;
padding: 10px;
}
/* This styling is just for the example */
#app {
display: flex;
height: 100vh;
width: 100vw;
align-items: center;
justify-content: center;
}
<link href="https://unpkg.com/bootstrap#4.4.1/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://unpkg.com/bootstrap-vue#2.14.0/dist/bootstrap-vue.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.js"></script>
<script src="https://unpkg.com/bootstrap-vue#2.14.0/dist/bootstrap-vue.js"></script>
<div id="app">
<div>
<b-button id="tooltip-target-1">
Hover Me
</b-button>
<!-- Use the variant prop to use your theme colors -->
<!-- If you want a custom color, you can use CSS -->
<b-tooltip target="tooltip-target-1" variant="primary" custom-class="custom-tooltip" triggers="click">
I am tooltip <b>component</b> content!
</b-tooltip>
</div>
</div>
The trick to change styles of bootstrapvue tooltip.
<style>
.tooltip-inner {
max-width: 800px;
}
</style>
Don't use scoped in style because the component render the html of tooltip outside of app so if you put scoped your css will not work.
I am trying to style my child components. Isit wrong to put the style in a parent component? It appears that does not work.
I put the style for .card-page in the top level element (containing expenses-module where I use it)
<dom-module id="expenses-app">
<template>
<style>
...
.card-page {
display: block;
width: 100%;
}
</style>
<app-drawer-layout>
<app-header-layout>
...
<iron-pages selected="{{routeData.view}}" attr-for-selected="name">
<dashboard-module name="dashboard" route="{{subroute}}"></dashboard-module>
<expenses-module name="expenses" route="{{subroute}}"></expenses-module>
<settings-module name="settings" route="{{subroute}}"></settings-module>
</iron-pages>
</app-header-layout>
</app-drawer-layout>
</template>
In expenses module,
<paper-card heading="Expenses" class="card-page">...
</paper-card>
Seems like if I move the styles into expenses-module it works.
You cannot directly style elements inside custom element from their parents like that, because Polymer processes the style within <dom-module> and will apply styles only to direct child members. It will not descend into child custom elements.
In other words, standard CSS selectors will only work within the scope of the declaring component. Both in Shadow and Shady DOM.
For your styles to work with nested elements, you should use CSS mixins and properties. All PolymerElements and many 3rd party elements will come with such styling extension points. The naming usually follow the convention, where the main mixin is called same as the element itself. Additionally, there may be more specific mixins and properties, which style only parts of the element. <paper-card> docs for example lists --paper-card mixin, --paper-card-content mixin, --paper-card-header-color and more.
If you want to better control the styling of elements you use, you would want to create your own CSS mixins/properties and #apply() them to selected elements. See how in the example below --my-elem-card-page applies only to one of the two paper cards.
<!DOCTYPE html>
<html>
<head>
<base href="https://polygit.org/components/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link href="polymer/polymer.html" rel="import"/>
<link href="paper-card/paper-card.html" rel="import"/>
</head>
<body>
<my-wrapper></my-wrapper>
<dom-module id="my-elem">
<template>
<style>
.card-page {
#apply(--my-elem-card-page);
}
</style>
<paper-card heading="my-elem specific style" class="card-page">
<div class="card-content">
Content here
</div>
</paper-card>
<paper-card heading="Default style" class="unstyled-page">
<div class="card-content">
Content here
</div>
</paper-card>
</template>
</dom-module>
<dom-module id="my-wrapper">
<template>
<style>
# will be ignored
paper-card {
width: 200px;
}
my-elem{
--paper-card: {
color: blue;
display: block;
}
}
my-elem {
--my-elem-card-page: {
color: red;
}
}
</style>
<my-elem></my-elem>
</template>
</dom-module>
<script>
Polymer({
is: 'my-elem'
});
Polymer({
is: 'my-wrapper'
});
</script>
</body>
</html>
I am trying to mix the template repeater and the paper-card tutorial in the Polymer Starter Kit.
My aim is to copy that kind of grid :
(source: instantshift.com)
I created two custom elements :
A list of employees
An employee
Employee List:
<style is="custom-style">
#board {
#apply(--layout-vertical); <<= HERE ARE DEFINED THE LAYOUT OF THE GRID
#apply(--layout-wrap);
height: 344px;
width: 384px;
}
#board > paper-card {
box-sizing: border-box;
max-width: 184px;
margin: 4px;
flex: 0 0 auto;
}
</style>
<template>
<div id="board">
<template is="dom-repeat" items="{{employeesArray}}">
<employee-element name="{{item.title}}"
preview="{{item.preview}}"
width={{item.width}} height={{item.height}}>
</employee-element>
</template>
</div>
</template>
Employee :
<paper-card
heading="{{name}}"
image="{{preview}}"
style="max-width:{{width}}px;
max-height:{{height}}px;"
>
<div class="card-actions">
<paper-icon-button class="favorite" icon="favorite"></paper-icon-button>
<paper-icon-button class="bookmark" icon="bookmark"></paper-icon-button>
<paper-icon-button class="share" icon="social:share"></paper-icon-button>
</div>
</paper-card>
Here is what I get :
How can I approach the result expected ? Is there a setting making the card arranging themselves automatically ?
How can I get a "carriage return"-like behaviour ?
Answer results (thanks to #Snekw) :
Steps :
Add the following line where you import your elements (elements/elements.html in my case)
<link rel="import" href="../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
My Employee list element now looks like :
<style is="custom-style" include="iron-flex">
.flex-wrap {
#apply(--layout-horizontal);
#apply(--layout-wrap);
}
</style>
<template>
<div class="container flex-wrap">
<template is="dom-repeat" items="{{employeesArray}}">
<employee-element name="{{item.title}}"
preview="{{item.preview}}"
width={{item.width}} height={{item.height}}>
</employee-element>
</template>
</div>
</template>
And I get this result :
I still have to fix the problem with the paper-card action panel.
You need to include the iron-flex class on your style tag.
<style is="custom-style" include="iron-flex">
//your styling
</style>
You will need to load the iron-flex-layout-classes.html element. Iron-flex-layout element contains the --layout-vertical and --layout-wrap properties.
More on iron-flex-layout here: iron-flex-layout-classes GitHub