HTML表单重叠图片横幅

时间:2016-10-05 10:51:25

标签: html css

我刚刚开始使用CSS,而且我无法根据需要在图像顶部放置图像横幅。当分辨率很大时,网站看起来很好,但是当它很低(导航窗口较小)时,HTML表单会覆盖横幅。那不是我想要的;我希望横幅始终保持在表单的顶部。图像显示了问题。

Form overlaps the image.

我的HTML代码:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Formulario de registro UVigo</title>
<link rel="stylesheet" href="style/index_style.css">
<script type="text/javaScript" src="p1.js"> </script>
</head>
<body>
<img src= "http://www.colegiosanagustin.net/wp-content/uploads/2016/06/Logo-Formulario.png"></img>
<section id="formulario">
    <p id="titulo">Formulario de registro</p>

    <form method="POST" action="" name="formulario" id="form" onsubmit="return checkForm(this);">
        <input type="text" id="nombre" name="nombre" placeholder="Nombre">
        <input type="text" id="apellidos" name="apellidos" placeholder="Apellidos">
        <input type="text" id="birth" name="birth" placeholder="Fecha de nacimiento">
        <div class="help-tip"><p>Formato: DD/MM/YYYY</p></div>
        <input type="text" id="dni" name="dni" placeholder="DNI">
        <div class="help-tip"><p>Formato ejemplo: 99999999L</p></div>
        <input type="text" id="telephone" name="telephone" placeholder="Tel&eacute;fono">
        <div class="help-tip"><p>Formato ejemplo: 887889781</p></div>
        <input type="mail" id="mail" name="mail" placeholder="Correo electr&oacute;nico">
        <div class="help-tip"><p>Formato: nombre@dominio.com</p></div>
        <input type="password" id="pass" name="pwd1" placeholder="Contrase&ntilde;a">
        <div class="help-tip"><p>Mínimo 6 caracteres. Debe contener al menos una letra mayúscula y un número.</p></div>
        <input type="password" id="pass" name="pwd2" placeholder="Confirmar contrase&ntilde;a">
        <p id="questions">¿Cuáles fueron sus estudios anteriores?<br>
        <select name="studieslist" form="form">
            <option value="bach">Bachillerato</option>
            <option value="ciclo">Ciclo Superior</option>
            <option value="extra">Estudios en el extranjero</option>
        </select>
        <p id="questions">¿Desea recibir comunicaciones por parte de la Universidad de Vigo?<br>
        <input type="checkbox" name="h" value="1" id="g"> SMS
        <br/>
        <input type="checkbox" name="h" value="2" id="g"> Correo electrónico
        <br/>
        <input type="checkbox" name="h" value="3" id="g"> Teléfono
        <br/>
        <input type="button" id="prueba" name="sub" value="Marcar todas" onclick="checkall(document.formulario.h)">
        <input type="button" name="sub" value="Desmarcar todas" onclick="uncheckall(document.formulario.h)">
        <p id="questions">¿Desea activar el servicio de "Notas al móvil"?<br>
        <input type="radio" name="mobilegrade" value="yes" checked="checked"> Sí<br>
        <input type="radio" name="mobilegrade" value="no"> No</p>
        <p id="questions">Escriba aquí cualquier comentario adicional que desee adjuntar con el formulario:<br>
        <textarea name="comment" form="form" placeholder="Comentario adicional..." rows="4" cols="50"></textarea></p>
        <div id="outer">
        <p id="opcionesenvio">Opciones de envío</p>
        <p id="questions">Tipo de codificación:<br>
        <input type="radio" name="codification" value="urlencoded" checked="checked"> application/x-www-form-urlencoded<br>
        <input type="radio" name="codification" value="multipart"> multipart/form-data</p>
        <p id="questions">Método de envío:<br>
        <input type="radio" name="sendmethod" value="GET"> GET<br>
        <input type="radio" name="sendmethod" value="POST" checked="checked"> POST</p>
        <p id="questions">Enviar a:<br>
        <input type="radio" name="sendto" value="myphp" checked="checked"> Fichero PHP (p1.php)<br>
        <input type="radio" name="sendto" value="sintprofphp"> URL "/~sint0/p1.php"</p>
        <input type="hidden" name="navegador"/>
        <input type="hidden" name="hora"/>
        <div class="inner"><input type="submit" value="enviar"></div>
        <div class="inner"><input type="reset" value="limpiar"></div>
        </div>
    </form>
</section>
</body>
</html>

