1
I’m starting a project right now and I want to make the header responsive, but I can’t. The header has an effect in js that changes the images every refresh, but I can’t assign the correct height to be responsive, only works in px, and px is not responsive (I don’t want media querie, please), any other data I put does not work, follows:
HTML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head lang="pt-br">
<meta charset="UTF-8">
<title>MMCCPCS</title>
<!-- Estilização -->
<link rel="stylesheet" type="text/css" href="css/estilo.css">
<!--Animate CSS-->
<link rel="stylesheet" type="text/css" href="css/animate.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<body>
<header>
</header>
<section id="empresa">
</section>
<script type="text/javascript">
function randFundo(){
var fundo = [1,2,3,4,5][Math.floor(Math.random()*4)];
!localStorage.fundo ? localStorage.fundo = fundo : 0;
return localStorage.fundo == fundo
?
(localStorage.fundo = fundo+1)
:
(localStorage.fundo = fundo);
}
var e_header = document.querySelector("header");
e_header.style.backgroundImage = "url(imagens/fundo"+randFundo()+".jpg)";
</script>
</body>
</html>
CSS
html{
width: 100%;
height: auto;
margin: 0;
padding: 0;
}
body {
width: 100%;
height: auto;
overflow-y: scroll;
overflow-x: hidden;
margin: 0;
padding: 0;
}
header {
position: relative;
display: block;
top: 0;
left: 0;
margin: 0;
padding: 0;
width: 100%;
height: 650px; /* Aqui está o erro, se coloco em % não dá certo e em px não fica responsivo */
background-color: #D9D625FF;
background-repeat: no-repeat;
}
#empresa {
position: relative;
width: 100%;
height: 300px;
background-color: #1981CD;
margin: 0;
padding: 0;
}
You can’t see the images because they are on my localhost, but you can see what I want) Link Codepen: https://codepen.io/clayton2018/pen/WMbzNd
From what I understand every image you will call in Header has a different height, but you want them all to appear at the same height is this?
– hugocsl
No, all images are 1350 x 600, I just want the header to be responsive, at each width of the browser it fits with the image. If I put in pixel in browsers smaller than 1350 appears the yellow background, because the height is 610px, needed to be in percentage, but if put gives error and does not appear the header.
– Clayton Furlanetto