How to set margin between fixed header and footer in print page? - html

in my html, Header and Footer are fixed but body content overlaps with header and footer. I want to display my content between header and footer without overlap. How can it be achieved ?
Please help me regarding this.i'm using this CSS code mentioned below.
You may check it and resolve this problem.
<style type="text/css">
#media print {
#header {
display: table-header-group;
position: fixed;
top: 0;
left: 0;
margin: 0px;
padding: 0px;
width: 100%;
}
#body {
/*position: absolute;
height: 80%;
margin-top: 0em !important;
margin-bottom: 1em !important;
padding: 2em 0 0 0;
margin:0 auto;*/
position: absolute;
margin-top: 10% !important;
margin-bottom: 5% !important;
height: 80%;
overflow: visible;
text-align: justify;
width: 90%;
}
#footer {
display: table-footer-group;
position: fixed;
bottom: -0.6em;
left: 0;
margin: 5em 0px 0px 0px;
padding: 0px;
width: 100%;
/*clear:both;*/
/*padding-top:98%;*/
/*padding-bottom:1em;*/
/*page-break-after: avoid;*/
}
}
#media screen {
#thead {
display: block;
/*padding-right: 5.9em;
padding-left: 6px;*/
width: 100%;
/*height: 5%;*/
}
#tbody {
display: block;
/*height: 80%;
vertical-align: central;
padding-top: 5em;
padding-bottom: 3em;*/
text-align: justify;
width: 100%;
margin-top: -5em;
}
#tfoot {
display: block;
/*padding-right: 6em;
padding-top: 2em;*/
width: 100%;
/*height: 4%;*/
}
}
</style>

This snippet shows an example of fixed header and footer (with variable height) and content that takes the remaining space. The trick here is to use flexbox: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
body {
overflow: hidden;
}
.content-container {
display: flex;
flex-direction: column;
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
#header {
position: relative;
width: 100%;
background-color: green;
}
#body {
position: relative;
width: 100%;
background-color: blue;
overflow: auto;
}
#footer {
position: relative;
width: 100%;
background-color: red;
}
<div class="content-container">
<div id="header">
<div style="height: 40px;"></div>
</div>
<div id="body">
<div style="height: 1000px;"></div>
</div>
<div id="footer">
<div style="height: 20px;"></div>
</div>
</div>

Related

How can I increase the width or height of the div it is in while moving an item independently?

I want to prevent the "Salgın" text from hitting other articles while moving it in the green divin. I saw that it is possible to do this with the "relative" code. The question is: While moving the text, the height and width of the green divin increase according to its position at the same time. When I give padding or margin to the text "Salgın", the others should not be affected, but the height or width of the green divin will increase.
Or let me put it like this: When I give a position to the "Salgın" article, the height or width of the divin it is located in should increase, but while this happens, the position of the other articles should not change in any way
and must be all in the same div.
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
background-color: #444444;
font-family: Roboto, sans-serif;
font-size: 24px;
}
#hepsi {
background-color: #FC0;
width: auto;
height: auto;
}
#deneme {
display: flex;
justify-content: center;
}
#sol {
float: left;
width: auto;
height: auto;
background-color: #666;
line-height: 0;
}
#orta {
float: left;
width: auto;
height: auto;
background-color: #0C0;
}
#sag {
float: left;
width: 300px;
height: auto;
background-color: #FF6;
}
#kitapfoto {
width: 186px;
height: 273px;
}
#kitapadi {
position: relative;
width: auto;
height: auto;
text-align: center;
font-size: 30px;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
}
#yayinyili {
,
position: relative;
width: auto;
height: auto;
text-align: center;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
}
#kitapturu {
position: relative;
width: auto;
height: auto;
text-align: center;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
}
#okuyucupuani {
position: relative;
width: auto;
height: auto;
text-align: center;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
}
#benimpuanim {
position: relative;
width: auto;
height: auto;
text-align: center;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
}
<div id="hepsi">
<div id="deneme">
<div id="sol"> <img id="kitapfoto" src="img/s9PBDwAAQBAJ.jpg" /> </div>
<div id="orta">
<div id="kitapadi">Salgın</div>
<div id="yayinyili">Yayın yılı : 2013</div>
<div id="kitapturu">Tür : Zombi</div>
<div id="okuyucupuani">Okuyucu Puanı : 8.8/10</div>
<div id="benimpuanim">Benim Puanım : 6.8/10</div>
</div>
<div id="sag">Sağ </div>
</div>
</div>
This might be completely wrong but is this what you are after?
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
background-color: #444444;
font-family: Roboto, sans-serif;
font-size: 24px;
}
#hepsi {
background-color: #FC0;
width: auto;
height: auto;
}
#deneme {
display: flex;
justify-content: center;
width: 740px;
margin: auto;
}
#sol {
display: flex;
flex-grow: 1;
background-color: #666;
line-height: 0;
max-height: 273px;
}
#orta {
display: flex;
flex-grow: 1;
flex-direction: column;
background-color: #0C0;
}
#orta:hover #kitapadi{
order: 6;
margin-top: 150px;
}
#orta:hover #yayinyili{
margin-top: 34px;
}
#sag {
display: flex;
flex-grow: 1;
width: 300px;
background-color: #FF6;
max-height: 273px;
}
#kitapfoto {
width: 186px;
height: 273px;
}
#kitapadi {
position: relative;
width: auto;
height: auto;
text-align: center;
font-size: 30px;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
order: 1;
}
#yayinyili {
position: relative;
width: auto;
height: auto;
text-align: center;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
order: 2;
}
#kitapturu {
position: relative;
width: auto;
height: auto;
text-align: center;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
order: 3;
}
#okuyucupuani {
position: relative;
width: auto;
height: auto;
text-align: center;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
order: 4;
}
#benimpuanim {
position: relative;
width: auto;
height: auto;
text-align: center;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
order: 5;
}
<div id="hepsi">
<div id="deneme">
<div id="sol"> <img id="kitapfoto" src="img/s9PBDwAAQBAJ.jpg" /> </div>
<div id="orta">
<div id="kitapadi">Salgın</div>
<div id="yayinyili">Yayın yılı : 2013</div>
<div id="kitapturu">Tür : Zombi</div>
<div id="okuyucupuani">Okuyucu Puanı : 8.8/10</div>
<div id="benimpuanim">Benim Puanım : 6.8/10</div>
</div>
<div id="sag">Sağ </div>
</div>
</div>