我的css代码:

*{
margin:0px;
padding:0px;
font-family: Tahoma;
font-weight: lighter;
}

img{
display: block;
margin: auto;
margin-top: 10px;
}

body{
background-color: #E0ECF8;
overflow-y: scroll;
}

section#formulario{
position: absolute;
top:50%;
left: 50%;
margin-left: -200px;
margin-top: -240px;
width:400px;
min-height: 100px;
background-color: white;
overflow: hidden;
border-radius: 5px;

}

p#titulo{
font-size: 1.6em;
text-align: center;
margin-top: 20px;
}

p#opcionesenvio{
font-size: 1.6em;
text-align: center;
margin-top: 20px;
}

p#questions{
font-size: 1em;
margin-top: 10px;
margin-left: 20px;
text-align: left;
}

input[type="text"], input[type="password"], input[type="mail"], input[type="birth"], input[type="dni"]{
width: 335px;
height: 35px;
margin-left: 20px;
margin-top:10px;
padding-left: 10px;
font-size: 1.1em;
outline: none;
border:0px;
background-color: #dcdcdc;
border-radius: 5px;
}

textarea{
width: 335px;
margin-left: 0px;
margin-top:10px;
padding-left: 10px;
font-size: 1em;
outline: none;
border:0px;
background-color: #dcdcdc;
border-radius: 5px;
}

#outer
{
width:100%;
text-align: center;
}
.inner
{
display: inline-block;
}


input[type="submit"]{
margin:20px;
margin-bottom: 20px;
width:157px;
height: 40px;
outline: none;
border:0px;
background-color: #75b6dc;
color: white;
font-size: 1.2em;
border-radius: 5px;
-webkit-box-shadow:0px 5px 0px #659dbf;

}

input[type="reset"]{
margin:20px;
margin-bottom: 20px;
width:157px;
height: 40px;
outline: none;
border:0px;
background-color: #585858;
color: white;
font-size: 1.2em;
border-radius: 5px;
-webkit-box-shadow:0px 5px 0px #424242;

}

.help-tip{
display: inline-block;
position: static;
text-align: center;
background-color: #BCDBEA;
border-radius: 50%;
width: 24px;
height: 24px;
font-size: 14px;
line-height: 26px;
cursor: default;
}

.help-tip:before{
content:'?';
font-weight: bold;
color:#fff;
}

.help-tip:hover p{
display:block;
transform-origin: 100% 0%;

-webkit-animation: fadeIn 0.3s ease-in-out;
animation: fadeIn 0.3s ease-in-out;

}

.help-tip p{    /* The tooltip */
display: none;
text-align: left;
background-color: #1E2021;
padding: 10px;
width: 200px;
position: absolute;
border-radius: 3px;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
right: -4px;
color: #FFF;
font-size: 13px;
line-height: 1.4;
}

.help-tip p:before{ /* The pointer of the tooltip */
position: absolute;
content: '';
width:0;
height: 0;
border:6px solid transparent;
border-bottom-color:#1E2021;
right:15px;
top:-12px;
}

.help-tip p:after{ /* Prevents the tooltip from being hidden */
width:100%;
height:40px;
content:'';
position: absolute;
top:-40px;
left:0;
}

/* CSS animation */

@-webkit-keyframes fadeIn {
0% { 
    opacity:0; 
    transform: scale(0.6);
}

100% {
    opacity:100%;
    transform: scale(1);
}
}

@keyframes fadeIn {
0% { opacity:0; }
100% { opacity:100%; }
}

JS Fiddle

https://jsfiddle.net/zg4g3Lke/

我应该采取哪种方式来纠正这个问题?谢谢!

6 个答案:

答案 0 :(得分:0)

*{
margin:0px;
padding:0px;
font-family: Tahoma;
font-weight: lighter;
}

img{
display: block;
margin: auto;
margin-top: 10px;
}

body{
background-color: #E0ECF8;
overflow-y: scroll;
}


section#formulario {
    position: absolute;
    top: 0px;
    left: 50%;
    margin-left: -200px;
    margin-top: 250px;
    width: 400px;
    min-height: 100px;
    background-color: white;
    overflow: hidden;
    border-radius: 5px;
}

p#titulo{
font-size: 1.6em;
text-align: center;
margin-top: 20px;
}

p#opcionesenvio{
font-size: 1.6em;
text-align: center;
margin-top: 20px;
}

