Internet Explorer and column collapse

本文介绍了解决Internet Explorer中常见布局问题的方法,通过使用负边距、相对定位及调整元素高度来确保跨浏览器的一致性。
 

So, you have built a beautiful CSS layout. It looks great. You feel powerful, knowledgeable and wise. Then you start adding real content to the layout - images, lists, links etc.

Suddenly you layout does not look so great in Internet Explorer. For some reason columns are now wider. In some cases the column width increases so much that the entire layout breaks and the column drops below the rest of the content. Your confidence is shattered. You curse CSS and think about table-based layouts. At least they “work” in IE.

Of course, there is a solution.

I was discussing this problem recently with Cameron Adams who suggested that negative margins could be the answer. He was, as always, right... with some simple additions.

Three steps to freedom from IE column collapse

In sample 1 (below), all browsers except IE will render the column to the correct width and allow wider elements to poke out the right side of the container.

However, IE honours the width of the content rather than the container, so the container is much wider.

Step 1

Add negative margins to the right edge of all elements being affected. In this sample, the affected elements include an unordered list, an image, a <div> and a table.

#column img { margin-right: -500px; }
#column ul { margin-right: -500px; }
#column div { margin-right: -500px; }
#column table { margin-right: -500px; }

We have tricked IE into thinking that the offending elements are very narrow. IE will now render the container to the correct width.

The width is specified to "500px". This unit can change to suit your needs. If you have one image poking 100px out the right edge, then you will only need a negative margin of 100px. A large amount is a safer option if you cannot be sure of the column width or possible content inside.

Before we move on, you can collapse all of the rules above into multiple selectors with the same declaration block:

#column img, #column ul, #column div, #column table { margin-right: -500px; }

You've probably noticed that the elements have been cut off in IE. So, let's deal with this issue.

Step 2

Apply "position: relative" to the relevant elements.

#column img, #column ul, #column div, #column table
{
margin-right: -500px;
position: relative;
}

Most of the elements are now rendering correctly. However, The the url strings are still cut off to some degree, so we need to fix them.

Step 3

As suggested by Mauricio Samy Silva, we need to give the <ul> element some dimension to overcome IE's hasLayout issues. This can be achieved using:

#column ul
{
margin-right: -500px;
position: relative;
height: 1%;
}

The url strings are now visible!

A simpler method

Some people may prefer the elements to be cut off rather than poking out. In this case, you can ignore the steps above and simply apply "overflow: hidden" to the entire column. The overflow hidden option is much simpler to apply, as it does not involve styling any of the affected elements.

#column { overflow: hidden; }

