Table of Contents
回复讨论(解决方案)
Home Web Front-end HTML Tutorial Urgent help: How to realize adaptive resolution of background images and adjustment of IE window_html/css_WEB-ITnose

Urgent help: How to realize adaptive resolution of background images and adjustment of IE window_html/css_WEB-ITnose

Jun 24, 2016 pm 12:15 PM

Dear experts, please give me some advice. I have a jsp login page here. In addition to the input boxes and buttons on the page, there is a background image. The positions of the input boxes are all relative positions. However, after IE or resolution adjustment, the input box and background image will still be misaligned. I would like to ask everyone, how can I make the background image change with the changes of IE and resolution? ?
Please give me some advice from all the experts! ! ! ! The page code is as follows:
login.jsp:
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.util.*,com.iproject.examsys. web.to.*" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<%
if(request.getSession (true).getAttribute(UserSessionInfo.USER_SESSION)!=null){
response.sendRedirect("examination/index");
}
response.setHeader("Pragma", "No-cache") ;
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
String path = request.getContextPath();
String basePath = request.getScheme() "://" request.getServerName() ":" request.getServerPort() path "/";
%>





System login









< ;body class="loginBgGround">



width="100%" height="100%">


                                                                                         td colspan="4" width="65.1%" >
                                               ;/td>
                                                               d colspan="2" width="27%">
                                                                   
                
            
                
                                    
                                               
            
                
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                 
                
                
                    
                    
                    
                    
                    
                    
                    
                 
            
                 
                    
                    
                    
                    
                    
                    
                    
                    
                                 
                
                
                    
                    
                    
                    
                    
                    
                    
                   
                
                
                    
                           
            



<script> <br> function processKey(event){ <br> if(event.keyCode==13){ <br> login(); <br> } <br> } <br> <br> function login(){ <br>     var saveFlag = true; <br> <br>     var regArray = new Array(); <br> var errorMsgArray = new Array(); <br> regArray.push(emptyReg);//empty <br> errorMsgArray.push("用户名不能为空 "); <br> regArray.push(/^[\w*\W*]{1,16}$/);//length <br> errorMsgArray.push("最大长度为16"); <br> regArray.push(/^\w{1,16}$/);//character <br> errorMsgArray.push("只能输入字符  0-9 a-z A-Z _"); <br> var temp = checkText("userName",regArray,errorMsgArray); <br> if(saveFlag==true) saveFlag = temp; <br>     <br> <br> regArray = new Array(); <br> errorMsgArray = new Array(); <br> regArray.push(emptyReg);//empty <br> errorMsgArray.push("密码不能为空"); <br> regArray.push(/^[\w*\W*]{1,16}$/);//length <br> errorMsgArray.push("最大长度为16"); <br> regArray.push(/^\w{1,16}$/);//character <br> errorMsgArray.push("只能输入字符  0-9 a-z A-Z _"); <br> temp = checkText("password",regArray,errorMsgArray); <br> if(saveFlag==true) saveFlag = temp; <br> <br> if(saveFlag){ <br> document.forms[0].submit(); <br> } <br> } <br> </script>





对一个的style.css如下:
.loginBgGround{
background-repeat:no-repeat;
background-position:center;
background-image:url(../images/bg.jpg); 
background-attachment:fixed;
width:100%;
height:100%;
}

.loginHeader{
/* background-image:url(../images/bg.jpg);  */
background-color:blue

}

.labelStyle{
font-weight:bold;
font-size:15px;
color:#333333;
}

.inputTextStyle{
/* background-image:url(../images/TextBox.jpg);  */
}


.warningFont{
font-size:12px;
color:#ff0000;
font-weight:bold;
}


.area {
background-image:url(../images/AREA.gif);
height:19px;
width:129px;
border:0px;
font-family:Tahoma;
font-size:12px;
color:#333333;
padding-left:3px;
}

.button{
display: block;
cursor:hand;
width:101px;
   height:92px;

  /*background:url(../images/LoginButton.jpg) no-repeat;*/
}



.button1,.button2{
float:left;
   width:196px;
   height:40px;
   position:relative;
  /*background:url(../images/button.jpg) no-repeat;*/
}

.button1{
display: block;
padding: 5px 10px 5px 11px;
cursor:hand;
font-size :22px;
  background-position:50% 20%;
}
.button2{
display: block;
padding: 5px 10px 5px 11px;

cursor:hand;
font-size :22px;
  background-position:50% 81%;
}


回复讨论(解决方案)

背景图要使用百分比,必须使用CSS3,ie9之前的浏览器不支持的。
你不要采用相对定位的方法,直接设置固定的宽度和高度实现

有一个 不是办法的办法,如果不考虑根据分辨率自适应之后的拉伸问题的话可以这么写先给 大外层 一个 position:relative 。然后 单独在这个层里面建立一个层 

The corresponding css is written like this .bgimg{width:100%;height100%;position:absolute;z-index:xxx;} .bgimg img{width:100%;height:100%;}

In fact The principle is to put this picture at the bottom of the page to fool the visual effect into thinking it is a background. Then stretch this layer. I think stretching a layer is much simpler than stretching a background.

Are you upstairs? After I followed your method, the positions of the page and the input box are now relatively static. But a new problem arises, that is, the page and input appear on the right side of the entire IE. The originally set width = 100%, but in fact the background does appear at IE50%, and then goes to the right to IE150%. .
The code is as follows, please, please, and also all the experts can help me take a look and give me some advice, thank you!
login.jsp code is as follows:

<%@ page contentType="text/html;charset=gb2312" language="java" import="java.util.*,com.iproject.examsys .web.to.*" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<%
if(request. getSession(true).getAttribute(UserSessionInfo.USER_SESSION)!=null){
response.sendRedirect("examination/index");
}
response.setHeader("Pragma", "No-cache" );
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
String path = request.getContextPath();
String basePath = request.getScheme() "://" request.getServerName() ":" request.getServerPort() path "/";
%>




System login















="center" width="100%" height="100%" class="divTB">
                                                                         "100%">
1.875%">
                                                                  65.1%" >
                                                    lt;/td>
                    
                                                                   
                
            
                
                                    
                                               
            
                
                    
                    
                    
                    
                    
                    
                    
                    
                    
                    
                 
                
                
                    
                    
                    
                    
                    
                    
                    
                 
            
                 
                    
                    
                    
                    
                    
                    
                    
                    
                                 
                
                
                    
                    
                    
                    
                    
                    
                    
                   
                
                
                    
                           
            










The css code is as follows:

.loginBgGround{
/*background-repeat:no-repeat;*/
background-position:center;
/*background-image:url(../images/bg.jpg); */
background-attachment:fixed;
width:100%;
height:100%;
position: absolute;
margin:0;
}

. divImg{
width:100%;
height:100%;
position:absolute;
z-index:-1;
margin: 0;
}

.divTB{
width:100%;
height:100%;
position:absolute;
z-index:1;
margin: 0;
}

I did it myself! ! Haha, I broke out in a sweat! Although I got it done by myself in the end, I still have to thank you upstairs, your idea is very clever!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

See all articles