How do you use background: auto; correctly? - html

I'm trying to make the background fill the whole page. The only way I figured out how to do it is by setting the height and width of <div id="All"> and putting that div around everything else. I know that if I change the size of the browser, though, it won't auto resize, so it would look weird if I made my browser smaller or bigger.
If I set height and width to auto on #All, it def doesn't fill out the whole webpage. Please advise what I am doing wrong. Plus if I do auto, the sticky #Move doesn't stay at the top of the page.
This code is just stuff I have learned, so not an actual project, but I want to learn how to do it for future projects.
#Move {
position: sticky;
top: 0;
color: red;
}
h1 {
color: red;
}
.Hello {
font-size: 36px;
}
.Hello2 {
font-size: 15px;
}
p {
color: white;
}
.DivClass {
width: 160px;
height: 220px;
padding: 40px;
border: 10px solid black;
border-radius: 60px;
margin: 50px;
background: url("https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSqOq9_iT948LTPmS5FuCMlaqlvn2KJQ-0d7Xw5kLMfWz69wwRA&usqp=CAU");
background-repeat: no-repeat;
background-size: cover;
opacity: 80%;
}
.image-whitecat {
width: 500px;
heigth: 500px;
background-color: red;
margin: 50px 50px 90px 250px;
transform: rotate(10deg);
}
.image-cat {
width: 700px;
height: 500px;
border-radius: 300px;
margin-left: 350px;
filter: opacity(70%)
}
.Purple {
color: purple;
}
.PurpleText {
background: teal;
text-align: center;
padding-top: 50px;
width: 150px;
height: 100px;
border: 5px solid red;
border-radius: 100px;
margin: 10px 0 0 1000px;
}
#All {
background-color: lavender;
position: absolute;
top: 10px;
bottom: 10px;
height: 1850px;
width: 1810px;
}
<div id="All">
<div class="DivClass">
<h1>HELLO!!!</h1>
<p class="Hello">Hello</p>
<p class="Hello2">Hello 2</p>
<p>Yes</p>
</div>
<p id="Move">I will stay at the top of the page!</p>
<div>
<img src="https://cdn.pixabay.com/photo/2014/11/30/14/11/kitty-551554__340.jpg" class="image-whitecat" />
</div>
<div>
<img src="https://cdn.pixabay.com/photo/2016/03/28/12/35/cat-1285634__340.png" class="image-cat" />
</div>
<div class="PurpleText">
<p class="Purple">Purple</p>
</div>
</div>

I think you will need to give both your html and body tags a css height ...
html, body {
height: 100%;
margin: 0;
}
So,
https://jsfiddle.net/z51crou7/

Related

How can I get the position of a child element not fixed even though the parent is fixed?

As the title says: I need the 'info-box' to not be fixed while the head-box and head-in-block are fixed.
I know it is possible. I have a live example: http://www.marktplaats.nl/.
The orange box is fixed (head-box) then the white part (my info-box) is not fixed. And the Title block is fixed again (head-in-block).
This is the css and html I'm using right now. What adjustment needs to be made to make the middle (white) box not fixed?
#head-block{
width: 100%;
height: auto;
background: rgb(245,245,245);
border: 1px solid grey;
z-index: 1000;
margin-top: 0px;
}
#head-box{
height: 5px;
background: #37326a;
}
#info-box{
height: 50px;
background: white;
position: static;
}
#head-in-block{
width: 1100px;
height: 60px;
color: #37326a;
text-align: left;
margin: auto;
padding: 10px;
}
.fixed{
position: fixed;
}
<div id='head-block' class='fixed'>
<div id='head-box'></div>
<div id='info-box'></div>
<div id='head-in-block'>
</div>
</div>
<div style='height: 1500px;' id='content'>
</div>
Test
Do you guys see the website the same I do?
The website you linked to hides the white box when the header is sticky. So to do that here, you would hide #info-box when #head-block has class .fixed
.fixed #info-box {
display: none;
}
#head-block{
width: 100%;
height: auto;
background: rgb(245,245,245);
border: 1px solid grey;
z-index: 1000;
margin-top: 0px;
}
#head-box{
height: 5px;
background: #37326a;
}
#info-box{
height: 50px;
background: white;
position: static;
}
#head-in-block{
width: 1100px;
height: 60px;
color: #37326a;
text-align: left;
margin: auto;
padding: 10px;
}
.fixed{
position: fixed;
}
.fixed #info-box {
display: none;
}
<div id='head-block' class='fixed'>
<div id='head-box'></div>
<div id='info-box'></div>
<div id='head-in-block'>
</div>
</div>
<div style='height: 1500px;' id='content'>
</div>
Test

