How to apply style to buttons within div in a component? - vue.js

I am trying to make a component with buttons inside a div, I am having issues, because the styles are not applying on the buttons, I guess I should not use slot here. Can someone guide me?
Component
<template>
<div :class="[$style.btnGroup]" v-bind="$attrs">
<slot :class="$style[variant]">/>
</div>
</template>
How I use this
<ButtonGroup variant="warning">
<button>Test</button>
<button>Test</button>
<button>Test</button>
</ButtonGroup>
I use css module
<style module>
.btnGroup button {
position: relative;
border: none;
font-weight: 400;
border-radius: 0.25rem;
cursor: pointer;
font-size: 1rem;
padding: 0.5rem 1rem;
transition: 0.1s;
}
.primary{
background: var(--primary-bg);
border: 1px solid var(--primary-bg);
color: white;
}
.warning {
background: var(--warning-bg);
border: 1px solid var(--warning-bg);
font-size: 1rem;
padding: 0.5rem 1rem;
transition: 0.1s;
color: black;
}
etc. for each variant I have different style.

You are applying the class on the button group not the buttons that are inside, to solve this instead of binding the class to the slot bind another variable and use that variable binding on each button or you can solve it through css thats why i suggested you show us the css give a class to the buttongroup the way you are doing and in css do as so:
<slot class="buttongroupclass">/>
.buttongroupclass button{
//the css you want to apply
}

Related

Border is not applied correctly when applying :focus to a input

I have an input with a defined border and background color. I apply a transition for the :focus selector which works fine except that the border becomes inner.
input {
border: solid 3px black;
background-color: red;
margin-bottom: 20px;
transition-property: color, background-color, transform;
transition-duration: 2s;
}
input:focus {
color: white;
background-color: blue;
transform: scale(1.5) translate(27px, 0);
margin-top: 10px;
}
<form method="get">
<label for="name">Name:</label><br>
<input type="text" id="name">
</form>
I guess the problem is the scale() function. How can I make the border to be outside when clicking on the input, as usual.
Thanks

Use CSS classes in Vue based on breakpoints

I have tried using a vuetify class based on breakpoint it worked
<v-app :class="{'yellow': !$vuetify.breakpoint.xs}">
I have a class named pagemargin in a vue file
But when I use this class it is not working, as in the following case
<v-app :class="{'pagemargin': !$vuetify.breakpoint.xs}">
why is it not working?
<style >
.pagemargin{
margin-right: 100px;
margin-left: 100px;
color: red;
}
</style>
Add !important to your styles. Vuetify adds its default style to the whole v-app so you need to override it.
.pagemargin{
margin-right: 100px !important;
margin-left: 100px !important;
color: red !important;
}
Using !important might work, but in long term as your application gets bigger, it could be costly. You should instead, solve this by providing a CSS that has a higher specificity than that of Vuetify. I provide you with an example:
<template>
<div class="my-div">
<v-btn :class="{'my-padding': !$vuetify.breakpoint.xs}" tile outlined color="success">
View
</v-btn>
</div>
</template>
<style>
/* this wont work */
.my-div .my-padding {
padding-right: 200px;
padding-left: 200px;
}
/* this works */
.my-div .v-btn.my-padding {
padding-right: 200px;
padding-left: 200px;
}
</style>
<style scoped>
/* this also works */
.my-div .my-padding {
padding-right: 200px;
padding-left: 200px;
}
</style>
You can read more about specificity here.

Vuejs pagination incompatible with bootstrap 4

I am having trouble with this Github package for vuejs pagination. It seem to work on bootstrap 3 but when I use bootstrap 4, it just doesn't work. My problem basically is that bootstrap 4 doesn't style the list item correctly.
I put 'pagination' class on :container-class and it makes the list inline, but not style it like what a normal bootstrap pagination should look. It's just plain list that is inline. I even tried overriding it and putting my own 'mypagination' class on :container-class but still doesn't style it properly. Thanks in advance to you.
//VueJs Paginate code
<paginate
:page-count="20"
:click-handler="functionName"
:prev-text="'Prev'"
:next-text="'Next'"
:container-class="'mypagination'">
</paginate>
//My style code
<style scoped>
.mypagination{
list-style-type: none;
}
.mypagination li {
display: inline !important;
}
.mypagination > li > a,
.mypagination > li > span {
position: relative;
float: left;
padding: 6px 12px;
margin-left: -1px;
line-height: 1.42857143;
color: #337ab7;
text-decoration: none;
background-color: #fff;
border: 1px solid #ddd;
}
</style>
You have to add the following properties for bootstrap 4:
<paginate
:page-count="20"
:click-handler="clickCallback"
:prev-text="'Prev'"
:next-text="'Next'"
:container-class="'pagination'"
:page-class="'page-item'"
:page-link-class="'page-link'"
:prev-class="'page-item'"
:next-class="'page-item'"
:prev-link-class="'page-link'"
:next-link-class="'page-link'"
:active-class="'active'">
</paginate>

