Antd select dropdown 样式修改

Antd select dropdown 样式修改

官网提供了dropdownClassName属性,链接
测试代码:

<template>
  <div class="select-container">
    <a-select
        v-model:value="select"
        :options="options"
        :getPopupContainer="triggerNode => triggerNode.parentNode"
        dropdown-class-name="dropdown-class"
        style="width: 120px"
    />
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';

const select = ref<string>('1')
const options = [{
  value: '1',
  label: '黄金糕'
}, {
  value: '2',
  label: '双皮奶'
}, {
  value: '3',
  label: '蚵仔煎'
}, {
  value: '4',
  label: '龙须面'
}, {
  value: '5',
  label: '北京烤鸭'
}]
</script>

<script lang="ts">
export default {
  name: 'Test'
}
</script>

<style lang="less" scoped>
.select-container {
  height: 400px;
  width: 100%;
}

:deep(.ant-select) {
  color: #44f0e9;

  .ant-select-selector {
    background: #3935c7;
    border: none;
  }

  .ant-select-arrow {
    color: #44f0e9;
  }
}
</style>

<style lang="less">
.dropdown-class {
  background-color: #3935c7;

  .ant-select-item-option-selected, .ant-select-item-option-active {
    color: #44f0e9;
    background-color: transparent;
  }
}
</style>

:getPopupContainer="triggerNode => triggerNode.parentNode"
可以保证在按了F11进入全屏后也能显示下拉框

.ant-select-item-option-selected这些个类名可以在antd的源码中查找,根据需要去修改,路径一般在:node_modules/ant-design-vue/es/select/style/index.css

个人理解,自定义的.dropdown-class是覆盖了.ant-select-dropdown样式,所以在修改的时候需要按照源码中提示的层级结构进行修改

效果:
在这里插入图片描述

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
antd-Dropdown样式可以通过CSS样式表或者内联样式进行设置。以下是一些常见的样式属性: 1. dropdownClassName:设置下拉框的类名。 2. overlayClassName:设置下拉框中选项的类名。 3. style:设置下拉框的样式,可以使用JavaScript对象或者CSS字符串。 4. overlayStyle:设置下拉框中选项的样式,可以使用JavaScript对象或者CSS字符串。 以下是一个CSS样式表的例子: ```css .dropdown { background-color: #fff; border: 1px solid #d9d9d9; border-radius: 4px; box-shadow: 0 2px 8px rgba(0,0,0,.15); } .dropdown-item { color: #333; padding: 8px 16px; } .dropdown-item:hover { background-color: #f5f5f5; } ``` 然后在组件中引入该样式表: ```jsx import React from 'react'; import { Dropdown, Menu } from 'antd'; import './style.css'; const menu = ( <Menu> <Menu.Item key="1">Option 1</Menu.Item> <Menu.Item key="2">Option 2</Menu.Item> <Menu.Item key="3">Option 3</Menu.Item> </Menu> ); const App = () => ( <Dropdown overlay={menu} trigger={['click']}> <a className="ant-dropdown-link" onClick={e => e.preventDefault()}> Click me </a> </Dropdown> ); export default App; ``` 如果需要使用内联样式,可以在组件中设置 style 属性: ```jsx import React from 'react'; import { Dropdown, Menu } from 'antd'; const menu = ( <Menu style={{ backgroundColor: '#f5f5f5' }}> <Menu.Item key="1" style={{ color: '#333' }}>Option 1</Menu.Item> <Menu.Item key="2" style={{ color: '#333' }}>Option 2</Menu.Item> <Menu.Item key="3" style={{ color: '#333' }}>Option 3</Menu.Item> </Menu> ); const App = () => ( <Dropdown overlay={menu} trigger={['click']} style={{ backgroundColor: '#fff', border: '1px solid #d9d9d9' }}> <a className="ant-dropdown-link" onClick={e => e.preventDefault()}> Click me </a> </Dropdown> ); export default App; ``` 以上是antd-Dropdown样式设置方法,可以根据自己的需要进行调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值