p#questions{
font-size: 1em;
margin-top: 10px;
margin-left: 20px;
text-align: left;
}

input[type="text"], input[type="password"], input[type="mail"], input[type="birth"], input[type="dni"]{
width: 335px;
height: 35px;
margin-left: 20px;
margin-top:10px;
padding-left: 10px;
font-size: 1.1em;
outline: none;
border:0px;
background-color: #dcdcdc;
border-radius: 5px;
}

textarea{
width: 335px;
margin-left: 0px;
margin-top:10px;
padding-left: 10px;
font-size: 1em;
outline: none;
border:0px;
background-color: #dcdcdc;
border-radius: 5px;
}

#outer
{
width:100%;
text-align: center;
}
.inner
{
display: inline-block;
}


input[type="submit"]{
margin:20px;
margin-bottom: 20px;
width:157px;
height: 40px;
outline: none;
border:0px;
background-color: #75b6dc;
color: white;
font-size: 1.2em;
border-radius: 5px;
-webkit-box-shadow:0px 5px 0px #659dbf;

}

input[type="reset"]{
margin:20px;
margin-bottom: 20px;
width:157px;
height: 40px;
outline: none;
border:0px;
background-color: #585858;
color: white;
font-size: 1.2em;
border-radius: 5px;
-webkit-box-shadow:0px 5px 0px #424242;

}

.help-tip{
display: inline-block;
position: static;
text-align: center;
background-color: #BCDBEA;
border-radius: 50%;
width: 24px;
height: 24px;
font-size: 14px;
line-height: 26px;
cursor: default;
}

.help-tip:before{
content:'?';
font-weight: bold;
color:#fff;
}

.help-tip:hover p{
display:block;
transform-origin: 100% 0%;

-webkit-animation: fadeIn 0.3s ease-in-out;
animation: fadeIn 0.3s ease-in-out;

}

.help-tip p{    /* The tooltip */
display: none;
text-align: left;
background-color: #1E2021;
padding: 10px;
width: 200px;
position: absolute;
border-radius: 3px;
box-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
right: -4px;
color: #FFF;
font-size: 13px;
line-height: 1.4;
}

.help-tip p:before{ /* The pointer of the tooltip */
position: absolute;
content: '';
width:0;
height: 0;
border:6px solid transparent;
border-bottom-color:#1E2021;
right:15px;
top:-12px;
}

.help-tip p:after{ /* Prevents the tooltip from being hidden */
width:100%;
height:40px;
content:'';
position: absolute;
top:-40px;
left:0;
}

/* CSS animation */

@-webkit-keyframes fadeIn {
0% { 
    opacity:0; 
    transform: scale(0.6);
}

100% {
    opacity:100%;
    transform: scale(1);
}
}