Why a gap between ul li [duplicate]

This question already has answers here:
How to remove the space between inline/inline-block elements?
(41 answers)
Closed 6 years ago.
In the following code, I am not able to understand that why is there a small margin between the green li's Home , Products , Services , About Us, Contact
I have set the margin and padding to 0px in both .ul and .li properties. Then why is there a gap between the green li's?
*{
box-sizing:border-box;
}
html,body {
margin: 0px;
height: 100%;
width: 100%;
left: 0px;
top: 0px;
background-color: rgba(173,192,241,1);
}
.wrapper {
height: 725px;
max-width: 960px;
margin-left: auto;
left: 0px;
top: 0px;
/* [disabled]background-color: rgba(15,26,155,1); */
margin-right: auto;
position: relative;
}
.topimage {
width: 100%;
max-width: 960px;
height: 100%;
max-height: 175px;
/* [disabled]background-color: rgba(0,102,204,1); */
position: absolute;
/* [disabled]border: thin solid rgba(255,0,0,1); */
}
.topimage img{
max-width: 100%;
max-height: 100%;
/* [disabled]margin-bottom: -9px; */
display: block;
margin-right: auto;
margin-left: auto;
border-radius: 15px 15px 0px 0px;
}
.menu {
background-color: rgba(15,26,155,1);
height: 100%;
max-height: 50px;
max-width: 960px;
position: relative;
top: 175px;
}
.list {
color: rgba(0,0,0,1);
text-decoration: none;
margin-right: auto;
margin-left: auto;
background-color: rgba(255,0,0,1);
padding: 0px;
}
.list li {
display: inline-block;
margin-right: 0px;
margin-left: 0px;
width: auto;
text-align: center;
background-color: rgba(204,255,0,1);
position: relative;
padding: 0px;
}
.content {
width: 100%;
height: 500px;
background-color: rgba(20,35,214,1);
position: relative;
top: 175px;
padding-right: 0.5%;
padding-left: 0.5%;
}
.leftcontent {
background-color: rgba(210,238,252,1);
float: left;
height: 100%;
max-height: 500px;
width: 100%;
max-width: 85%;
top: 0px;
position: relative;
border-left-color: rgba(205,205,205,1);
/* [disabled]margin-left: 0.3%; */
}
.rightcontent {
background-color: rgba(51,177,236,1);
float: right;
height: 100%;
max-height: 500px;
width: 100%;
max-width: 15%;
position: relative;
top: 0px;
/* [disabled]margin-right: 0.3%; */
}
.footer {
}
<div class="wrapper">
<div class="topimage">
</div>
<div class="menu">
<ul class="list">
<li>Home</li>
<li>Products</li>
<li>Services</li>
<li>About Us</li>
<li>Contact</li>
</ul>
</div>
<div class="content">
<div class="leftcontent">
</div>
<div class="rightcontent">
</div>
</div>
</div>
If you have no new lines between the list elements then it works. So you could put all on one line (see snippet) or add font-size: 0; to the <ul>
ul {font-size:0;}
*{
box-sizing:border-box;
}
html,body {
margin: 0px;
height: 100%;
width: 100%;
left: 0px;
top: 0px;
background-color: rgba(173,192,241,1);
}
.wrapper {
height: 725px;
max-width: 960px;
margin-left: auto;
left: 0px;
top: 0px;
/* [disabled]background-color: rgba(15,26,155,1); */
margin-right: auto;
position: relative;
}
.topimage {
width: 100%;
max-width: 960px;
height: 100%;
max-height: 175px;
/* [disabled]background-color: rgba(0,102,204,1); */
position: absolute;
/* [disabled]border: thin solid rgba(255,0,0,1); */
}
.topimage img{
max-width: 100%;
max-height: 100%;
/* [disabled]margin-bottom: -9px; */
display: block;
margin-right: auto;
margin-left: auto;
border-radius: 15px 15px 0px 0px;
}
.menu {
background-color: rgba(15,26,155,1);
height: 100%;
max-height: 50px;
max-width: 960px;
position: relative;
top: 175px;
}
.list {
color: rgba(0,0,0,1);
text-decoration: none;
margin-right: auto;
margin-left: auto;
background-color: rgba(255,0,0,1);
padding: 0px;
}
.list li {
display: inline-block;
margin-right: 0px;
margin-left: 0px;
width: auto;
text-align: center;
background-color: rgba(204,255,0,1);
position: relative;
padding: 0px;
}
.content {
width: 100%;
height: 500px;
background-color: rgba(20,35,214,1);
position: relative;
top: 175px;
padding-right: 0.5%;
padding-left: 0.5%;
}
.leftcontent {
background-color: rgba(210,238,252,1);
float: left;
height: 100%;
max-height: 500px;
width: 100%;
max-width: 85%;
top: 0px;
position: relative;
border-left-color: rgba(205,205,205,1);
/* [disabled]margin-left: 0.3%; */
}
.rightcontent {
background-color: rgba(51,177,236,1);
float: right;
height: 100%;
max-height: 500px;
width: 100%;
max-width: 15%;
position: relative;
top: 0px;
/* [disabled]margin-right: 0.3%; */
}
.footer {
}
<div class="wrapper">
<div class="topimage">
</div>
<div class="menu">
<ul class="list">
<li>Home</li><li>Products</li><li>Services</li><li>About Us</li><li>Contact</li>
</ul>
</div>
<div class="content">
<div class="leftcontent">
</div>
<div class="rightcontent">
</div>
</div>
</div>
Try this -
.list li {
float: left;
list-style: none;
width: auto;
text-align: center;
background-color: rgba(204,255,0,1);
position: relative;
}
Replace with above css with your existing .list li class
You can remove space created by inline-block element as with following trick.
Or you can use float instead of inline-block.
.list {
letter-spacing: -4px;
font-size: 0;
}
.list li {
display: inline-block;
vertical-align: top;
letter-spacing: 0;
font-size: 14px;
}
Or you can use float:
.list {
overflow: hidden;
}
.list li {
float: left;
}
Just add this into your code,
.list{
font-size:0;
}
.list li{
font-size:20px;
padding:0px 0px 0px 10px;
}

