css - 放大缩小CSS中的问题

标签 css html

您好,我正在粘贴我的页面代码,因为我有一张背景图片。在那里我需要放置按钮。当我进行放大和缩小时,按钮会从位置移动。

<html>
<head>
    <style type="text/css">
        body
        {   
            background:SteelBlue url('BG_BLUE_NEW.jpg') no-repeat center center;
        }
        .login
        {
            margin-top:300px;
            height:300px
        }
    </style>
</head>
<body>
    <div class="container">
    <div class="login">
        <form style="padding-left:370px;margin-bottom:0px;">
            <INPUT TYPE="button" style="background-color:SteelBlue;width:100px;height:30px;font-size:150%;margin-bottom:10px" VALUE="Submit" onClick="window.open('http://www.google.com','_blank');"><br>
            <INPUT TYPE="button" style="background-color:SteelBlue;width:100px;height:30px;font-size:150%;margin-bottom:10px" VALUE="Submit" onClick="window.open('http://www.google.com','_blank');"><br>
            <INPUT TYPE="button" style="background-color:SteelBlue;width:100px;height:30px;font-size:150%;margin-bottom:10px" VALUE="Submit" onClick="window.open('http://www.google.com','_blank');"><br>
            <INPUT TYPE="button" style="background-color:SteelBlue;width:100px;height:30px;font-size:150%;margin-bottom:10px" VALUE="Submit" onClick="window.open('http://www.google.com','_blank');"><br>
            <INPUT TYPE="button" style="background-color:SteelBlue;width:100px;height:30px;font-size:150%;margin-bottom:10px" VALUE="Submit" onClick="window.open('http://www.google.com','_blank');"><br>
        </form>
    </div>
    </div>
</body>
</html>

最佳答案

看看这个:

<html>
<head>
    <style type="text/css">
        body
        {   
            background:SteelBlue url('BG_BLUE_NEW.jpg') no-repeat center center;
        }
        .login
        {
            width:100px; /*<- important edit*/
            margin: 0 auto; /*<- important edit*/
            margin-top:300px;
            height:300px
        }
    </style>
</head>
<body>
    <div class="container">
    <div class="login">
        <form style="margin-bottom:0px;"><!-- removed padding -->
            <INPUT TYPE="button" style="background-color:SteelBlue;width:100px;height:30px;font-size:150%;margin-bottom:10px" VALUE="Submit" onClick="window.open('http://www.google.com','_blank');"><br>
            <INPUT TYPE="button" style="background-color:SteelBlue;width:100px;height:30px;font-size:150%;margin-bottom:10px" VALUE="Submit" onClick="window.open('http://www.google.com','_blank');"><br>
            <INPUT TYPE="button" style="background-color:SteelBlue;width:100px;height:30px;font-size:150%;margin-bottom:10px" VALUE="Submit" onClick="window.open('http://www.google.com','_blank');"><br>
            <INPUT TYPE="button" style="background-color:SteelBlue;width:100px;height:30px;font-size:150%;margin-bottom:10px" VALUE="Submit" onClick="window.open('http://www.google.com','_blank');"><br>
            <INPUT TYPE="button" style="background-color:SteelBlue;width:100px;height:30px;font-size:150%;margin-bottom:10px" VALUE="Submit" onClick="window.open('http://www.google.com','_blank');"><br>
        </form>
    </div>
    </div>
</body>
</html>

这里发生了什么:

我在 .login 上设置了一个指定的 (100px) div 来保存宽度也为 100px 的输入。

然后我申请了margin:0 auto上面写着:将上下边距设置为 0,将左右边距设置为“自动”(增长到填充)

之后,我删除了 <form> 上的 padding-left|元素

您可以在实际中看到它 here

关于css - 放大缩小CSS中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12313679/

相关文章:

css - Flexbox 边距和阶梯效应的偏移问题

javascript - dc.js 教程折线图渲染

javascript - 滚动时更改图像

html - 创建一个不会在 Bootstrap 跨度类中占用整个宽度的 div

javascript - Firefox 的 Web 扩展

css - 为什么 Chrome 会针对出现在错误位置的文本输入字段弹出错误消息?

css - 当浏览器尺寸减小时,图像和 div 部分被截断

html - 如何使所有设备的 hr 行保持在同一行?

html - IE6/7 div 清除时 float 没有宽度问题(在固定宽度的父 div 中)

html - 所有内容顶部的文本