How to achieve Glyphicons with "numeric subscripts" inside Bootstrap 3?

Typically, to insert a Glyphicon inside a Bootstrap 3 app, it's as simple as:
<span class="glyphicon glyphicon-envelope"></span>
etc. In many apps, however, it is typical for Glyphicons to be "customized" so that they appear with numeric superscripts like so:
Above, this red/white "5" bubble might indicate that the user has 5 notifications. I'm wondering how this "numeric superscript" effect can be achieved in Bootstrap 3.
You mean something like this?
This is just some CSS basic styling, there is afaik no "standard" and certainly no special HTML tags nor "secret" bootstrap features that supports it. Below my suggestion - modify so it fit your expectations :
.rw-number-notification {
position: absolute;
top: -7px;
right: -6px;
padding: 3px 3px 2px 3px;
background-color: red;
color: white;
font-family: arial;
font-weight: bold;
font-size: 10px;
border-radius: 4px;
box-shadow: 1px 1px 1px silver;
}
markup :
<span class="glyphicon glyphicon-envelope">
<span class="rw-number-notification">7</span>
</span>
demo with some examples -> http://jsfiddle.net/rqfthhkx/
NB: Not completely related, but I do believe, though, that it is common practice to use the <i> tag when you are using glyphicons, fontawesome etc
<i class="glyphicon glyphicon-envelope"></i>
at least it renders as exactly the same -> http://jsfiddle.net/rqfthhkx/1/
Font Awesome
Example:
<i class="fa fa-envelope text-primary">
<span class="number-notification">7</span>
</i>
The .number-notification CSS is the same, except it seems impossible to adjust the position of the number container to fa-xx sizes and different font-sizes. The solution is to wrap the <i> element into <h> elements and specify the relative position in rem units :
.number-notification {
position: relative;
padding: 3px 3px 2px 3px;
background-color:red;
color:white;
font-family: arial;
font-weight:bold;
font-size: 10px;
border-radius: 4px;
box-shadow:1px 1px 1px silver;
}
.fa .number-notification {
top: -1rem;
right: 1rem;
}
h3 .fa .number-notification {
top: -1.2rem;
right: 1.2rem;
}
h2 .fa .number-notification {
top: -1.5rem;
right: 1.5rem;
}
h1 .fa .number-notification {
top: -2.2rem;
right: 1.8rem;
}
This should look more or less the same with different font sizes.
New fiddle -> http://jsfiddle.net/b86oj9gd/

on click toggle for child element of the certain class (handlers) - jquery

When I click on parent, I need to affect one particular child (toggle it's style).
I achieved toggle functionality with handlers:
$(".p1").on({
mouseenter: mouseEnter,
mouseleave: mouseLeave
});
function mouseEnter() {
$(this).css('border', 'solid 5px #999999');
}
function mouseLeave() {
$(this).css('border', 'solid transparent 5px');
}
function handler1() {
$(this).css('border', 'solid 5px #222222');
$(this).off('mouseenter mouseleave');
$(this).one("click", handler2);
}
function handler2() {
$(this).css('border', 'solid transparent 5px');
$(this).on({mouseenter: mouseEnter, mouseleave: mouseLeave});
$(this).one("click", handler1);
}
$(".p1a").parent(".p1").one("click", handler1);
$(".pl").children(".p1").one("click", handler1); //this one doesn't work
http://jsfiddle.net/2czxN/4/
Everything works except for affecting the child by clicking on it's parent (aka the last line).
How can this functionality be added to this function?
The only diffrence in your fiddle is, that the .pl wraps just the first .p1, so the second wont work...
$(".pl").children(".p1").one("click", handler1); //this one doesn't work
<div class="pl" style="width: 300px; height: 150px; background: #888888; border: solid white 5px;">
<div class="p1" style="width: 200px; height: 100px; background: #555555; border: solid transparent 5px;">
<div class="p1a" style="width: 200px; height: 10px; background: #333333;"></div>
</div>
<div class="p1" style="width: 200px; height: 100px; background: #555555; border: solid transparent 5px;">
<div class="p1a" style="width: 200px; height: 10px; background: #333333;"></div>
</div>
</div>
yes, i just wanted to explain why the second declaration isnt working on the seconed p1..
im not sure what you want to achive, something like this?: http://jsfiddle.net/reyaner/3yZmW/
Here is the final function - http://jsfiddle.net/2czxN/6/
Works 100% accurately regardless if you click on children (p1a) or parent (pl).
$(".p1a").one("click", handler1);
$(".pl").one("click", handler1);
Key is in putting all selectors (find, parent) in the handlers with $(this).