Fixed the width of select2

Fixed the width of select2



I am using select2 for selecting a candidate skill.
I don't want to change my select box width, I want Fixed width for my slelet2


select2



Here is the Image



What have I Tried So far?


//HTML
<select class="skill_select_id" name="skill_select_id">
<?php foreach ( $skills as $skill ) ?>
<option value="<?= $skill['id'] ?>" ><?= $skill['name'] ?></option>
<?php ?>
</select>



First I use resolve


resolve


//Script
$('.skill_select_id').select2(tags:true, width: 'resolve');



I have also tried element, 100% option in width


element


100%


width


//Another Try
$('.skill_select_id').select2(tags:true, width: 'element');



But it didn't help me to set a Fixed width of select2.



I don't want to add inline CSS to solve this problem because if I use the plugin then it must have some solution for this type of problems.


inline CSS






Can you share your code on jsfiddle.com or jsbin.com ?

– CodeWalker
Jul 1 '17 at 6:38






@CodeWalker ok let me try because never created fiddle before.

– user8239841
Jul 1 '17 at 11:26




1 Answer
1



To fix my dropdown width, setting it to 'element' on select2 initialization worked fine for me:


$("#dropDown").select2( width: 'element' );



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)