Vue Bootstrap dropdown items color changing - css

Hello I'm making a vertical menu with Vue Bootstrap 4
<b-dropdown id="dropdown-dropright" no-caret dropright :text="result.title" variant="primary" class="drop" v-for="result in resultsmenu.slice(0,4)" :key="result.id">
<span v-on:click="selectedEntry">
<b-dropdown-item class="slide-in-right" v-for="submenu in result.submenu" :key="submenu"><nuxt-link :prefetch="true" :to="submenu.slug">{{submenu.title}}</nuxt-link></b-dropdown-item>
</span>
</b-dropdown>
I'm trying to change the color of the dropdown-items like at first all the dropdown items are black color and if i clicked one of the items of the dropdown the other dropdown items become white
color but the clicked one stay black color.
Hope someone have a way to help me
Thank you

You can try to bind class to dropdown item :
new Vue({
el: '#demo',
data() {
return {
resultsmenu: [{id: 1, title: 'AAA', submenu: [{title: 'aaa', slug: ''}, {title: 'bbb', slug: ''},{title: 'ccc', slug: ''}]}],
active: null
}
},
methods: {
selectedEntry(i) {
this.active = i
}
}
})
.dark {
background: black;
}
.light {
background: white;
}
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue#latest/dist/bootstrap-vue.min.css" />
<script src="//unpkg.com/vue#latest/dist/vue.min.js"></script>
<script src="//unpkg.com/bootstrap-vue#latest/dist/bootstrap-vue.min.js"></script>
<script src="//unpkg.com/bootstrap-vue#latest/dist/bootstrap-vue-icons.min.js"></script>
<div id="demo">
<b-dropdown
id="dropdown-dropright" no-caret dropright
:text="result.title"
variant="primary"
class="drop"
v-for="result in resultsmenu"
:key="result.id"
>
<span>
<b-dropdown-item
class="slide-in-right dark"
v-for="(submenu, i) in result.submenu"
:key="i"
:class="i === active ? 'light' : ''"
v-on:click="selectedEntry(i)"
>
<a :href="submenu.slug">{{submenu.title}}</a>
</b-dropdown-item>
</span>
</b-dropdown>
</div>

Related

Change color of v-select selected element using CSS

I have the following v-select
Vue.config.productionTip = false;
Vue.config.devtools = false;
new Vue({
el: '#app',
vuetify: new Vuetify(),
data(){
return{
company_roles:[{
value: 1,
text: 'CEO'
},
{
value: 2,
text: 'Project Manager'
},
]
}
}
})
.v-list-item__title:hover{
color: #ffd54f !important;
}
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/#mdi/font#4.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/vue#2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.js"></script>
<div id="app">
<v-app>
<v-row>
<v-col cols="12" sm="12" md="6">
<v-select :items="company_roles" label="Role in Company" solo color="yellow"></v-select>
</v-col>
</v-row>
</v-app>
</div>
I could change the hover color before select, but after it's selected, if you open the dropdown again the background and the color are blue, I don't know how to change those. I would like a solution using CSS, not SCSS, thanks.
You can modify css like:
.v-list .v-list-item--active {
background-color: green!important;
}
.v-list .v-list-item--active .v-list-item__title {
color: #ffd54f !important;
}
you can update the colors as per your requirement here. For demo, I have added background green and text color #ffd54f
Working Demo:
Vue.config.productionTip = false;
Vue.config.devtools = false;
new Vue({
el: '#app',
vuetify: new Vuetify(),
data(){
return{
company_roles:[{
value: 1,
text: 'CEO'
},
{
value: 2,
text: 'Project Manager'
},
]
}
}
})
.v-list-item__title:hover{
color: #ffd54f !important;
}
.v-list .v-list-item--active {
background-color: green!important;
}
.v-list .v-list-item--active .v-list-item__title {
color: #ffd54f !important;
}
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/#mdi/font#4.x/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/vue#2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#2.x/dist/vuetify.js"></script>
<div id="app">
<v-app>
<v-row>
<v-col cols="12" sm="12" md="6">
<v-select :items="company_roles" label="Role in Company" solo color="yellow"></v-select>
</v-col>
</v-row>
</v-app>
</div>

