iis服务器助手广告广告
返回顶部
首页 > 资讯 > 前端开发 > html >IE下Css没有圆角的解决方法
  • 630
分享到

IE下Css没有圆角的解决方法

2024-04-02 19:04:59 630人浏览 八月长安
摘要

这篇文章主要介绍“IE下CSS没有圆角的解决方法”,在日常操作中,相信很多人在IE下Css没有圆角的解决方法问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”IE下Css没有圆角

这篇文章主要介绍“IE下CSS没有圆角的解决方法”,在日常操作中,相信很多人在IE下Css没有圆角的解决方法问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”IE下Css没有圆角的解决方法”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

在网頁制作时,圆角的样式在很多时候都要到,大多数都是用图片来搞,其实图片不图片无所谓的,但也有的朋友比较喜欢用CSS来写,CSS写的话在火狐、谷歌等浏览器都是没有问题的。但是在IE下就会出现问题,圆角就没有了。这时候就要用到一个文件,当时那个文件是哪里下的已经记不清了,但用着还是挺不错的。由于不知道怎么上传文件,就只能把源码弄出来了。

test.html

代码如下:


<html>
<head><title>test</title>
<style type="text/css">
.test {
width:100px;
height:100px;
background-color: blue;
margin-bottom:10px;
border-radius: 10px;
behavior: url(ie-css3.htc);
}
</style>
</head>
<body>
<div class="test">
test
</div>
</body>
</html>


ie-css3.htc

代码如下:


