Javascript 通过更改屏幕分辨率调整按钮大小

Javascript 通过更改屏幕分辨率调整按钮大小,javascript,jquery,css,Javascript,Jquery,Css,我有html页面、背景图像和按钮,当我调整浏览器窗口的大小时,背景适合它,但按钮不适合。我想通过更改屏幕或浏览器窗口来调整按钮的大小,你能帮我吗?谢谢大家 index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3

我有html页面、背景图像和按钮,当我调整浏览器窗口的大小时,背景适合它,但按钮不适合。我想通过更改屏幕或浏览器窗口来调整按钮的大小,你能帮我吗?谢谢大家

index.html

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Post</title>
</head>

<body>
<div>
<table cellspacing="0"  cellpadding="0">
<tr>
<td>
<img id="bgimage" src="heroes.jpg"/>
<div id="content">
<input type="submit" value="Click" class="butt" onclick="dosomething();"/>
</div>
</td>
</tr>
</table>
</div>
<style>
body,html{margin:0;padding:0; height:100% width:100%}
#bgimage{ position:fixed; left:0; top:0; z-index:1;height:100%; width:100%;}

.butt {
    -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
    -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
    box-shadow:inset 0px 1px 0px 0px #ffffff;
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf) );
    background:-moz-linear-gradient( center top, #ededed 5%, #dfdfdf 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#dfdfdf');
    background-color:#ededed;
    -moz-border-radius:6px;
    -webkit-border-radius:6px;
    border-radius:6px;
    border:1px solid #3c4fd9;
    display:inline-block;
    color:#777777;
    font-family:arial;
    font-size:15px;
    font-weight:bold;
    padding:6px 24px;
    text-decoration:none;
    text-shadow:1px 1px 0px #ffffff;
    float: left;
padding: 10px;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;

}

.butt:hover {
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #dfdfdf), color-stop(1, #ededed) );
    background:-moz-linear-gradient( center top, #dfdfdf 5%, #ededed 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf', endColorstr='#ededed');
    background-color:#dfdfdf;
}
.butt:active {
    position:relative;
    top:1px;
}
.butt{

    position: fixed;
    top: 40%;
    left: 39%;
    z-index: 1;


}

/*#content{position:absolute;left:-39%; top:-40%; z-index:70; height:100%; width:100%;}*/

</style>

<script type="text/javascript">
//$(window).resize(function() {
  //$(window).height(); 
  //$(window).width(); 
  //});
//get dimensions 
//var height = $(window).height();
//var width = $(window).width();
//refresh on resize
//$(window).resize(function() {
//$("#butt").css("height", "20px");
//$("#butt").css("width", "20px");
//});

</script>
</body>
</html>

邮递
正文,html{margin:0;padding:0;高度:100%宽度:100%}
#bgimage{位置:固定;左:0;顶:0;z索引:1;高度:100%;宽度:100%;}
.屁股{
-moz盒阴影:插入0px 1px 0px 0px#ffffff;
-网络工具包盒阴影:插入0px 1px 0px 0px#ffffff;
盒影:插入0px 1px 0px 0px#ffffff;
背景:-webkit渐变(线性、左上、左下、颜色停止(0.05,#eded)、颜色停止(1,#dfdf));
背景:-莫兹线性梯度(中心-顶部,#eded 5%,#dfdf 100%);
过滤器:progid:DXImageTransform.Microsoft.gradient(startColorstr='#eded',endColorstr='#dfdfdf');
背景色:#ededed;
-moz边界半径:6px;
-webkit边界半径:6px;
边界半径:6px;
边框:1px实心#3c4fd9;
显示:内联块;
颜色:#777777;
字体系列:arial;
字体大小:15px;
字体大小:粗体;
填充:6px 24px;
文字装饰:无;
文本阴影:1px 1px 0px#ffffff;
浮动:左;
填充:10px;
边界半径:10px;
-moz边界半径:10px;
-webkit边界半径:10px;
}
.屁股:悬停{
背景:-webkit渐变(线性、左上、左下、颜色停止(0.05,#dfdfdf)、颜色停止(1,#eded));
背景:-莫兹线性梯度(中心-顶部,#dfdfdf 5%,#EDED100%);
过滤器:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf',endColorstr='#ededed');
背景色:#dfdfdf;
}
.butt:活动{
位置:相对位置;
顶部:1px;
}
.屁股{
位置:固定;
最高:40%;
左:39%;
z指数:1;
}
/*#内容{位置:绝对;左侧:-39%;顶部:-40%;z索引:70;高度:100%;宽度:100%;}*/
//$(窗口)。调整大小(函数(){
//$(window.height();
//$(窗口).width();
//});
//获取维度
//var height=$(window.height();
//变量宽度=$(窗口).width();
//调整大小时刷新
//$(窗口)。调整大小(函数(){
//$(“#butt”).css(“高度”,“20px”);
//$(“对接”).css(“宽度”,“20px”);
//});
style.css

html {height:100%;}
body {height:100%; margin:0; padding:0;}
#bg {position:fixed; top:0; left:0; width:100%; height:100%;}
<!--[if IE 6]>

html {overflow-y:hidden;}
body {overflow-y:auto;}
#bg {position:absolute; z-index:-1;}


<![endif]-->
html{height:100%;}
正文{高度:100%;边距:0;填充:0;}
#bg{位置:固定;顶部:0;左侧:0;宽度:100%;高度:100%;}

图像

使用相对测量(如百分比)指定宽度而不是固定的像素。

以百分比表示按钮宽度。

将填充设置为每美分,如果调整页面大小时更改了基本字体大小,则可能将字体大小设置为每美分。

您可以使用百分比值设置按钮尺寸(但它们将首先相对于父元素,而不是浏览器窗口)。使用媒体查询更改值也会起作用。
位置:固定;宽度:100%;高度:100%
?上传一些代码please@Teemu我不推荐
position:fixed;
@badZoke No?有什么问题吗?从IE7开始,在所有现代浏览器中都可以使用。嗯,你们真的不知道如何编写CSS来分配宽度吗?如果你希望你的
.butt
为50%,那么就做
.butt{width:50%;}
吧,等等。是的,我知道这一点,但我想通过更改浏览器尺寸来设置宽度,这正是它的作用。如果你对宽度使用百分比,当浏览器的尺寸发生变化时,所有元素的尺寸都会用百分比设置。