@keyframes fadeIn {
0% { opacity:0; }
100% { opacity:100%; }
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Formulario de registro UVigo</title>
<link rel="stylesheet" href="style/index_style.css">
<script type="text/javaScript" src="p1.js"> </script>
</head>
<body>
<img src= "http://www.colegiosanagustin.net/wp-content/uploads/2016/06/Logo-Formulario.png"></img>
<section id="formulario">
    <p id="titulo">Formulario de registro</p>

    <form method="POST" action="" name="formulario" id="form" onsubmit="return checkForm(this);">
        <input type="text" id="nombre" name="nombre" placeholder="Nombre">
        <input type="text" id="apellidos" name="apellidos" placeholder="Apellidos">
        <input type="text" id="birth" name="birth" placeholder="Fecha de nacimiento">
        <div class="help-tip"><p>Formato: DD/MM/YYYY</p></div>
        <input type="text" id="dni" name="dni" placeholder="DNI">
        <div class="help-tip"><p>Formato ejemplo: 99999999L</p></div>
        <input type="text" id="telephone" name="telephone" placeholder="Tel&eacute;fono">
        <div class="help-tip"><p>Formato ejemplo: 887889781</p></div>
        <input type="mail" id="mail" name="mail" placeholder="Correo electr&oacute;nico">
        <div class="help-tip"><p>Formato: nombre@dominio.com</p></div>
        <input type="password" id="pass" name="pwd1" placeholder="Contrase&ntilde;a">
        <div class="help-tip"><p>Mínimo 6 caracteres. Debe contener al menos una letra mayúscula y un número.</p></div>
        <input type="password" id="pass" name="pwd2" placeholder="Confirmar contrase&ntilde;a">
        <p id="questions">¿Cuáles fueron sus estudios anteriores?<br>
        <select name="studieslist" form="form">
            <option value="bach">Bachillerato</option>
            <option value="ciclo">Ciclo Superior</option>
            <option value="extra">Estudios en el extranjero</option>
        </select>
        <p id="questions">¿Desea recibir comunicaciones por parte de la Universidad de Vigo?<br>
        <input type="checkbox" name="h" value="1" id="g"> SMS
        <br/>
        <input type="checkbox" name="h" value="2" id="g"> Correo electrónico
        <br/>
        <input type="checkbox" name="h" value="3" id="g"> Teléfono
        <br/>
        <input type="button" id="prueba" name="sub" value="Marcar todas" onclick="checkall(document.formulario.h)">
        <input type="button" name="sub" value="Desmarcar todas" onclick="uncheckall(document.formulario.h)">
        <p id="questions">¿Desea activar el servicio de "Notas al móvil"?<br>
        <input type="radio" name="mobilegrade" value="yes" checked="checked"> Sí<br>
        <input type="radio" name="mobilegrade" value="no"> No</p>
        <p id="questions">Escriba aquí cualquier comentario adicional que desee adjuntar con el formulario:<br>
        <textarea name="comment" form="form" placeholder="Comentario adicional..." rows="4" cols="50"></textarea></p>
        <div id="outer">
        <p id="opcionesenvio">Opciones de envío</p>
        <p id="questions">Tipo de codificación:<br>
        <input type="radio" name="codification" value="urlencoded" checked="checked"> application/x-www-form-urlencoded<br>
        <input type="radio" name="codification" value="multipart"> multipart/form-data</p>
        <p id="questions">Método de envío:<br>
        <input type="radio" name="sendmethod" value="GET"> GET<br>
        <input type="radio" name="sendmethod" value="POST" checked="checked"> POST</p>
        <p id="questions">Enviar a:<br>
        <input type="radio" name="sendto" value="myphp" checked="checked"> Fichero PHP (p1.php)<br>
        <input type="radio" name="sendto" value="sintprofphp"> URL "/~sint0/p1.php"</p>
        <input type="hidden" name="navegador"/>
        <input type="hidden" name="hora"/>
        <div class="inner"><input type="submit" value="enviar"></div>
        <div class="inner"><input type="reset" value="limpiar"></div>
        </div>
    </form>
</section>
</body>
</html>

试试此代码

刚刚在课堂上改变了

section#formulario {
    position: absolute;
    top: 0px;
    left: 50%;
    margin-left: -200px;
    margin-top: 250px;
    width: 400px;
    min-height: 100px;
    background-color: white;
    overflow: hidden;
    border-radius: 5px;
}

答案 1 :(得分:0)

原因是

position: absolute;

成功

position: relative;

或者,如果position:absolute是必要的,请为表单提供margin-top。

答案 2 :(得分:0)

这是更新的jsFiddle

更新下面的CSS行

section#formulario {
  background-color: white;
  border-radius: 5px;
  margin: 0 auto;
  min-height: 100px;
  overflow: hidden;
  width: 400px;
}

答案 3 :(得分:0)

我更新了您的CSS代码。

得到它

https://jsfiddle.net/zg4g3Lke/3/

已删除position:absolute并添加margin 0 auto以使其位于中间位置。

祝你好运!

答案 4 :(得分:0)

您的<section id="formulario">元素位置绝对且边距为负。您应该让html文档遵循正常流程。

此外,如果您希望它居中,您可以在定义宽度后使用margin: 0 auto;

试试这个小提琴:https://jsfiddle.net/2qyufp7t/1/

答案 5 :(得分:0)

除了其他人给出的答案之外,如果您感兴趣,我想指出一些可以在您的代码中进行改进的事情。

  

position: absolute属性从技术上将元素拉出HTML,因此除非必要不使用它

  1. 尝试使用容器满足此类要求,并将position: relative应用于该容器&amp;相反,将所有子项相对于父项移动。

  2. 如果您使用left&amp; right定位您的元素,您也无需使用margin-left&amp; margin-right。您可以使用margin: auto将元素置于中心位置(注意:这需要width属性

  3. 所以你section#formulario可以像

    一样简单
    section#formulario{
        width:400px;
        margin: auto;
        min-height: 100px;
        background-color: white;
        overflow: hidden;
        border-radius: 5px;
    }
    

    因此,基本上在您的情况下,您只需要从section#formulario中删除多余的不需要的代码。 Check here