dongzhi7641 2018-09-18 17:08
浏览 29

too long

i have this HTML line here (its an echo from php)

echo "
<div class='rowItem'>
    <div class='singleItem'>
        <div class='itemImage' >
            <img src= $arr3[$i] >
        </div>
        <div class='itemName'>$arr1[$i]</div>
        <div class='itemPrice'><br> Php$arr2[$i]
            <div class='orderButtonDiv'>
                <a href='menu_burger.php'>ORDER</a>
            </div>
        </div>
    </div>
</div>";

Here is the CSS I'm using

.itemImage{
  height:100%;
  width :100%;
}

.itemImage img{
  width: 60%;
  left: 0px;
  right: 0px;
}

.itemName{
  color: red;
  text-decoration: none;
  font-family: "Roboto",sans-serif;
  font-size: 150%;
  font-weight: bold;
  margin-left: 40%;
  margin-top: 4%;
}

.itemPrice{
  color: black;
  text-decoration: none;
  font-family: "Roboto",sans-serif;
  font-size: 110%;
  margin-left: 41%;
  position: absolute;
  bottom: 25%;
  z-index -1;
}

.singleItem{
  width: 48%;
  background-color: #e0dede;
  border:1px solid red;
  height: 150px;
  position: relative;
  z-index: -1;
}

here picture of the result

enter image description here

as you can see i am not able to resize the image here is the css code. Aside from that it is also overlapping some text

here is the image without the picture without the image

enter image description here

How can i resize the image properly that it will follow the the height of single item and at the same time equate its width to its height

Thank you very much

  • 写回答

2条回答 默认 最新

  • 普通网友 2018-09-18 17:24
    关注

    In my experience, a div with

      background:url([imagepath]);background-size:cover;
    

    is the best solution, the css property:

    object-fit: cover;
    

    Can help if you want to preseve the img aproach, but is less backwards compatible. As for the overlaping text, read the documentation for z-index css property.

    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测