How to change arrows color in Bootstrap Vue?

I have a <b-form-select></b-form-select> in Bootstrap Vue and would like to change color of arrows. I tried a lot but arrows still stay black. How can I change the color of them?
You have to change the background of your .custom-select
Arrow color changed:
new Vue({
el: "#app",
data() {
return {
selected: null,
options: [{
value: null,
text: 'Please select an option'
},
{
value: 'a',
text: 'This is First option'
},
{
value: 'b',
text: 'Selected Option'
},
{
value: {
C: '3PO'
},
text: 'This is an option with object value'
},
{
value: 'd',
text: 'This one is disabled',
disabled: true
}
]
}
}
})
/* I changed the fill of the SVG to red */
.custom-select {
background: #fff url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='4' height='5' viewBox='0 0 4 5'%3e%3cpath fill='red' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e") no-repeat right .75rem center/8px 10px !important;
<!-- Load required Bootstrap and BootstrapVue CSS -->
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap-vue#latest/dist/bootstrap-vue.min.css" />
<!-- Load polyfills to support older browsers -->
<script src="//polyfill.io/v3/polyfill.min.js?features=es2015%2CIntersectionObserver" crossorigin="anonymous"></script>
<!-- Load Vue followed by BootstrapVue -->
<script src="//unpkg.com/vue#latest/dist/vue.min.js"></script>
<script src="//unpkg.com/bootstrap-vue#latest/dist/bootstrap-vue.min.js"></script>
<!-- Load the following for BootstrapVueIcons support -->
<script src="//unpkg.com/bootstrap-vue#latest/dist/bootstrap-vue-icons.min.js"></script>
<div id="app">
<b-container>
<b-row>
<b-col>
<div class="mt-3">Selected: <strong>{{ selected }}</strong></div>
<b-form-select v-model="selected" :options="options"></b-form-select>
</b-col>
</b-row>
</b-container>
</div>
This is the CSS solution.
With SASS you can do this without overwriting - just include your modifications, and that overwrite the default value: https://bootstrap-vue.js.org/docs/reference/theming/
Try this with a classname in your css style of
<b-form-select></b-form-select>
Demo: https://jsfiddle.net/bardalesj/uwnp8efr/147/

Change Fontawesome icon in Nativescript Vue

I'm creating a voting system. For both positive and negative votes, i use the same component - VoteButton. How to change the icon ( 'fa-thumbs-o-up' to 'fa-thumbs-up' and 'fa-thumbs-o-down' to 'fa-thumbs-down') when the button is activated? Which is the best option - via CSS (:before), vue.js logic ( IF or something), replace string via JS or something else?
Parent component:
<GridLayout columns="auto,*">
<VoteButton col="0" :buttontext=" 'fa-thumbs-o-up' | fonticon" :votes="upVotes" label="Upvote" :active="upvoted" width="33%" #click="vote(1)" />
<VoteButton col="1" :buttontext=" 'fa-thumbs-o-down' | fonticon" :votes="downVotes" label="Downvote" :active="downvoted" width="33%" #click="vote(-1)" />
</GridLayout>
Parent component CSS:
.upvote.active {
background: orangered;
color: white;
}
.downvote.active {
background: blue;
color: white;
}
VoteButton child component:
<template>
<button #tap="$emit('click')" :class="[buttonClass, { active }]">
<FormattedString>
<Span class="fa" > {{ buttontext }}</Span>
<Span> {{ votes }}</Span>
</FormattedString>
</button>
</template>
<script>
export default {
props: {
active: Boolean,
label: String,
buttontext: String,
votes: Number
},
computed: {
buttonClass() {
return this.label.toLowerCase();
}
}
};
</script>
You could use a counter in javascript to keep track of whether the button should be displaying an upvote or a downvote based on the number of times the button is pressed.
Example:
Html:
<button onclick="myFunction()">Try it</button>
<div id="myDIV">
This is a DIV element.
</div>
CSS:
<style>
.mystyle {
background: orangered;
color: white;
}
.mystyle2 {
background: blue;
color: white;
}
</style>
Javascript:
<script>
var x = 0;
function myFunction() {
var element = document.getElementById("myDIV");
if (x % 2 == 0){
element.classList.add("mystyle");
element.classList.remove("mystyle2");
x++;
}
else {
element.classList.add("mystyle2");
element.classList.remove("mystyle");
x++;
}
}
</script>
Thanks! I did it the following way:
Parent:
<VoteButton col="0" noactivefatext='fa-thumbs-o-up' activefatext='fa-thumbs-up' :votes="upVotes" label="Upvote" :active="upvoted" #click="vote(1)" />
<VoteButton col="1" noactivefatext='fa-thumbs-o-down' activefatext='fa-thumbs-down' :votes="downVotes" label="Downvote" :active="downvoted" #click="vote(-1)" />
VoteButton component:
<template>
<button #tap="$emit('click')" :class="[buttonClass, { active }]">
<FormattedString>
<Span class="fa body" :text="active ? activefatext : noactivefatext | fonticon" ></Span>
<Span> {{ votes }}</Span>
</FormattedString>
</button>
</template>

How can I add conditional style in Vue.js?

I want to add a conditional style in my Component.
My component is below:
<site-pricing
color="primary"
currency="$"
price="25"
to="/purchase"
>
<template v-slot:title>Complete</template>
<template v-slot:desc>{{ $t('plans.completeDesc' )}}</template>
<template v-slot:planSuffix>/ {{ $t('plans.oneTime' )}}</template>
<template v-slot:features>
<ul>
<li>{{ $t('plans.xchats', [ 200 ] )}}</li>
<li>{{ $t('plans.sDomain' )}}</li>
</ul>
</template>
<template v-slot:footer>{{ $t('plans.oneTime' )}}</template>
</site-pricing>
I want to add a special style just like, if 'color = primary', then add a border-top: 5px red...
You should use the conditional style binding for vue. I'll show an example:
new Vue({
el: '#app',
data: {
color: "secondary"
},
methods: {
toggleColor(val) {
this.color = val
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<div :style="[color==='primary' ? {color: 'red'} : {color: 'blue'}]">Primary</div>
<div :style="[color==='secondary' ? {color: 'red'} : {color: 'blue'}]">Secondary</div>
<button #click="(e) => toggleColor('primary')">Switch to pirmary</button>
<button #click="(e) => toggleColor('secondary')">Switch to secondary</button>
</div>

Blur all But one div in ng-repeat

I am making an angularJS app where my goal is, when a user clicks a button inside one of the ng-repeat div, it should get focus by blurring all the other entries in of ng-repeat. I have created a minimal plunkr and described the problem with the image below.
I have this html
<ul ng-repeat="detail in details">
<li>
<div style="border-style:solid;"> {{detail.name}} </div>
</li>
</ul>
and the Empty Controller:
app.controller('MainCtrl', function ($scope) {
$scope.details =
[
{ "name": "Employees" },
{ "name": "Support" }
];
$scope.details.name =
[
{ "prof": "enginerr" },
{ "prof": "doctor" }
];
});
I have also added an image for demonstration
and created a plunkr for reference.
I am trying to achieve the bottom part of the image.
Thanks in advance.
Here's the sample I have created , please refer to it . Hopes this help you out. Thanks.
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.details = [
{ "name": "Employees" },
{ "name": "Support" }
];
$scope.details.name = [
{ "prof": "enginerr" },
{ "prof": "doctor" }
];
$scope.isActive=false;
$scope.clickMe = function(index){
$scope.currentIndex=index;
$scope.isActive=!$scope.isActive;
}
});
/* Put your css in here */
.notActive {
pointer-events: none;
cursor: not-allowed;
opacity: 0.3;
}
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>
document.write('<base href="' + document.location + '" />');
</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js#1.0.x" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js" data-semver="1.0.8"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<ul ng-repeat="detail in details">
<li style="border-style:solid;" ng-class="{'notActive':isActive && currentIndex!=$index}">
<div > {{detail.name}} </div>
<button ng-click="clickMe($index)">Click me</button>
</li>
</ul>
</body>
</html>

Resources