<template> <div class="navBarBox" :style="{ width: width }"> <div class="title">统一预约管理平台</div> <el-menu :default-active="activeMenuPath" :collapse="!isCollapse" :background-color="variables['menu-background']" :text-color="variables['menu-text']" :active-text-color="variables['menu-active-text']" :unique-opened="false" :collapse-transition="false" popper-class="sub-menu-popper" router > <template v-for="item in menuList" :key="addSlash(item.path)"> <!-- 分组菜单 --> <el-sub-menu v-if="item.meta?.isGrouping" :index="addSlash(item.path)" class="sub-menu"> <template #title> <!-- 判断是否使用 svg-icon 组件 --> <template v-if="item.meta?.icon && isSvgIcon(item.meta.icon)"> <svg-icon class="meta-svg" :icon-class="item.meta.icon.replace('icon-', '')" size="18px" /> </template> <el-icon v-else-if="item.meta?.icon"> <component :is="item.meta.icon" /> </el-icon> <span v-if="isCollapse">{{ item.meta!.title }}</span> </template> <template v-for="child in item.children" :key="child.path"> <el-menu-item :index="addSlash(item.path) + addSlash(child.path)" v-if="!child.meta?.hidden"> <!-- 判断是否使用 svg-icon 组件 --> <template v-if="child.meta?.icon && isSvgIcon(child.meta.icon)"> <svg-icon class="meta-svg" :icon-class="child.meta.icon.replace('icon-', '')" size="18px" /> </template> <el-icon v-else-if="child.meta?.icon"> <component :is="child.meta.icon" /> </el-icon> <span>{{ child.meta!.title }}</span> </el-menu-item> </template> </el-sub-menu> <el-menu-item v-else :index="addSlash(item.path)" v-if="!item.meta?.hidden"> <!-- 判断是否使用 svg-icon 组件 --> <template v-if="item.meta?.icon && isSvgIcon(item.meta.icon)"> <svg-icon class="meta-svg" :icon-class="item.meta.icon.replace('icon-', '')" size="18px" /> </template> <el-icon v-else-if="item.meta?.icon"> <component :is="item.meta.icon" /> </el-icon> <span v-if="isCollapse">{{ item.meta!.title }}</span> </el-menu-item> </template> </el-menu> </div> </template> <script setup lang="ts"> import variables from '@/styles/variables.module.scss'; import { usePermissionStore } from '@/store'; import SvgIcon from '@/components/SvgIcon/index.vue'; const props = defineProps({ width: { type: String, default: variables['sidebar-width'] }, isCollapse: { type: Boolean, default: false } }); const currentRoute = useRoute(); const permissionStore = usePermissionStore(); const menuList = permissionStore.routes.filter(item => !item.meta?.hidden).flatMap(item => item.children || []); // 计算激活的菜单路径 const activeMenuPath = computed(() => { const pathSegments = currentRoute.path.split('/').filter(Boolean); if (pathSegments.length > 2) { return '/' + pathSegments.slice(0, pathSegments.length - 1).join('/'); } return currentRoute.path; }); const addSlash = (str: string) => { if (str[0] !== '/') { return '/' + str; } return str; }; // 判断是否为 svg 图标(以 'icon-' 开头的图标) const isSvgIcon = (icon: string) => { return typeof icon === 'string' && icon.startsWith('icon-'); }; </script> <style lang="scss" scoped> .title { height: 60px; line-height: 60px; width: 100%; text-align: center; background-color: var(--menu-background); color: var(--menu-text); user-select: none; } .navBarBox { height: 100vh; display: flex; justify-content: flex-start; flex-direction: column; transition: 0.5s; border-right: 1px solid var(--border-color); } .el-menu { height: 100vh; width: 100%; border-right: none; user-select: none; --el-menu-hover-bg-color: var(--menu-hover) !important; overflow: auto; -ms-overflow-style: none; /* Internet Explorer 10+ */ scrollbar-width: none; /* Firefox */ .el-menu-item:hover { background-color: $menu-hover; } .el-menu-item, :deep(.el-sub-menu__title) { border-radius: 20px; } } .el-menu::-webkit-scrollbar { display: none; /* Chrome, Safari, Opera */ } .meta-svg { width: 24px !important; margin-right: 5px; } </style> 我这个该如何修改
10-03
在数字化环境中,线上票务获取已成为参与各类活动的主要途径。随着公众对热门演出需求的增长,票源往往在开放销售后迅速告罄,导致普通消费者难以顺利购得所需票券。为应对这一挑战,部分技术开发者借助编程手段构建了自动化购票辅助程序,旨在提升用户成功获取门票的概率。本文将以一个针对特定票务平台设计的自动化工具为例,系统阐述其设计理念、技术组成及具体实施流程。 秀动网作为国内知名的演出及体育赛事票务销售平台,因活动热度较高,常出现访问拥堵、瞬时抢购压力大等现象,使得常规购票过程面临困难。因此,开发一款能够协助用户更有效完成票务申购的辅助工具具有实际意义。 该工具主要具备以下几项关键功能:持续监控目标平台的票务信息更新;在票务释放时自动执行选座、添加至购物车及提交订单等系列操作;集成一定的异常处理机制,以应对网络延迟或服务器响应异常等情况。 在技术实现层面,选用Python作为开发语言,主要基于其语法简洁、标准库与第三方资源丰富,适合快速构建功能原型。同时,Python在网络通信与浏览器自动化方面拥有如requests、selenium等成熟支持库,为程序实现网页交互与数据抓取提供了便利。 开发过程主要包括以下环节:首先解析目标网站的页面结构,明确可通过程序操控的网页元素路径;随后编写监控模块,实时检测新票务信息的上线并及时触发后续操作;接着模拟用户操作流程,包括自动填写个人信息、选择座位偏好、完成购物车添加等步骤,并通过行为模拟降低被平台反爬虫机制识别的可能;最终实现订单自动提交,并在成功购票后向用户发送通知。 此外,该工具提供了可配置的操作界面,允许用户根据个人需求设定抢票时间、目标活动类型及座位选择等参数,从而在提升使用体验的同时,减少对票务平台服务器资源的非必要占用。 需指出的是,尽管此类工具能提高购票效率,但其使用可能涉及违反平台服务协议或相关法规的风险。各票务销售方通常对自动化抢票行为设有明确约束,因此开发与使用者均应遵守相应规定,确保技术应用的合法性。 综上所述,该基于Python的票务辅助工具是针对特定场景设计的自动化解决方案,通过技术手段改善用户购票体验,但同时也强调必须在法律与平台规则框架内合理使用此类技术。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值