S
S
Sandro_s2018-10-05 11:38:21
Yii
Sandro_s, 2018-10-05 11:38:21

How do I add a size to an image link?

Here is such a link in the form, but without params. picture size.

<?= Html::img("@web/images/products/{$hit->img}", ['alt' => $hit->name])?>

How to add couples to pictures. dimensions ('240x180') ?
Block code
<div class="recommended_items">
    <!--recommended_items-->
    <h2 class="title text-center">recommended items</h2>

    <div id="recommended-item-carousel" class="carousel slide" data-ride="carousel">
        <div class="carousel-inner">
<?php $count = count($hits); $i = 0; foreach($hits as $hit): ?>
<?php if($i % 3 == 0): ?>
    <div class="item <?php if($i == 0) echo 'active' ?>">
<?php endif; ?>
        <div class="col-sm-4">
            <div class="product-image-wrapper">
                <div class="single-products">
                    <div class="productinfo text-center">
                        


                    <?= Html::img("@web/images/products/{$hit->img}", ['alt' => $hit->name])?>

 
                        <h2>$<?= $hit->price?></h2>
                        <p><a href="<?= \yii\helpers\Url::to(['product/view', 'id' => $hit->id])?>"><?= $hit->name?></a></p>
                        <button type="button" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</button>
                    </div>
                </div>
            </div>
        </div>
<?php $i++; if($i % 3 == 0 || $i == $count): ?>
    </div>
<?php endif; ?>
<?php endforeach; ?>
        </div>
        <a class="left recommended-item-control" href="#recommended-item-carousel" data-slide="prev">
            <i class="fa fa-angle-left"></i>
        </a>
        <a class="right recommended-item-control" href="#recommended-item-carousel" data-slide="next">
            <i class="fa fa-angle-right"></i>
        </a>
    </div>
</div><!--/recommended_items-->

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2018-10-05
@Sandro_s

Good morning.

<?= Html::img("@web/images/products/{$hit->img}", ['alt' => $hit->name, 'width' => 280, 'height' => 180])?>

D
dtBlack, 2018-10-05
@dtBlack

Usually it is worth specifying what exactly you are asking about, a correctly asked question is already at least half the answer ... It would be worthwhile to indicate that this is yii2 ...
It's worth asking what ['alt' => $hit->name] is... It's useful to read the documentation... You
can solve the problem by adding a class to this array and setting the dimensions in CSS, or by writing the style directly.

<?= Html::img("@web/images/products/{$hit->img}", ['alt' => $hit->name,  'style' => ['width' => '100px', 'height' => '100px'], 'class' => 'my_img'])?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question