Skip to Content
Menu
This question has been flagged
1 Reply
26243 Views

Hi,

I want to apply css on fields of odoo form view. not like <field name="add_more"    style="" /> not in style attribute ,i want to add a new class in css file of static folder,and want to apply <field name="add_more" class="c_class" /> like here.

I tried this but not getting success,added css in css file not showing any affect on field of for view

Avatar
Discard
Best Answer

Try doing the following in a new module or in an already existing custom module:

  1. Create a new css file under the file structure: your_module/static/src/css/your_style_sheet.css

  2. Create a new XML file under the file structure: your_module/views/css_loader.xml

  3. Add a new line in your modules `__manifest__.py`'s data section `views/css_loader.xml`

Edit the `css_loader.xml` file to look like this:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<!-- Load css File -->
<template id="my_custom_css_asset" name="my_custom_css assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/your_module/static/src/css/your_style_sheet.css"/>
</xpath>
</template>
</data>
</odoo>

The `__manifest__.py` files data section should look like this after the edit:

'data': [
'views/foo.xml',
'views/ls_ui.xml',
'views/bar.xml',
],

Avatar
Discard

It works! Thank you