Elements display in front of their container, but can't be interacted with

I'm currently working on a website and have encountered an interesting problem. I have a container which holds my navbar. For some reason, this container displays behind its contents (Which it should) but mouse interaction acts as if it's in front of its contents.
JSFiddle of my current code
https://jsfiddle.net/qzsxpgrq/
HTML
<div id="navbar">
<div id="bar">
<div id="navLeft">
<div class="navL navbutton">About</div>
<div class="navL navbutton">The Team</div>
</div>
<div id="navLogo">
<div id="logo">
<img src="http://www.epicyoobed.com/res/img/navLogo.png"/>
</div>
</div>
<div id="navRight">
<div class="navR navbutton">Programs</div>
<div class="navR navbutton">Contact</div>
</div>
</div>
</div>
CSS
html {
height: 100%;
font-family: arial;
}
body {
margin: 0;
padding: 0;
background-color: #BBB;
}
#navbar {
margin: 0;
padding: 0;
height: 80px;
width: 100%;
position: fixed;
display: block;
z-index: 1;
}
#bar {
display: block;
position: fixed;
width: 100%;
height: 40px;
background-image: url("http://www.epicyoobed.com/res/img/nav.png");
}
#navRight {
margin: 0;
padding: 0;
height: 40px;
width: 45%;
position: absolute;
display: block;
float: left;
top: 0;
right: 0;
}
#navbar div div a {
display: block;
text-decoration: none;
padding-top: 5px;
color: #000;
width: 100%;
height: 100%;
font-size: 20px;
}
.current {
background-image: url("http://www.epicyoobed.com/res/img/nav_sel.png");
background-repeat: repeat-x;
}
.navL {
float: right;
}
.navR {
float: left;
}
.navbutton {
display: block;
position: relative;
width: 150px;
height: 100%;
text-align: center;
}
.navbutton:hover {
background-image: url("http://www.epicyoobed.com/res/img/nav_sel.png");
background-repeat: repeat-x;
}
#navLogo {
margin: auto;
height: 40px;
width: 100%;
position: absolute;
display: block;
z-index: 2;
}
#logo {
margin: auto;
height: 80px;
width: 80px;
}
#navLeft {
margin: 0;
padding: 0;
height: 40px;
width: 45%;
position: absolute;
display: block;
float: right;
}
Xetanai Try adding a z-index of 3 to the #navLeft and navRight.
#navLeft {
margin: 0;
padding: 0;
height: 40px;
width: 45%;
position: absolute;
display: block;
float: right;
z-index:3;
}
#navRight {
margin: 0;
padding: 0;
height: 40px;
width: 45%;
position: absolute;
display: block;
float: left;
top: 0;
right: 0;
z-index:3;
}
The issue you're experiencing is because the logo is 100% width and has a z-index of 2. Effectively placing it above the left and right containers.