CSS child element producing a margin the full width of parent

building an overlay containing a stylised container for some text, however this container seems to be producing a margin which when combined with the elements normal width takes up the entire parent element width. According to chrome dev tools its the .flipcontainerelement that is causing this.
It's really weird behaviour and I can't figure out why its behaving in this way.
If I wanted to place content to the right of the container for example, I would not be able to because of this margin being produced.
.flipcontainer {
height: 230px;
width: 150px;
}
.flipcalender {
border: 1px solid #dddddd;
border-radius: 25px;
margin: 0 auto;
margin-top: 0.2px;
background: linear-gradient(white, #f4f2f2);
}
.mmouter {
width: 100%;
height: 100%;
border: 1.5px solid #dddddd;
}
.mmmiddle {
width: 98%;
height: 98%;
}
.mminner {
width: 98%;
height: 98%;
background: linear-gradient(white, #f4f2f2);
position: relative;
}
.mmbreaker {
width: 99%;
background-color: white;
height: 2px;
position: absolute;
z-index: 1;
top: 115px;
}
#mmlightbox {
display: block;
width: 400px;
height: auto;
position: fixed;
top: 30%;
left: 40%;
z-index: 999;
background-color: white;
padding: 10px 20px 10px 0px;
/* margin-right: 239px; */
margin-top: -100px;
margin-left: -150px;
border: solid 2px #f21c0a;
}
<div id='mmlightbox'>
<div class='flipcontainer'>
<div class='flipcalender mmouter'>
<div class='flipcalender mmmiddle'>
<div class='flipcalender mminner'>
<p class='daysremaining'></p>
<p>days</p>
<div class='mmbreaker'></div>
</div>
</div>
</div>
</div>
</div>
Add float: right; to .flipcontainer css like so:
.flipcontainer {
height: 230px;
width:150px;
float: right;
}
Here is the JSFiddle demo
The margin you saw was because you specified the width to '150px'.
Adding float: left removes this and you can add content next to it
.flipcontainer {
height: 230px;
width:150px;
float: left;
}
See Fiddle http://jsfiddle.net/epe3bfdw/

How to make header like that in css?

My site code is very usual
<div class="header"></div>
<div class="site-inner"></div>
<div class="footer"></div>
How can I make header background like on the image?
Is the whole site content have to be position absolute and margin-top:-500px ?
Is that only case to do it?
I assume you mean the overlap.
Negative margin is one way.
.header {
height: 50px;
background: lightblue;
}
.site-inner {
width: 80%;
margin: auto;
height: 50px;
background: lightgrey;
margin-top: -30px;
box-shadow: 0 -2px 2px black;
}
<div class="header"></div>
<div class="site-inner"></div>
You can use:
.header{
width: 80%;
height: 75px;
margin: 0 auto;
margin-top: -20px;
background:#3A3A3A;
}
Take a look at positioning: Positioning, also z-index might be relevant: Z-index, notice in my example the negative index on .header-bg
A quick example:
.header-bg {
width: 100%;
height: 200px;
z-index: -1;
background: lightblue;
position: absolute;
top: 0;
left: 0;
}
.header {
margin-top: 50px;
height: 50px;
background: grey;
z-index
}
.menu {
height: 80px;
}
.site-inner {
height: 400px;
width: 100%;
background: red;
}
<div class="header-bg"></div>
<div class="header"></div>
<div class="menu">menu</div>
<div class="site-inner">Site inner</div>
<div class="footer"></div>
A negative z-index lets you put elements behind others. The answer is simple enough then.
<div class="color"></div>
<div class="fixed">
<div class="header">
</div>
<div class="nav">
Text
</div>
<div class="body">
</div>
</div>
html, body
{
height: 100;
margin: 0;
}
div.color
{
position: absolute; /*Take out of the flow*/
top: 0; /*Move to top left*/
left: 0;
z-index: -1; /*Place below normal elements in the flow*/
width: 100%; /*Fill whole width*/
height: 300px; /*300px tall*/
background: #c7edfb; /*Color specified*/
}
div.fixed
{
margin: 50px auto 0; /*push whole document down 50px and center*/
width: 600px; /*document is 600px wide*/
}
div.header
{
height: 150px; /*top gray block is 150px tall*/
background: #222; /*dark gray*/
}
div.nav
{
padding: 25px 0; /*Gap between blocks above and below*/
}
div.body
{
min-height: 300px; /*Force a height*/
background: #777; /*Light gray*/
box-shadow: 0 0 8px black; /*Drop shadow*/
}
JSFiddle

Issue with content scrolling over banner and under header

So I have this fixed header which has z-index:10, below that a fixed banner and then below that a relative content container. What I want is that the content scrolls over the banner but under the header. However, when I try to scroll it doesn't work. The strange part to me is that whenever I add box-shadow: 0px 0px 2px rgb(100,100,125); to the content container it does do what I want. I'm using the following code:
* {
padding: 0;
margin: 0 auto;
}
body {
background: rgb(223,227,238);
text-align: center;
}
#body_container {
padding-top: 80px;
}
#banner_container {
position: fixed;
left: 0;
right: 0;
}
#banner {
width: 1024px;
height: 300px;
}
#content_container {
background: rgb(243,247,248);
max-width: 1024px;
height: 100%;
position: relative;
top: 300px;
box-shadow: 0px 0px 2px rgb(100,100,125);
}
header {
min-width: 100%;
background: rgb(50,50,50);
height: 80px;
position: fixed;
z-index: 10;
}
/* Header styling, not relevant */
#header_container {
max-width: 1024px;
height: 100%;
}
#header_container div {
float: left;
display: inline-block;
width: 25%;
}
#logo {
width: 50%;
height: auto;
}
.menuItem {
padding-top: 29px;
height: calc(100% - 29px);
border: 0;
text-align: center;
font-family: Signika;
font-size: 25px;
color: rgb(203,207,218);
}
.menuItem:hover {
border-bottom: 4px solid rgb(59,89,202);
height: calc(100% - 33px);
color: rgb(160,170,218);
}
.menuLogo {
padding-top: 14.5px;
height: calc(100% - 14.5px);
border: 0;
text-align: center;
}
#mobile_menu_button {
display: none;
}
<header>
<div id="header_container">
<div class="menuLogo">
<img id="logo" src="img/desygn%20logo%20website.png">
</div>
<div class="menuItem">Home</div>
<div class="menuItem">Over</div>
<div class="menuItem">Contact</div>
<div id="mobile_menu_button">
</div>
</div>
</header>
<div id="body_container">
<div id="banner_container">
<img id="banner" src="img/banner_website.png">
</div>
<div id="content_container">
</div>
</div>
In your code you've not added any content under content_container. I don't see any issue with your code. It is working fine. Check here with content

