Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set the Ionic 2 ion-col to a set pixel size rather than a percentage?

I just want to set a column to a set px size, and then have the other column take up the rest of the space.

I have the following where I want the first col to be say 10px

    <ion-grid>
        <ion-row>
               <ion-col width-X='10px' style='width:10px;background-color:red'></ion-col>
                <ion-col>
                    <div><b>item 1</b></div>
                    <div>item 2</div>
                    <div>item 3</div>
             </ion-col>
         </ion-row>
    </ion-grid>

But the first column is always 50%.

Is there a way to use a fixed px?

Thanks in advance

like image 985
peterc Avatar asked Feb 15 '17 14:02

peterc


People also ask

How do you adjust the width of an ion Col?

By default, the grid will take up 100% width. To set a specific width based on the screen size, add the fixed attribute. The width of the grid for each breakpoint is defined in the --ion-grid-width-{breakpoint} CSS variables.

What is ion Col?

ion-col: Column Component Padding, Size and Other Properties. Skip to main content.

How do you use the Ionic grid system?

Working with the Ionic Grid System is straightforward. There are two main classes – row for working with rows and col for columns. You can choose as many columns or rows you want. All of them will adjust its size to accommodate the available space, although you can change this behavior to suit your needs.


2 Answers

You could use flex-basis to achieve what you're looking for. In your Sass...

ion-row {

    ion-col {

        &:first-of-type {

            flex: 0 0 10px;

        }
    }
}

Flex's shorthand property allows you set it to and the you'd like the element to take up.

See here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/

like image 147
Alsh Avatar answered Oct 05 '22 06:10

Alsh


You can specify a min width to the column as mentioned in ionic doc. In mycase, the first column will stay fixed and the column around will resize.

<ion-grid>
    <ion-col class="accordion" col-2></ion-col>
    <ion-col></ion-col>
</ion-grid>

.accordion{
   min-width: 224px;
}
like image 31
Samiullah Khan Avatar answered Oct 05 '22 04:10

Samiullah Khan