--Do not remove this if you are using--
Original Author: Remiz Rahnas
Original Author URL: Http://www.htmlremix.com
Published date: 2008/09/24
Changes by Nick Fetchak:
- IE8 standards mode compatibility
- VML elements now positioned behind original box rather than inside of it - should be less prone to breakage
- Added partial support for 'box-shadow' style
- Checks for VML support before doing anything
- Updates VML element size and position via timer and also via window resize event
- lots of other small things
Published date : 2010/03/14
http://fetchak.com/ie-css3
Thanks to TheBrightLines.com (http://www.thebrightlines.com/2009/12/03/using-ies-filter-in-a-cross-browser-way) for enlightening me about the DropShadow filter
<public:attach event="ondocumentready" onevent="ondocumentready('v08vnSVo78t4JfjH')" />
<script type="text/javascript">
timer_length = 200; // Milliseconds
border_opacity = false; // Use opacity on borders of rounded-corner elements? Note: This causes antialiasing issues

// supportsVml() borrowed from http://stackoverflow.com/questions/654112/how-do-you-detect-support-for-vml-or-svg-in-a-browser
function supportsVml() {
if (typeof supportsVml.supported == "undefined") {
var a = document.body.appendChild(document.createElement('div'));
a.innerHTML = '<v:shape id="vml_flag1" adj="1" />';
var b = a.firstChild;
b.style.behavior = "url(#default#VML)";
supportsVml.supported = b ? typeof b.adj == "object": true;
a.parentnode.removeChild(a);
}
return supportsVml.supported
}

// findPos() borrowed from http://www.quirksmode.org/js/findpos.html
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
}
return({
'x': curleft,
'y': curtop
});
}
function createBoxShadow(element, vml_parent) {
var style = element.currentStyle['iecss3-box-shadow'] || element.currentStyle['-moz-box-shadow'] || element.currentStyle['-WEBkit-box-shadow'] || element.currentStyle['box-shadow'] || '';
var match = style.match(/^(\d+)px (\d+)px (\d+)px/);
if (!match) { return(false); }

var shadow = document.createElement('v:roundrect');
shadow.userAttrs = {
'x': parseInt(RegExp.$1 || 0),
'y': parseInt(RegExp.$2 || 0),
'radius': parseInt(RegExp.$3 || 0) / 2
};
shadow.position_offset = {
'y': (0 - vml_parent.pos_ieCSS3.y - shadow.userAttrs.radius + shadow.userAttrs.y),
'x': (0 - vml_parent.pos_ieCSS3.x - shadow.userAttrs.radius + shadow.userAttrs.x)
};
shadow.size_offset = {
'width': 0,
'height': 0
};
shadow.arcsize = element.arcSize +'px';
shadow.style.display = 'block';
shadow.style.position = 'absolute';
shadow.style.top = (element.pos_ieCSS3.y + shadow.position_offset.y) +'px';
shadow.style.left = (element.pos_ieCSS3.x + shadow.position_offset.x) +'px';
shadow.style.width = element.offsetWidth +'px';
shadow.style.height = element.offsetHeight +'px';
shadow.style.antialias = true;
shadow.className = 'vml_box_shadow';
shadow.style.zIndex = element.zIndex - 1;
shadow.style.filter = 'progid:DXImageTransfORM.Microsoft.Blur(pixelRadius='+ shadow.userAttrs.radius +',makeShadow=true,shadowOpacity='+ element.opacity +')';
element.parentNode.appendChild(shadow);
//element.parentNode.insertBefore(shadow, element.element);
// For window resizing
element.vml.push(shadow);
return(true);
}
function createBorderRect(element, vml_parent) {
if (isNaN(element.borderRadius)) { return(false); }
element.style.background = 'transparent';
element.style.borderColor = 'transparent';
var rect = document.createElement('v:roundrect');
rect.position_offset = {
'y': (0.5 * element.strokeWeight) - vml_parent.pos_ieCSS3.y,
'x': (0.5 * element.strokeWeight) - vml_parent.pos_ieCSS3.x
};
rect.size_offset = {
'width': 0 - element.strokeWeight,
'height': 0 - element.strokeWeight
};
rect.arcsize = element.arcSize +'px';
rect.strokeColor = element.strokeColor;
rect.strokeWeight = element.strokeWeight +'px';
rect.stroked = element.stroked;
rect.className = 'vml_border_radius';
rect.style.display = 'block';
rect.style.position = 'absolute';
rect.style.top = (element.pos_ieCSS3.y + rect.position_offset.y) +'px';
rect.style.left = (element.pos_ieCSS3.x + rect.position_offset.x) +'px';
rect.style.width = (element.offsetWidth + rect.size_offset.width) +'px';
rect.style.height = (element.offsetHeight + rect.size_offset.height) +'px';
rect.style.antialias = true;
rect.style.zIndex = element.zIndex - 1;
if (border_opacity && (element.opacity < 1)) {
rect.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity='+ parseFloat(element.opacity * 100) +')';
}
var fill = document.createElement('v:fill');
fill.color = element.fillColor;
fill.src = element.fillSrc;
fill.className = 'vml_border_radius_fill';
fill.type = 'tile';
fill.opacity = element.opacity;
// Hack: IE6 doesn't support transparent borders, use padding to offset original element
isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
if (isIE6 && (element.strokeWeight > 0)) {
element.style.borderStyle = 'none';
element.style.paddingTop = parseInt(element.currentStyle.paddingTop || 0) + element.strokeWeight;
element.style.paddingBottom = parseInt(element.currentStyle.paddingBottom || 0) + element.strokeWeight;
}
rect.appendChild(fill);
element.parentNode.appendChild(rect);
//element.parentNode.insertBefore(rect, element.element);
// For window resizing
element.vml.push(rect);
return(true);
}
function createTextShadow(element, vml_parent) {
if (!element.textShadow) { return(false); }
var match = element.textShadow.match(/^(\d+)px (\d+)px (\d+)px (#?\w+)/);
if (!match) { return(false); }

//var shadow = document.createElement('span');
var shadow = element.cloneNode(true);
var radius = parseInt(RegExp.$3 || 0);
shadow.userAttrs = {
'x': parseInt(RegExp.$1 || 0) - (radius),
'y': parseInt(RegExp.$2 || 0) - (radius),
'radius': radius / 2,
'color': (RegExp.$4 || '#000')
};
shadow.position_offset = {
'y': (0 - vml_parent.pos_ieCSS3.y + shadow.userAttrs.y),
'x': (0 - vml_parent.pos_ieCSS3.x + shadow.userAttrs.x)
};
shadow.size_offset = {
'width': 0,
'height': 0
};
shadow.style.color = shadow.userAttrs.color;
shadow.style.position = 'absolute';
shadow.style.top = (element.pos_ieCSS3.y + shadow.position_offset.y) +'px';
shadow.style.left = (element.pos_ieCSS3.x + shadow.position_offset.x) +'px';
shadow.style.antialias = true;
shadow.style.behavior = null;
shadow.className = 'ieCSS3_text_shadow';
shadow.innerHTML = element.innerHTML;
// For some reason it only looks right with opacity at 75%
shadow.style.filter = '\
progid:DXImageTransform.Microsoft.Alpha(Opacity=75)\
progid:DXImageTransform.Microsoft.Blur(pixelRadius='+ shadow.userAttrs.radius +',makeShadow=false,shadowOpacity=100)\
';
var clone = element.cloneNode(true);
clone.position_offset = {
'y': (0 - vml_parent.pos_ieCSS3.y),
'x': (0 - vml_parent.pos_ieCSS3.x)
};
clone.size_offset = {
'width': 0,
'height': 0
};
clone.style.behavior = null;
clone.style.position = 'absolute';
clone.style.top = (element.pos_ieCSS3.y + clone.position_offset.y) +'px';
clone.style.left = (element.pos_ieCSS3.x + clone.position_offset.x) +'px';
clone.className = 'ieCSS3_text_shadow';

element.parentNode.appendChild(shadow);
element.parentNode.appendChild(clone);
element.style.visibility = 'hidden';
// For window resizing
element.vml.push(clone);
element.vml.push(shadow);
return(true);
}
function ondocumentready(classID) {
if (!supportsVml()) { return(false); }
if (this.className.match(classID)) { return(false); }
this.className = this.className.concat(' ', classID);
// Add a namespace for VML (IE8 requires it)
if (!document.namespaces.v) { document.namespaces.add("v", "urn:schemas-microsoft-com:vml"); }
// Check to see if we've run once before on this page
if (typeof(window.ieCSS3) == 'undefined') {
// Create global ieCSS3 object
window.ieCSS3 = {
'vmlified_elements': new Array(),
'update_timer': setInterval(updatePositionAndSize, timer_length)
};
if (typeof(window.onresize) == 'function') { window.ieCSS3.previous_onresize = window.onresize; }
// Attach window resize event
window.onresize = updatePositionAndSize;
}

// These attrs are for the script and have no meaning to the browser:
this.borderRadius = parseInt(this.currentStyle['iecss3-border-radius'] ||
this.currentStyle['-moz-border-radius'] ||
this.currentStyle['-webkit-border-radius'] ||
this.currentStyle['border-radius'] ||
this.currentStyle['-khtml-border-radius']);
this.arcSize = Math.min(this.borderRadius / Math.min(this.offsetWidth, this.offsetHeight), 1);
this.fillColor = this.currentStyle.backgroundColor;
this.fillSrc = this.currentStyle.backgroundImage.replace(/^url\("(.+)"\)$/, '$1');
this.strokeColor = this.currentStyle.borderColor;
this.strokeWeight = parseInt(this.currentStyle.borderWidth);
this.stroked = 'true';
if (isNaN(this.strokeWeight) || (this.strokeWeight == 0)) {
this.strokeWeight = 0;
this.strokeColor = fillColor;
this.stroked = 'false';
}
this.opacity = parseFloat(this.currentStyle.opacity || 1);
this.textShadow = this.currentStyle['text-shadow'];
this.element.vml = new Array();
this.zIndex = parseInt(this.currentStyle.zIndex);
if (isNaN(this.zIndex)) { this.zIndex = 0; }
// Find which element provides position:relative for the target element (default to BODY)
vml_parent = this;
var limit = 100, i = 0;
do {
vml_parent = vml_parent.parentElement;
i++;
if (i >= limit) { return(false); }
} while ((typeof(vml_parent) != 'undefined') && (vml_parent.currentStyle.position != 'relative') && (vml_parent.tagName != 'BODY'));
vml_parent.pos_ieCSS3 = findPos(vml_parent);
this.pos_ieCSS3 = findPos(this);
var rv1 = createBoxShadow(this, vml_parent);
var rv2 = createBorderRect(this, vml_parent);
var rv3 = createTextShadow(this, vml_parent);
if (rv1 || rv2 || rv3) { window.ieCSS3.vmlified_elements.push(this.element); }
if (typeof(vml_parent.document.ieCSS3_stylesheet) == 'undefined') {
vml_parent.document.ieCSS3_stylesheet = vml_parent.document.createStyleSheet();
vml_parent.document.ieCSS3_stylesheet.addRule("v\\:roundrect", "behavior: url(#default#VML)");
vml_parent.document.ieCSS3_stylesheet.addRule("v\\:fill", "behavior: url(#default#VML)");
// Compatibility with IE7.js
vml_parent.document.ieCSS3_stylesheet.ie7 = true;
}
}
function updatePositionAndSize() {
if (typeof(window.ieCSS3.vmlified_elements) != 'object') { return(false); }
for (var i in window.ieCSS3.vmlified_elements) {
var el = window.ieCSS3.vmlified_elements[i];
if (typeof(el.vml) != 'object') { continue; }
for (var z in el.vml) {
//var parent_pos = findPos(el.vml[z].parentNode);
var new_pos = findPos(el);
new_pos.x = (new_pos.x + el.vml[z].position_offset.x) + 'px';
new_pos.y = (new_pos.y + el.vml[z].position_offset.y) + 'px';
if (el.vml[z].style.left != new_pos.x) { el.vml[z].style.left = new_pos.x; }
if (el.vml[z].style.top != new_pos.y) { el.vml[z].style.top = new_pos.y; }
var new_size = {
'width': parseInt(el.offsetWidth + el.vml[z].size_offset.width),
'height': parseInt(el.offsetHeight + el.vml[z].size_offset.height)
}
if (el.vml[z].offsetWidth != new_size.width) { el.vml[z].style.width = new_size.width +'px'; }
if (el.vml[z].offsetHeight != new_size.height) { el.vml[z].style.height = new_size.height +'px'; }
}
}
if (event && (event.type == 'resize') && typeof(window.ieCSS3.previous_onresize) == 'function') { window.ieCSS3.previous_onresize(); }
}
</script>

到此,关于“IE下Css没有圆角的解决方法”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注编程网网站,小编会继续努力为大家带来更多实用的文章!

--结束END--

本文标题: IE下Css没有圆角的解决方法

本文链接: https://www.lsjlt.com/news/77281.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • IE下Css没有圆角的解决方法
    这篇文章主要介绍“IE下Css没有圆角的解决方法”,在日常操作中,相信很多人在IE下Css没有圆角的解决方法问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”IE下Css没有圆角...
    99+
    2022-10-19
  • ie下没有背景色bug的解决方法是怎样的
    ie下没有背景色bug的解决方法是怎样的,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。  鼠标经过下...
    99+
    2022-10-19
  • 纯CSS实现圆角三角形的方法有哪些
    本篇内容主要讲解“纯CSS实现圆角三角形的方法有哪些”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“纯CSS实现圆角三角形的方法有哪些”吧!法一. 全兼容的 SV...
    99+
    2022-10-19
  • 右下角小喇叭不见了的解决办法(右下角没有小喇叭的处理方法)
    电脑有声音,但右下角没有小喇叭图标的解决办法: 第一步:点击“开始”菜单——>选择“设置”——>打开&ldquo...
    99+
    2023-06-04
    右下角小喇叭不见了 右下角没有小喇叭 小喇叭 处理 解决办法 方法
  • 电脑误删ie没有找到iertutil.dll的解决方法
    开机没有找到iertutil.dll 问题重现启动电脑就出现问题,提示“没有找到iertutil.dll,因此这个应用程序未能启动,重新安装应用程序可能修复此问题”,看不到电脑桌面。 开机没有找到...
    99+
    2023-06-04
    电脑误删ie 没有找到iertutil.dll 解决 电脑 iertutil.dll 方法
  • CSS+DIV实现圆角表格的方法有哪些
    这篇文章主要介绍“CSS+DIV实现圆角表格的方法有哪些”,在日常操作中,相信很多人在CSS+DIV实现圆角表格的方法有哪些问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”CS...
    99+
    2022-10-19
  • 解决ie下margin不居中的方法有哪些
    本篇内容主要讲解“解决ie下margin不居中的方法有哪些”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“解决ie下margin不居中的方法有哪些”吧!正常情况下...
    99+
    2022-10-19
  • hbuilderx写css代码没有提示的解决方法
    小编给大家分享一下hbuilderx写css代码没有提示的解决方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!解决方法:首先找到没有提示的项目,鼠标右键选中“项...
    99+
    2023-06-14
  • web项目WEB-INF下没有web.xml的解决方法
    目录创建项目的同时,就自动生成web.xml手动创建web.xml用IdeaeclipseWEB-INF是Java的WEB应用的安全目录。所谓安全就是客户端无法访问,只有服务端可以访...
    99+
    2022-12-29
    WEB-INF下没有web.xml
  • css导入成功但没有效果的解决方法
    这篇文章给大家分享的是有关css导入成功但没有效果的解决方法的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。css导入成功但没有效果的解决办法:1、打开网页调试工具,根据显示错误进行修改;2、查看link标签的“r...
    99+
    2023-06-14
  • php7没有phpize的解决方法
    本文操作环境:ubuntu 16.04系统、PHP7.0版、DELL G3电脑 php7 没有phpize怎么办? ubuntu服务器下php7没有phpize文件解决方案 第一种:...
    99+
    2022-11-12
  • linux没有ifconfig的解决方法
    这篇文章主要介绍了linux没有ifconfig的解决方法,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。解决方法:1、执行“yum search ifconfig”命令搜索i...
    99+
    2023-06-29
  • linux 没有php.ini的解决方法
    这篇文章主要介绍linux 没有php.ini的解决方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!linux没有php.ini的解决办法:1、进入php源码包目录;2、复制php.ini-development或...
    99+
    2023-06-21
  • ie中css背景图片不显示的解决方法
    这篇文章给大家分享的是有关ie中css背景图片不显示的解决方法的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。css的选择器有哪些css的选择器可以分为三大类,即id选择器、class选择器、标签选择器。它们之间可...
    99+
    2023-06-14
  • nginx没有解析php的解决方法
    这篇文章主要讲解了“nginx没有解析php的解决方法”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“nginx没有解析php的解决方法”吧!nginx没有解析php的解决办法:首先安装php...
    99+
    2023-06-20
  • php_eol没有换行的解决方法
    这篇文章给大家分享的是有关php_eol没有换行的解决方法的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。php_eol没有换行的解决办法:首先打开相应的PHP代码文件;然后在“PHP_EOL”前面添加“echo ...
    99+
    2023-06-14
  • php7 没有phpize的解决方法
    本文操作环境:ubuntu 16.04系统、PHP7.0版、DELL G3电脑 php7 没有phpize怎么办? ubuntu服务器下php7没有phpize文件解决方案 第一种: sudo vim /etc/resolv.conf ...
    99+
    2015-07-11
    php7 phpize
  • php 5.6.30没有php.ini的解决方法
    这篇文章给大家分享的是有关php 5.6.30没有php.ini的解决方法的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。php是什么语言php,一个嵌套的缩写名称,是英文超级文本预处理语言(PHP:Hyperte...
    99+
    2023-06-15
  • ubuntu下没有中文输入法的解决办法
    ubuntu下没有中文输入法的解决办法! 我们在安装虚拟机或者ubuntu系统的时候,常见的是尽管是中文版本的但却没有中文输入法,确实是一件很恼火的事情! 我自己也亲身经历过,特此给大家提供一种方法,很好用的! 我们在安...
    99+
    2022-06-04
    ubuntu中文输入法 ubuntu下没有中文输入法的解决办法
  • 没有找到msvcr100.dll的解决方法
    小编给大家分享一下没有找到msvcr100.dll的解决方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!  没有找到msvcr100.dll怎么办  方法一: ...
    99+
    2023-06-06
软考高级职称资格查询
推荐阅读
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作