How to make footer stick to bottom of wrapper with bottom margin?

I´m trying to make a footer that sticks to the bottom of wrapper, but leaving a bottom margin so that the pattern image on the body background can be seen.
I came accross the sticky footer at
http://ryanfait.com/resources/footer-stick-to-bottom-of-page/
which worked great, but all my attempts of adding margin/paddings to footer/ wrapper/ body didn´t.
I guess it must be a pretty simple thing, but I´m not finding it. Thanks for any hints/ suggestions!
Here´s the relevant CSS:
*
{
margin: 0;
}
html, body
{
margin-top: 0px;
margin-bottom: 25px;
background-repeat: repeat;
background-image: url(images/modulo-pattern-grey-light.gif);
height: 100%;
}
#wrapper
{
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -98px;
background: #fff url(images/footer.gif) left bottom no-repeat;
width: 980px;
box-shadow: 4px 4px 5px #999;
}
.footer, .push
{
height: 98px;
}
.footer
{
margin-left: 490px;
margin-right: 40px;
background-color: #bc4c9b;
}
HTML:
<div id="wraper">
<div class="header"></div>
<div class="logo">
</div>
<div class="menu_container">
<div class="main_menu">
<ul>
<li>Home</li>
<li><a class="selected" >Quiénes Somos</a></li>
<li>Consultoría</li>
<li>Capacitación</li>
<li>Académico / Artículos</li>
<li>Alianzas</li>
<li>Proyectos</li>
<li>Contacto</li>
</ul>
</div>
</div>
<div class="quienes_pic"></div>
<div class="quienes_text"></div>
<div class="push"></div>
</div>
<div class="footer"></div>
Sorry I didn´t mention, but Fixed position won´t work, since I want the same footer to work on different pages with differents heighs. The idea was to have the same wraper and footer through all the pages, and then assigning different body ids to set the different heighs
Pretty much like is done through this site:
http://www.casadelviento.com.ar/
In this case, it´s using different body ids AND different wrappers, I thought may be it could be done with less code and more clear (i.e I don´t understand why is the difference between the wraper heigh #contenido-index and the body heigh)
#contenido-index {
background-color: #FFF;
height: 2040px;
width: 900px;
margin: 0 auto;
}
#contenido-chicos {
background-color: #FFF;
height: 2760px;
width: 900px;
margin: 0 auto;
}
#contenido-adultos {
background-color: #FFF;
height: 2810px;
width: 900px;
margin: 0 auto;
}
#contenido-somos {
background-color: #FFF;
height: 2150px;
width: 900px;
margin: 0 auto;
}
#contenido-historia {
background-color: #FFF;
height: 980px;
width: 900px;
margin: 0 auto;
}
#contenido-horarios {
background-color: #FFF;
height: 967px;
width: 900px;
margin: 0 auto;
}
#contenido-contacto {
background-color: #FFF;
height: 750px;
width: 900px;
margin: 0 auto;
}
#contenido-videos {
background-color: #FFF;
height: 820px;
width: 900px;
margin: 0 auto;
}
#contenido-fotos {
background-color: #FFF;
height: 595px;
width: 900px;
margin: 0 auto;
}
#body-index {
height: 2160px;
}
#body-somos {
height: 2070px;
}
#body-historia {
height: 1150px;
}
#body-horarios {
height: 1060px;
}
#body-chicos {
height: 2700px;
}
#body-adultos {
height: 2800px;
}
#body-videos {
height: 960px;
}
#body-fotos {
height: 740px;
}
#body-contacto {
height: 880px;
}
/*FOOTER}*/
#contenedor_pie {
height: 40px;
width: 500px;
float: left;
margin-left: 20px;
margin-top: 15px;
}
With Reference to http://alt-web.com/DEMOS/CSS2-Sticky-Footer.shtml
You can define your footer HTML as
<div id="Sticky">
<h2>Here is a Sticky Footer</h2>
<p>Test for Sticky Footer</p>
</div>
then your CSS would be like
#Sticky
{
color:#FFF;
text-shadow: 2px 2px 2px #333;
border: 2px solid orange;
position:fixed;
padding: 0 10px 0 10px;
left: 0px;
bottom: 0px;
width: 100%;
}
Hey you can do easily just define in your css some code as like this
Css
body{background:green;}
#wrapper {
background:red;
min-height:700px;
}
.footer {
position:fixed;
bottom:20px;
height:100px;
background:yellow;
left:0;
right:0;
}
HTML
<div id="wrapper">Wraper text </div>
<div class="footer">Sticky footer</div>
Live demo http://jsfiddle.net/6z6Uk/
​
and now adjust according to your design .