I would like to set my ion-select with 100% of width.
I have tried with css class like this:
.mySelect { width: 100% !important; } But it is not working.
I would like to set my ion-select with 100% of width.
I have tried with css class like this:
.mySelect { width: 100% !important; } But it is not working.
I did it.
For someone who wants the solution, here is the code:
.myCustomSelect{ max-width: 100% !important; } You must have to override the 'max-width' css property.
!important because class selectors are of higher priority than element selectors.max-width property, correct?max-width: none as you can then do: width: 110% which in this case is not really necessary but cleaner in my opinion.Increasing the specificity of the selector allows for doing it without the !important on it:
ion-select.myCustomSelect{ width: 100%; max-width: 100%; } Which makes it a bit cleaner, since !important should be used as sparingly as possible, as noted in the Stack Overflow article here: Should I avoid using !important in CSS?
You don't need !important at all! Ionic has specified a min-width of 45% (or whatever as per your version of ionic). All you have to do is over-ride it with a max-width of 100%. At the same time, the select, being an inline element, will only expand to fit its contents. So it won't fill the whole width. So to make this happen, you simply add width: 100% to it. So your final CSS class may look something like this:
.full-width-select { width: 100%; max-width: 100%; } This is what helped me. After perusing multiple articles, I've found in this stack overflow article ~ Styling ion-select with popover interface, that if you open the developer tools and use the inspect tool, you can see the class that directly affects the select option.
So now that we know that the classes are .alert-wrapper.ion-overlay-wrapper.sc-ion-alert-md we can then add adjust this in our global.scss file
Like so
:root{ .alert-wrapper.ion-overlay-wrapper.sc-ion-alert-md{ max-width: 100% !important; width: 100% !important; } I'm currently working with Ionicv4 and above, however I'm assuming this should still be of assistance