图片随外层容器<div>的大小而改变大小

本文介绍了一种使用 CSS 控制图片宽度以实现响应式布局的方法。通过设置 max-width 和利用 expression 函数,可以让图片在不同屏幕尺寸下保持合适的大小。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#divID img{
    max-width:480px;
    width:expression(document.body.clientWidth > 480? "480px": "auto"

}



<p-table [value]="salesOrderList" stripedRows class="w-full" dataKey="vehicleSeq" [expandedRowKeys]="expandedRows"> <ng-template #header> <tr> <th>工厂</th> <th class="fontLine" style="min-width: 100px">装货日期</th> <th class="fontLine" style="min-width: 100px">发货日期</th> <th class="fontLine" style="min-width: 100px">车牌号</th> <th class="fontLine" style="min-width: 100px">车次</th> <th class="fontLine" style="min-width: 100px">优先级</th> <th class="fontLine" style="min-width: 100px">拼车</th> <th class="fontLine" style="min-width: 100px">计划到库</th> <th class="fontLine" style="min-width: 100px">到库时间</th> <th class="fontLine" style="min-width: 100px">状态</th> </tr> </ng-template> <ng-template #body let-product let-expanded="expanded"> <tr> <td> <div class="flex gap-2 items-center"> <button (click)="!expanded ? onClickSalesOrderDetail(product) : null" pButton class="text-sm" pRipple [pRowToggler]="product" [text]="true" [rounded]="true" [plain]="true" [icon]="expanded ? 'pi pi-chevron-down' : 'pi pi-chevron-right'" style="padding-right: 6px;"></button> <span>{{ product.factoryName }}</span> </div> </td> <td>{{ product.loadDate }}</td> <td>{{ product.deliveryDate }}</td> <td>{{ product.vehicleNo }}</td> <td>{{ product.vehicleSeq }}</td> <td> <p-select class="w-full" [(ngModel)]="product.priority" [options]="priorityList" optionLabel="dicName" optionValue="dicCode" [appendTo]="'body'"> </p-select> </td> <td>{{ product.isCarpool ? '是' : '否' }}</td> <td>{{ product.planArrivalTime }}</td> <td>{{ product.actualArrivalTime }}</td> <td> <div class="py-1 rounded text-center" [ngClass]="{'status-done': (product.status | salesOrderStatus) === '已装车','status-warning': (product.status | salesOrderStatus) === '待通知','status-error': (product.status | salesOrderStatus) === '待排序'}"> {{ product.status | salesOrderStatus }}</div> </td> </tr> </ng-template> <ng-template #expandedrow let-product> <tr> <td colspan="100%" class="bg-white !pl-8 !pr-0"> <div class="pl-6" style="border-left: 1px #c30001 solid"> <p-table [value]="salesOrderDetail" class="wareList"> <ng-template #header> <tr> <th>发货仓库</th> <th class="fontLine">备货单</th> <th class="fontLine">合同</th> <th class="fontLine">到货日期</th> <th class="fontLine">商业公司</th> <th class="fontLine">装载顺序</th> <th class="fontLine">批次</th> <th class="fontLine">物料编号</th> <th class="fontLine">物料描述</th> <th class="fontLine">数量</th> </tr> </ng-template> <ng-template #body let-order> <tr> <td>{{ order.deliveryWarehouse }}</td> <td>{{ order.packingList }}</td> <td>{{ order.contractNo }}</td> <td>{{ order.arrivalDate }}</td> <td>{{ order.businessCompany }}</td> <td>{{ order.loadingOrder }}</td> <td>{{ order.batchNo }}</td> <td>{{ order.materialCode }}</td> <td>{{ order.materialDesc }}</td> <td>{{ order.quantity }}</td> </tr> </ng-template> </p-table> 我的html是这样的结构
最新发布
07-19
``` <div style="width: 110%;height: 220%;background-color: white;float: left;margin-top: 40px;margin-left: -660px;border-radius: 10px"> <div style="width: 5px;height: 25px;background-color: #1f78ff;margin-top: 22px;margin-left: 10px;border-radius: 10px;float: left"> </div> <div style="float: left;margin-top: 20px;font-size: 20px;font-weight: bold;width: 40%;"> 今日有效单量:{{ userinfo.today_order || '0' }}单 </div> <div style="float: right;font-size: 14px;color: gray;padding-top: 20px;padding-right: 20px">更新时间:{{ userinfo.nowtime }} <button @click="showdrawer" type="primary" style="color: rgb(64,158,255);background-color: white;border: none">数据表格 ></button> </div> <div style="clear: both"></div> <div style="float: left;margin-left: 8px;margin-top: 10px"> 日期A:<span style="color: rgb(64,158,255);font-weight: bold">{{ this.totalBa }}</span>单 日期B:<span style="color: rgb(64,158,255);font-weight: bold">{{ this.totalAa }}</span>单 升幅: <span style="font-weight: bold">{{ this.totalBa - this.totalAa }}</span>单</div> <div style="clear: both"></div> <div style="float: left;margin-left: 8px;padding-top: 20px"> 对比日期A: </div> <div style="clear: both"></div> <div style="float: left;margin-left: 106px;margin-top: -26px"> <el-date-picker value-format="yyyy-MM-dd" style="width: 140px;" v-model="timeA" type="date" @change="getOrderChart" placeholder="选择日期"> </el-date-picker> </div> <div style="clear: both"></div> <div style="float: left;margin-left: 260px;margin-top: -32px;position: relative"> 对比日期B: </div> <div style="clear: both"></div> <div style="float: left;margin-left: 360px;margin-top: -36px;position: relative"> <el-date-picker value-format="yyyy-MM-dd" style="width: 150px;" v-model="timeB" type="date" @change="getOrderChart" placeholder="选择日期"> </el-date-picker> </div> <div style="clear: both"></div> <div style="float: right;margin-top: -36px;margin-right: 440px;position: relative"> <el-select style="width: 120px;position: relative" v-model="current_time" placeholder="当前对比" @change="getOrderChart"> <el-option v-for="item in option_time" :label=item.label :value="item.value"> </el-option> </el-select> </div> <div style="clear: both"></div> </div>```窗口缩小后里面位置发生错乱怎么解决
03-15
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>3D旋转立体相册源码(送给那个她)</title> <link rel="stylesheet" href="index.css"> <link rel="shortcut icon" href="https://www.xfabe.com/favicon.ico" type="image/x-icon" /> </head> <body> <!-- 自动循环播放音乐(谷歌浏览器内核除外) --> <audio src="https://links.xfyun.club/xfyun/fansisi.mp3" autoplay="autoplay" loop="loop" controls="controls"></audio> <!-- 3d旋转的盒子 --> <div class="xf_3d_box"> <!-- 内部 --> <ul class="xf_rotate_1"> <!-- 这里修改照片路径 --> <li><img src="img/xw1.jpg" alt="女友照片"></li> <li><img src="img/xw2.jpg" alt="女友照片"></li> <li><img src="img/xw3.jpg" alt="女友照片"></li> <li><img src="img/xw4.jpg" alt="女友照片"></li> <li><img src="img/xw5.jpg" alt="女友照片"></li> <li><img src="img/xw6.jpg" alt="女友照片"></li> </ul> <!-- 外部 --> <ul class="xf_rotate_2"> <li><img src="img/xw1.jpg" alt="女友照片"></li> <li><img src="img/xw2.jpg" alt="女友照片"></li> <!-- 第三个和第四个隐藏了 --> <li><img src="img/xw3.jpg" alt="女友照片"></li> <li><img src="img/xw4.jpg" alt="女友照片"></li> <li><img src="img/xw5.jpg" alt="女友照片"></li> <li><img src="img/xw6.jpg" alt="女友照片"></li> </ul> </div> <script> let div = document.querySelector('.xf_3d_box') let ul = document.querySelector('.xf_rotate_2') let xfhusband = false div.addEventListener('click', function () { xfhusband = !xfhusband if (xfhusband) { ul.style.opacity = 1 } else { ul.style.opacity = 0 } console.log((xfhusband)); }) </script> </body> </html> 这个代码有两层图片对吧 里面方块是六张 外面环绕的是四张 请你让着两可以实现更多的互动效果 不要修改里面的照片
06-05
``` <div style="width: 110%;height: 220%;background-color: white;float: left;margin-top: 40px;margin-left: -660px;border-radius: 10px"> <div style="width: 5px;height: 25px;background-color: #1f78ff;margin-top: 22px;margin-left: 10px;border-radius: 10px;float: left"> </div> <div style="float: left;margin-top: 20px;font-size: 20px;font-weight: bold;width: 40%;"> 今日有效单量:{{ userinfo.today_order || '0' }}单 </div> <div style=" float: right;font-size: 14px;color: gray;padding-top: 20px;padding-right: 20px">更新时间:{{ userinfo.nowtime }} <button @click="showdrawer" type="primary" style="color: rgb(64,158,255);background-color: white;border: none">数据表格 ></button> </div> <div style="clear: both"></div> <div style="float: left;padding-top: 10px;padding-left: 10px;"> 日期A:<span style="color: rgb(64,158,255);font-weight: bold">{{ this.totalBa }}</span>单 日期B:<span style="color: rgb(64,158,255);font-weight: bold">{{ this.totalAa }}</span>单 升幅: <span style="font-weight: bold">{{ this.totalBa - this.totalAa }}</span>单 </div> <div style="clear: both"></div> <div style="float: left;padding-left: 8px;padding-top: 20px"> 对比日期A: </div> <div style="clear: both"></div> <div style="float: left;margin-left: 106px;margin-top: -26px"> <el-date-picker value-format="yyyy-MM-dd" style="width: 140px;" v-model="timeA" type="date" @change="getOrderChart" placeholder="选择日期"> </el-date-picker> </div> <div style="clear: both"></div> <div style="float: left;padding-left: 260px;margin-top: -32px;"> 对比日期B: </div> <div style="clear: both"></div> <div style="float: left;padding-left: 360px;margin-top: -36px;"> <el-date-picker value-format="yyyy-MM-dd" style="width: 150px;" v-model="timeB" type="date" @change="getOrderChart" placeholder="选择日期"> </el-date-picker> </div> <div style="float: right;margin-top: -36px;margin-right: 350px;"> <el-select style="width: 50%;" v-model="current_time" placeholder="当前对比" @change="getOrderChart"> <el-option v-for="item in option_time" :label=item.label :value="item.value "> </el-option> </el-select> </div> <div style="clear: both"></div> </div>```窗口缩小里面的今日有效单量:0单日期A:0单 日期B:0单 升幅: 0单 2025-03-16 对比日期B: 2025-03-17 当前对比 位置发生错乱看不到了,要求是不要新代码在我的代码基础上修改,达到窗口缩小后依然全可以看到
03-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值