How to set width of DetailView Widget?

Hi,

How do I set the width of the DetailView widget?

I don’t want to use css as each widget will be a different width.

I have tried:




    <?= DetailView::widget([

        'model' => $model,

        'attributes' => [

            'product',

            'price',

            'unit',

        ],

    ], $options = ['style' => 'width:150px']) ?>



What if you enclose your detailView widget in a div?

Something like:


<div class="row">

 <div class="col-md-5">

  <?= DetailView::widget([

        'model' => $model,

        'attributes' => [

            'product',

            'price',

            'unit',

        ],

    ], $options = ['style' => 'width:150px']) ?>

  </div>

</div>



Thanks, that will work, but you are using container divs to set the width.

If there is no other way to set the width, I will resort to using divs.

The idea is that you reuse existing css classes and you remain consistant into bootstrap.

have you tried




    <?= DetailView::widget([

        'model' => $model,

        'attributes' => [

            'product',

            'price',

            'unit',

        ],

    ], $options = ['class' => 'col-md-5']) ?>



?

Thanks Gregoire,

Nope sorry, your last try/example did not set the width of the DetailView widget.

I get the idea behind using css, but if I am going to have 20 different view pages with different view sizes, I really don’t want to set 20 different css classes just to set the width. The width of each will also never change so specifying it directly in the widget will do just fine.

But as I have said, if there is no way of doing this, then I will use divs and set the style width directly on the div to fix it.