Keep divs from stacking when browser resized

So I have a website that when it is resized the divs start to stack. I have been unable to figure out why as I am using min-width on the container.
Here is how the divs are laid out:
<div id="content">
<div id="leftColumn">
</div>
<div="content">
</div>
</div>
Here is the CSS
#container {
position: absolute;
left: 0;
top: 0;
width: 99%;
min-width: 700px;
height: 100%;
background-color: #FFFFFF;
z-index: 0;
display: inline-block;
white-space: nowrap;
}
#leftColumn {
width: 20%;
min-width: 200px;
height: 100%;
background-color: #2196f3;
color: white;
text-align: center;
float: left;
font-size: 100%;
display: inline;
}
#content {
text-align: center;
left: 0%;
height: 100%;
width: 80%;
min-width: 498px;
background-color: white;
float: left;
display: inline;
}
Any help would be greatly appreciated.
Would you be opposed to using inline-block instead of floats? Like This:
HTML
<div id="container">
<div id="leftColumn">leftcolumn</div>
<div id="content">content</div>
</div>
CSS
#container {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: #FFFFFF;
z-index: 0;
display: inline-block;
white-space: nowrap;
}
#leftColumn {
min-width:200px;
height: 100%;
background-color: #2196f3;
color: white;
text-align: center;
display:inline-block;
font-size: 100%;
}
#content {
text-align: center;
min-width:200px;
width:80%;
height: 100%;
background-color: white;
display:inline-block;
}
Your wrote
<div="content"></div>
this. You missed ID declaration. It should be
<div id="content"></div>

Centering my logo over the custom header and right aligning my nav

If you are viewing it on JSFiddle you'll have to make the results window bigger to see what I am talking about. The logo should be right over top of the half circle and header and the nav should be centered in the header and right aligned.
Here is the fiddle - http://jsfiddle.net/sPEXp/1/
HTML
<div class="header">
<div class="container">
<img class="logo" src="img/onewaylogo.png">
<nav>
Home
About
Let's Partner
Contact
</nav>
</div>
</div>
CSS
.header {
position: fixed;
top: 0;
left: 0;
width: 100%;
background: #f6f6f6;
z-index: 10000;
height: 100px;
}
.header .container {
position: relative;
height: 100px;
width: 85%;
margin: 0 auto;
text-align: center;
}
.header:after {
content: '';
position: relative;
bottom: 0;
display: block;
margin: 0 auto;
background: #f6f6f6;
width: 150px;
height: 75px;
border-radius: 0 0 75px 75px;
}
.header .logo,
.header nav a {
line-height: 100px;
}
.header nav {
float: right;
position: relative;
width: 320px;
}
.logo {
position: relative;
top: 50px;
display: inline-block;
width: 150px;
height: 100px;
z-index: 100000;
margin: 0 auto;
}
.header nav a {
color: #aaa;
font-weight: 700;
margin: 0 0 0 20px;
font-size: .95em;
}
.header nav a:hover {
color: #333;
}
Fiddle Working
You can center elements by setting its width and position to absolute
In this case:
.logo {
position: absolute;
margin: 0 50%;
width: 150px;
left: -75px; // total width half (75px)
...
}