Make HTML table fit width of DIV - html

I'm trying to make a sidebar for my website that will contain a list of names, and I want to use HTML rows so I can set different background colors for even/odd rows. The issue I'm running into is making the HTML table fit the entire width of the sidebar div, without having any horizontal overflow. Ideally this will be responsive too. What am I doing wrong?
Codepin: https://codepen.io/dansbyt/pen/gOrozzV?editors=1100
CSS in question:
#sidebar {
z-index: 1;
position: fixed;
left: 0%;
top: 8%;
width: 20%;
height:100vh;
overflow-y: scroll;
background-color: #EBEDE9;
border-right: 2px solid darkgray}
tr {
display: block;
table-layout: fixed;
width: 100%;
padding: 10%;
text-align: center;
color: blue;
border-bottom: 1px solid darkgray}
tr:nth-child(even){background-color: #f2f2f2;}
tr:hover {background-color: #E2D0BE;}

You had to set width of table & tr as 100%
#sidebar {
z-index: 1;
position: fixed;
left: 0%;
top: 8%;
width: 20%;
height:100vh;
overflow-y: scroll;
background-color: #EBEDE9;
border-right: 2px solid darkgray}
table,tr{
width:100%
}
td {
width: 100%;
padding: 10%;
text-align: center;
color: blue;
border-bottom: 1px solid darkgray}
tr:nth-child(even){background-color: #f2f2f2;}
tr:hover {background-color: #E2D0BE;}
#content {
position: fixed;
left: 20%;
top: 8%;
width: 72%;
height:100vh;
padding: 4%;
overflow-y: scroll;
background-color: #F5F7F2;}
<div id="sidebar">
<table>
<tr><td>John Doe</td></tr>
<tr><td>Justin Bieber</td></tr>
<tr><td>Donald Trump</td></tr>
<tr><td>Shawn Mendes</td></tr>
<tr><td>Donald Duck</td></tr>
<tr><td>Micky Mouse</td></tr>
<tr><td>7</td></tr>
<tr><td>8</td></tr>
<tr><td>9</td></tr>
<tr><td>10</td></tr>
<tr><td>11</td></tr>
<tr><td>12</td></tr>
<tr><td>13</td></tr>
<tr><td>14</td></tr>
<tr><td>15</td></tr>
<tr><td>16</td></tr>
<tr><td>17</td></tr>
<tr><td>18</td></tr>
<tr><td>19</td></tr>
<tr><td>20</td></tr>
<tr><td>21</td></tr>
<tr><td>22</td></tr>
<tr><td>23</td></tr>
<tr><td>24</td></tr>
<tr><td>25</td></tr>
<tr><td>26</td></tr>
<tr><td>27</td></tr>
<tr><td>28</td></tr>
<tr><td>29</td></tr>
<tr><td>30</td></tr>
<tr><td>31</td></tr>
<tr><td>32</td></tr>
<tr><td>33</td></tr>
<tr><td>34</td></tr>
<tr><td>35</td></tr>
<tr><td>36</td></tr>
<tr><td>37</td></tr>
<tr><td>38</td></tr>
<tr><td>39</td></tr>
<tr><td>40</td></tr>
<tr><td>41</td></tr>
<tr><td>42</td></tr>
<br><br><br><br>
</table>
</div>
<div id="content">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Sed viverra ipsum nunc aliquet bibendum. Mauris pharetra et ultrices neque ornare aenean. Luctus venenatis lectus magna fringilla urna porttitor rhoncus. Odio ut sem nulla pharetra. Sed egestas egestas fringilla phasellus faucibus scelerisque eleifend donec. Est ullamcorper eget nulla facilisi etiam dignissim. Elit ut aliquam purus sit. Sed vulputate odio ut enim blandit volutpat. Leo integer malesuada nunc vel. Urna porttitor rhoncus dolor purus non enim praesent. Ipsum nunc aliquet bibendum enim facilisis gravida neque. Morbi leo urna molestie at elementum. Et magnis dis parturient montes nascetur ridiculus mus. Nec ultrices dui sapien eget mi. Massa massa ultricies mi quis hendrerit dolor magna. Cursus vitae congue mauris rhoncus aenean vel elit. Et malesuada fames ac turpis egestas maecenas. At volutpat diam ut venenatis tellus. Feugiat scelerisque varius morbi enim nunc faucibus. Et netus et malesuada fames ac. Morbi quis commodo odio aenean. Sed vulputate mi sit amet. Sed lectus vestibulum mattis ullamcorper velit sed. Ornare suspendisse sed nisi lacus sed viverra. Fermentum iaculis eu non diam phasellus vestibulum. Laoreet non curabitur gravida arcu ac tortor dignissim convallis aenean. Facilisi etiam dignissim diam quis enim lobortis scelerisque fermentum dui. Tortor at risus viverra adipiscing at in tellus integer feugiat. Faucibus purus in massa tempor nec feugiat nisl. Molestie a iaculis at erat pellentesque adipiscing commodo. In nibh mauris cursus mattis molestie a iaculis at erat. Faucibus ornare suspendisse sed nisi lacus sed viverra tellus. Aliquet sagittis id consectetur purus ut faucibus pulvinar elementum. Egestas fringilla phasellus faucibus scelerisque eleifend. Tortor consequat id porta nibh venenatis cras sed felis. Eu volutpat odio facilisis mauris sit. Ac placerat vestibulum lectus mauris ultrices. Eu feugiat pretium nibh ipsum consequat nisl vel. Id cursus metus aliquam eleifend. Amet purus gravida quis blandit. Lacus vel facilisis volutpat est velit egestas dui id ornare. Sapien faucibus et molestie ac feugiat sed lectus vestibulum mattis. Maecenas accumsan lacus vel facilisis volutpat est. Phasellus vestibulum lorem sed risus ultricies tristique. Tincidunt vitae semper quis lectus nulla at volutpat. Praesent tristique magna sit amet. Amet est placerat in egestas erat imperdiet sed euismod. Eget mi proin sed libero enim sed faucibus turpis in. Ac odio tempor orci dapibus ultrices in. Diam maecenas sed enim ut sem. Velit egestas dui id ornare arcu odio ut. Morbi tristique senectus et netus. Morbi tristique senectus et netus et malesuada fames ac. Nullam non nisi est sit amet facilisis. Egestas erat imperdiet sed euismod nisi porta. Egestas pretium aenean pharetra magna ac placerat. Augue neque gravida in fermentum et. Tortor pretium viverra suspendisse potenti nullam ac tortor vitae. Quisque sagittis purus sit amet volutpat consequat mauris nunc congue. Pharetra pharetra massa massa ultricies mi quis hendrerit dolor magna. Nisi vitae suscipit tellus mauris a diam maecenas sed enim. Lacus laoreet non curabitur gravida arcu ac tortor dignissim. Tristique nulla aliquet enim tortor at auctor. Nibh ipsum consequat nisl vel pretium lectus quam id leo. Egestas erat imperdiet sed euismod nisi porta lorem mollis aliquam. Dui ut ornare lectus sit. Dui ut ornare lectus sit amet est. Urna duis convallis convallis tellus. Nunc consequat interdum varius sit amet. Lacus laoreet non curabitur gravida.
</div>

The table is inheriting the sidebar width, so you need to specify the width of table element as 100%.
#sidebar {
table {
width:100%;
}
}

#sidebar {
z-index: 1;
position: fixed;
left: 0%;
top: 8%;
width: 20%;
height:100vh;
overflow-y: scroll;
background-color: #EBEDE9;
border-right: 2px solid darkgray}
#sidebar * {
box-sizing: border-box;
}
#sidebar > table {
width: 100%;
}
#sidebar > table tr td {
text-align: center;
display: inline-block;
}
tr {
display: block;
width: 100%;
padding: 15px;
color: blue;
text-align: center;
border-bottom: 1px solid darkgray}
tr:nth-child(even){background-color: #f2f2f2;}
tr:hover {background-color: #E2D0BE;}
#content {
position: fixed;
left: 20%;
top: 8%;
width: 72%;
height:100vh;
padding: 4%;
overflow-y: scroll;
background-color: #F5F7F2;}
You didn't set the border-box.
you added padding 10%. it's already overflow without box-sizing.
please see #sidebar * selector.

You have not set the table element to 100% width
table {
width:100%;
}
Full code:
#sidebar {
z-index: 1;
position: fixed;
left: 0%;
top: 8%;
width: 20%;
height:100vh;
overflow-y: scroll;
background-color: #EBEDE9;
border-right: 2px solid darkgray}
table {
width:100%;
}
tr {
display: block;
table-layout: fixed;
width: 100%;
padding: 10%;
text-align: center;
color: blue;
border-bottom: 1px solid darkgray}
tr:nth-child(even){background-color: #f2f2f2;}
tr:hover {background-color: #E2D0BE;}
#content {
position: fixed;
left: 20%;
top: 8%;
width: 72%;
height:100vh;
padding: 4%;
overflow-y: scroll;
background-color: #F5F7F2;}

Related

Making outer columns of flexbox sticky

I have content on page and I would like to make both sidebars to be sticky, something like:
I am using flex:
<div className="homePageFeed">
<div className="homePageFeedWrapper">
<HomePageFeedMenu/>
<HomePageFeedContent/>
<HomePageFeedUtil/>
</div>
</div>
.homePageFeed{
position: relative;
width: 100%;
}
.homePageFeedWrapper{
display: flex;
align-items: center;
position: relative;
height: 100%;
padding-left: 22px;
padding-right: 16px;
z-index: 30;
flex-direction: row;
}
Other components, left-sidebar:
const HomePageFeedMenu = () => {
return (
<div className="homeFeedMenu">
<ol>
<li> Mammals</li>
<li> Lizards</li>
<li> Birds</li>
<li> Spiders</li>
</ol>
</div>
)
}
export default HomePageFeedMenu;
.homeFeedMenu{
flex: 10 0 0;
width: 100%;
height: 500px;
border-right: 1px solid hsl(210,8%,35%);
}
ol{
list-style: none;
}
li{
color: hsl(210,8%,35%);
margin: 0;
}
Scrollable content ( with test item in it ):
const HomePageFeedContent = () => {
return (
<div className="homeFeedContent">
<div className="homeFeedItem">
<div className="content">
<div className="homeFeedItemTitle"><p>Animal name</p></div>
<div className="homeFeedItemContent">
Animal description
</div>
<div className="homeFeedItemMetaInfo">Age and adoption info</div>
</div>
<div className="img">Animal picture</div>
</div>
</div>
)
}
.homeFeedContent{
padding-top: 25px;
flex: 70 0 0;
width: 100%;
border-right: 1px solid hsl(210,8%,35%);
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
}
.homeFeedItem{
width: 90%;
height: 200px;
display: flex;
margin-top:25px;
flex-direction: row;
justify-content: center;
border-bottom: 1px solid hsl(210,8%,35%);;
}
.content{
flex: 80 80 0;
display: flex;
flex-direction: column;
}
.img{
flex: 20 20 0;
width: 100%;
height: 100%;
border: 1px solid black;
}
.homeFeedItemTitle{
width: 100%;
flex: 20 20 0;
}
.homeFeedItemContent{
width: 100%;
flex: 60 60 0;
border-bottom: 1px hsl(210,8%,35%);;
}
.homeFeedItemMetaInfo{
width: 100%;
flex: 20 20 0;
}
export default HomePageFeedContent;
And right static sidebar
const HomePageFeedUtil = () => {
return (
<div className="homeFeedUtil">
</div>
)
}
export default HomePageFeedUtil;
.homeFeedUtil{
flex: 20 0 0;
width: 100%;
height: 500px;
}
Now I am trying to use sticky positioning for both sidebars, however, it does not work as they are part of the flexbox. I would also like to fix their height, as you can see I attempted to use 500px, hover when the middle flex element gets lots of element and the site become scrollable, it readjusts the position of both sidebars ( as they have fixed height ) and thus their content does not appear on top of it "column".
Are there any tricks to use both, flex and sticky positioning? Or do I need to do it without flex?
Thanks for the help!
I'd not use flexbox. I'd use position: sticky for the top then position: fixed for each sidebar. Use css variables to work out the width of the scrollable area. Here's an example:
body {
box-sizing: border-box;
margin: 0;
}
.main-container {
--header-height: 50px;
--header-gap: 0.5rem;
--sidebar1-width: 200px;
--sidebar2-width: 100px;
--sidebar-gap: 0.5rem;
}
.sticky-header {
position: sticky;
height: var(--header-height);
background-color: lightblue;
border: 1px solid blue;
top: 0;
z-index: 1;
}
.sticky-sidebar1 {
position: fixed;
top: var(--header-height);
left: 0;
width: var(--sidebar1-width);
height: calc(100vh - var(--header-height));
background-color: lightgreen;
border: 1px solid darkgreen;
}
.sticky-sidebar2 {
position: fixed;
top: var(--header-height);
right: 0;
width: var(--sidebar2-width);
height: calc(100vh - var(--header-height));
background-color: lightpink;
border: 1px solid darkred;
}
.scrollable-content {
border: 1px solid red;
padding: 0.25rem;
overflow: hidden;
margin-left: calc(var(--sidebar1-width) + var(--sidebar-gap));
margin-right: calc(var(--sidebar2-width) + var(--sidebar-gap));
margin-top: var(--header-gap);
}
#media only screen and (max-width: 600px) {
.main-container {
--sidebar1-width: 100px;
--sidebar2-width: 0px;
}
}
<div class='main-container'>
<div class="sticky-header">Sticky Header</div>
<div class="sticky-sidebar1">Sticky Sidebar1</div>
<div class="sticky-sidebar2">Sticky Sidebar2</div>
<div class="scrollable-content">
<h1>Scrollable Content</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua. In eu mi bibendum neque egestas congue quisque egestas. Adipiscing enim eu turpis egestas
pretium.
Accumsan sit amet nulla facilisi morbi tempus iaculis urna id. In massa tempor nec feugiat nisl. Mattis nunc
sed
blandit libero volutpat sed. Magna ac placerat vestibulum lectus mauris ultrices eros in. Senectus et netus et
malesuada fames ac turpis egestas. Tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada. Vel elit
scelerisque mauris pellentesque pulvinar. Egestas egestas fringilla phasellus faucibus scelerisque eleifend
donec pretium. Tristique risus nec feugiat in fermentum posuere urna nec tincidunt. Lectus vestibulum mattis
ullamcorper velit sed. Risus ultricies tristique nulla aliquet enim tortor at auctor. Vitae congue mauris
rhoncus aenean vel elit scelerisque mauris pellentesque. Lacus suspendisse faucibus interdum posuere lorem
ipsum
dolor. Suspendisse interdum consectetur libero id. Vestibulum lorem sed risus ultricies tristique nulla
aliquet.
Nunc eget lorem dolor sed viverra ipsum nunc. Diam sit amet nisl suscipit adipiscing bibendum est.
Diam phasellus vestibulum lorem sed risus ultricies tristique. Ultrices sagittis orci a scelerisque. Iaculis
at
erat pellentesque adipiscing commodo elit at imperdiet dui. Donec enim diam vulputate ut pharetra sit.
Fringilla
urna porttitor rhoncus dolor purus. Turpis massa tincidunt dui ut ornare lectus. Et netus et malesuada fames
ac
turpis egestas maecenas pharetra. Malesuada nunc vel risus commodo viverra maecenas. Purus sit amet volutpat
consequat mauris nunc. Vel fringilla est ullamcorper eget nulla. Duis ultricies lacus sed turpis tincidunt id
aliquet risus. Arcu ac tortor dignissim convallis aenean et. Elementum nibh tellus molestie nunc non blandit
massa.
Magna sit amet purus gravida quis. Amet tellus cras adipiscing enim eu turpis egestas pretium aenean. Sagittis
nisl rhoncus mattis rhoncus urna neque. Feugiat scelerisque varius morbi enim nunc faucibus. Parturient montes
nascetur ridiculus mus mauris vitae ultricies leo. Enim nulla aliquet porttitor lacus luctus accumsan tortor
posuere. Rhoncus aenean vel elit scelerisque mauris pellentesque. Velit aliquet sagittis id consectetur purus.
Id porta nibh venenatis cras sed felis eget velit aliquet. Mattis nunc sed blandit libero. Suspendisse in est
ante in. Duis at tellus at urna condimentum mattis. Consequat semper viverra nam libero justo laoreet sit amet
cursus.
Sed turpis tincidunt id aliquet risus feugiat. Aliquam purus sit amet luctus. Suspendisse faucibus interdum
posuere lorem. Cursus turpis massa tincidunt dui ut ornare. Donec ultrices tincidunt arcu non sodales. Tellus
integer feugiat scelerisque varius morbi enim nunc faucibus. Leo integer malesuada nunc vel risus. Ut pharetra
sit amet aliquam id diam. Condimentum vitae sapien pellentesque habitant morbi tristique. Vestibulum lectus
mauris ultrices eros. Aenean sed adipiscing diam donec adipiscing tristique risus. Nulla aliquet porttitor
lacus
luctus accumsan tortor. Semper feugiat nibh sed pulvinar. Placerat in egestas erat imperdiet sed.
Pulvinar pellentesque habitant morbi tristique senectus et netus. Vitae turpis massa sed elementum tempus
egestas sed. Aliquam sem et tortor consequat id porta nibh venenatis cras. Orci dapibus ultrices in iaculis
nunc
sed augue lacus. Blandit turpis cursus in hac habitasse platea. Volutpat blandit aliquam etiam erat velit
scelerisque. Massa ultricies mi quis hendrerit dolor magna eget est lorem. Lectus sit amet est placerat. Eu mi
bibendum neque egestas congue. Dictum non consectetur a erat nam at. Facilisis magna etiam tempor orci eu
lobortis. Sit amet venenatis urna cursus eget nunc. Sed risus pretium quam vulputate dignissim suspendisse.
Vivamus at augue eget arcu dictum. Ultricies tristique nulla aliquet enim tortor. Gravida neque convallis a
cras
semper auctor neque.
Malesuada pellentesque elit eget gravida cum sociis natoque penatibus. Est lorem ipsum dolor sit amet. Tempor
orci dapibus ultrices in iaculis nunc. Lorem ipsum dolor sit amet consectetur adipiscing. Volutpat diam ut
venenatis tellus in metus vulputate eu. Sed nisi lacus sed viverra tellus. Penatibus et magnis dis parturient.
Ipsum consequat nisl vel pretium lectus quam. Mollis aliquam ut porttitor leo a diam. Cras sed felis eget
velit.
Euismod lacinia at quis risus. Neque viverra justo nec ultrices dui. Pellentesque habitant morbi tristique
senectus et netus et. Pharetra vel turpis nunc eget lorem dolor. Ac auctor augue mauris augue neque gravida
in.
</p>
</div>
</div>
For the result you are looking for you would need to use position: fixed; in your css for all 3 elements you want to be fixed;
For your top header it would be something like:
#enterIDhere {
position: fixed;
top: 0;
left: 0;
right: 0;
width: 100%;
margin: 0 auto;
}
For your left sidebar it would be something like:
#EnterIDhere {
position: fixed;
left: 0;
bottom: 0;
}
and last but not least your right sidebar would need something like:
#EnterIDhere {
position: fixed;
right: 0;
bottom: 0;
}

How do I position a <img> in-between two <ul> in a navigation bar?

I'm trying to create a navigation bar at the top the page, with the logo in the centre and a list either side. Each list containing three links to pages in the site.
For some reason, the logo doesn't scroll with the page, but .nav, #left and #right do scroll normally.
The page is live here:
afsmma.com
Here's the code:
.nav {
margin: auto;
height: 60px;
width: 100%;
max-width: 900px;
background: #efefef;
font-family: 'Assistant' , sans-serif;
font-weight: 700;
}
#left {
margin: 0;
padding-top: 17px;
padding-left: 20px;
float: left;
list-style: none;
}
#left li {
display: inline-block;
padding-right: 15px;
font-size: 12pt;
}
.afs {
position: absolute;
text-align: center;
width: 100%;
max-width: 900px;
}
.afs img {
margin: 5px auto 0px auto;
height: 50px;
}
#right {
float: right;
margin: 0;
padding-top: 17px;
padding-right: 20px;
list-style: none;
}
#right li {
display: inline-block;
padding-left: 15px;
font-size: 12pt;
}
.hero {
height: 100%;
background: url(/images/ph.jpg) 50% 50% no-repeat;
background-size: cover;
}
<div class="nav">
<ul id="left">
<li>HOME</li>
<li>EVENTS</li>
<li>TICKETS</li>
</ul>
<div class="afs">
<img src="images/LogoCyan.svg">
</div>
<ul id="right">
<li>SHOP</li>
<li>GALLERY</li>
<li>CONTACT</li>
</ul>
</div>
<div class="hero"></div>
A bit of Flex will solve it easily and very cleanly.
Avoid position:absolute and use flex,
DEMO : https://jsfiddle.net/vikas_saini/v6uxh3sc/1/
CSS:
.nav {
margin: auto;
height: 60px;
width: 100%;
max-width: 900px;
background: #efefef;
display:flex;
justify-content: space-between;
font-family: 'Assistant' , sans-serif;
font-weight: 700;
}
#left {
margin: 0;
display:flex;
padding-top: 17px;
padding-left: 20px;
float: left;
list-style: none;
}
#left li {
display: inline-block;
padding-right: 15px;
font-size: 12pt;
}
.afs {
flex-grow: 1;
text-align: center;
width: 100%;
max-width: 900px;
}
.afs img {
margin: 5px auto 0px auto;
height: 50px;
}
#right {
display:flex;
float: right;
margin: 0;
padding-top: 17px;
padding-right: 20px;
list-style: none;
}
#right li {
display: inline-block;
padding-left: 15px;
font-size: 12pt;
}
.hero {
height: 200vh;
background: url(/images/ph.jpg) 50% 50% no-repeat;
background-size: cover;
}
HTML:
<div class="nav">
<ul id="left">
<li>HOME</li>
<li>EVENTS</li>
<li>TICKETS</li>
</ul>
<div class="afs">
<div class="image-container">
<img src="images/LogoCyan.svg">
</div>
</div>
<ul id="right">
<li>SHOP</li>
<li>GALLERY</li>
<li>CONTACT</li>
</ul>
</div>
<div class="hero"></div>
Try position: fixed; or position: absolute; in the .nav class and position: absolute to the .hero class
Try to align your items with flex:
.nav {
margin: auto;
height: 60px;
width: 100%;
max-width: 900px;
background: #efefef;
font-family: 'Assistant' , sans-serif;
font-weight: 700;
display: flex;
justify-content: space-between;
}
#left {
margin: 0;
padding-top: 17px;
padding-left: 20px;
list-style: none;
display: flex;
}
#left li {
display: inline-block;
padding-right: 15px;
font-size: 12pt;
}
.afs {
text-align: center;
width: 100%;
max-width: 900px;
}
.afs img {
margin: 5px auto 0px auto;
height: 50px;
}
#right {
margin: 0;
padding-top: 17px;
padding-right: 20px;
list-style: none;
display: flex;
}
#right li {
display: inline-block;
padding-left: 15px;
font-size: 12pt;
}
.hero {
height: 100%;
background: url(/images/ph.jpg) 50% 50% no-repeat;
background-size: cover;
}
Using flex, you can create some surrounding divs for your ul menus, and specify the widths of each div container to show the menus and logo inline. As for the hero image, moving that after open <body>, you can specify a position of fixed with a z-index of -1 to move it behind the menu. Please see the JSFiddle that shows the new CSS with the actual images from your site.
https://jsfiddle.net/4Lk1ygsp/
.nav {
margin: auto;
height: 60px;
width: 100%;
max-width: 900px;
background: #efefef;
font-family: 'Assistant', sans-serif;
font-weight: 700;
}
#nav-left {
position: relative;
float: left;
width: 300px;
display: inline-flex;
}
#left {
margin: 0;
padding-top: 17px;
padding-left: 20px;
float: left;
list-style: none;
}
#left li {
display: inline-block;
padding-right: 15px;
font-size: 12pt;
}
.afs {
position: absolute;
text-align: center;
width: 100%;
max-width: 900px;
}
.afs img {
margin: 5px auto 0px auto;
height: 50px;
}
#nav-right {
position: relative;
float: right;
width: 300px;
display: inline-flex;
}
#right {
float: right;
margin: 0;
padding-top: 17px;
padding-right: 20px;
list-style: none;
}
#right li {
display: inline-block;
padding-left: 15px;
font-size: 12pt;
}
.hero {
height: 100%;
background: url(http://afsmma.com/images/ph.jpg) 50% 50% no-repeat;
background-size: cover;
position: fixed;
width: 100%;
z-index: -1;
}
#body-container {
width: 900px;
margin: 0px auto;
color: #fff;
}
<!DOCTYPE html>
<html>
<body>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ambition Fight Series</title>
<link href="css/styles.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Assistant:400,700&display=swap" rel="stylesheet">
</head>
<body>
<div class="hero"></div>
<div class="nav">
<div id="nav-left">
<ul id="left">
<li>HOME</li>
<li>EVENTS</li>
<li>TICKETS</li>
</ul>
</div>
<div class="afs">
<img src="http://afsmma.com/images/LogoCyan.svg">
</div>
<div id="nav-right">
<ul id="right">
<li>SHOP</li>
<li>GALLERY</li>
<li>CONTACT</li>
</ul>
</div>
</div>
<div id="body-container">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ullamcorper volutpat nunc vehicula tincidunt. Phasellus vel urna id mi aliquam consequat non eget eros. Fusce rutrum lorem nunc, eu ultricies justo tempor sit amet. Orci varius natoque penatibus
et magnis dis parturient montes, nascetur ridiculus mus. Mauris ante velit, eleifend non nulla et, mollis blandit purus. Curabitur vehicula orci vel ultricies pretium. Donec cursus suscipit arcu, eget dignissim eros scelerisque at. Mauris a blandit
libero. Quisque quis vehicula orci, id dapibus ipsum. Maecenas urna purus, mattis et sollicitudin eget, ullamcorper quis enim. Maecenas sagittis mi vitae justo feugiat pretium. In quis elementum sapien. Integer consequat mi vitae nisl vulputate
feugiat. Curabitur rhoncus, lorem at fermentum sagittis, tellus metus sagittis metus, et ullamcorper massa mi sit amet metus. Mauris nec dictum orci, eu pellentesque mi. Proin maximus et lacus eget vestibulum.
</p>
<p>
In tempor erat nec tristique cursus. Quisque eleifend placerat lacinia. Suspendisse lectus nibh, congue non auctor non, lacinia et erat. Donec pellentesque mi ac sapien luctus, luctus laoreet quam ullamcorper. Donec consequat est neque, id elementum libero
iaculis sit amet. Fusce imperdiet in erat in imperdiet. Cras ullamcorper elit vel nisl efficitur ultricies. Suspendisse potenti. Quisque eu porta erat, a mattis turpis. Quisque aliquam nunc quis felis consectetur, ut interdum tortor sagittis.
Suspendisse posuere ipsum ut ipsum sagittis viverra. Vestibulum feugiat, turpis ut vehicula dignissim, ipsum lectus efficitur magna, facilisis condimentum mi nulla sed mi. Nullam nunc dui, elementum et tellus nec, facilisis convallis libero. Mauris
facilisis, magna ut vestibulum ornare, elit massa pellentesque arcu, sed laoreet nisi erat quis dolor.
</p>
<p>
Donec ut imperdiet nisi. Nullam molestie convallis erat convallis accumsan. Suspendisse in lectus ac orci aliquet consequat. Praesent eleifend, nisl quis vulputate mollis, dui erat dignissim tortor, non mattis felis enim quis magna. Fusce posuere ante
ac orci rutrum, ut varius lectus gravida. Curabitur tristique volutpat sodales. Fusce lobortis volutpat pretium. Integer luctus purus eu neque blandit, id rhoncus diam consectetur. Donec placerat sapien vel augue semper, consequat consequat eros
dictum. Fusce sagittis, nibh at scelerisque finibus, lorem purus aliquam dolor, at finibus quam dui ut dolor.
</p>
<p>
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur vehicula iaculis volutpat. Nullam nibh mi, dapibus a nisl facilisis, consectetur gravida elit. Donec tempus tristique massa semper elementum. Nam mauris
massa, aliquam in dolor ut, porttitor cursus erat. Cras pretium egestas ipsum quis ornare. Nunc sit amet ornare odio.
</p>
<p>
Mauris molestie enim vitae magna venenatis fringilla. Nullam nisi dui, eleifend et erat a, sollicitudin fringilla risus. Integer molestie purus id urna tristique volutpat. Duis interdum pharetra arcu vitae consectetur. Nunc at suscipit quam. Nunc sit
amet gravida risus, malesuada eleifend libero. Aenean quis nibh libero. Morbi ut sapien nec erat sodales tempor at in magna. Etiam pretium velit mi, quis auctor sapien fringilla sit amet. Maecenas ornare, sapien et posuere tempor, nunc justo tempus
odio, ac sodales ipsum lacus quis nisi. Suspendisse viverra turpis at nibh blandit, id sollicitudin purus fermentum.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ullamcorper volutpat nunc vehicula tincidunt. Phasellus vel urna id mi aliquam consequat non eget eros. Fusce rutrum lorem nunc, eu ultricies justo tempor sit amet. Orci varius natoque penatibus
et magnis dis parturient montes, nascetur ridiculus mus. Mauris ante velit, eleifend non nulla et, mollis blandit purus. Curabitur vehicula orci vel ultricies pretium. Donec cursus suscipit arcu, eget dignissim eros scelerisque at. Mauris a blandit
libero. Quisque quis vehicula orci, id dapibus ipsum. Maecenas urna purus, mattis et sollicitudin eget, ullamcorper quis enim. Maecenas sagittis mi vitae justo feugiat pretium. In quis elementum sapien. Integer consequat mi vitae nisl vulputate
feugiat. Curabitur rhoncus, lorem at fermentum sagittis, tellus metus sagittis metus, et ullamcorper massa mi sit amet metus. Mauris nec dictum orci, eu pellentesque mi. Proin maximus et lacus eget vestibulum.
</p>
<p>
In tempor erat nec tristique cursus. Quisque eleifend placerat lacinia. Suspendisse lectus nibh, congue non auctor non, lacinia et erat. Donec pellentesque mi ac sapien luctus, luctus laoreet quam ullamcorper. Donec consequat est neque, id elementum libero
iaculis sit amet. Fusce imperdiet in erat in imperdiet. Cras ullamcorper elit vel nisl efficitur ultricies. Suspendisse potenti. Quisque eu porta erat, a mattis turpis. Quisque aliquam nunc quis felis consectetur, ut interdum tortor sagittis.
Suspendisse posuere ipsum ut ipsum sagittis viverra. Vestibulum feugiat, turpis ut vehicula dignissim, ipsum lectus efficitur magna, facilisis condimentum mi nulla sed mi. Nullam nunc dui, elementum et tellus nec, facilisis convallis libero. Mauris
facilisis, magna ut vestibulum ornare, elit massa pellentesque arcu, sed laoreet nisi erat quis dolor.
</p>
<p>
Donec ut imperdiet nisi. Nullam molestie convallis erat convallis accumsan. Suspendisse in lectus ac orci aliquet consequat. Praesent eleifend, nisl quis vulputate mollis, dui erat dignissim tortor, non mattis felis enim quis magna. Fusce posuere ante
ac orci rutrum, ut varius lectus gravida. Curabitur tristique volutpat sodales. Fusce lobortis volutpat pretium. Integer luctus purus eu neque blandit, id rhoncus diam consectetur. Donec placerat sapien vel augue semper, consequat consequat eros
dictum. Fusce sagittis, nibh at scelerisque finibus, lorem purus aliquam dolor, at finibus quam dui ut dolor.
</p>
<p>
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur vehicula iaculis volutpat. Nullam nibh mi, dapibus a nisl facilisis, consectetur gravida elit. Donec tempus tristique massa semper elementum. Nam mauris
massa, aliquam in dolor ut, porttitor cursus erat. Cras pretium egestas ipsum quis ornare. Nunc sit amet ornare odio.
</p>
<p>
Mauris molestie enim vitae magna venenatis fringilla. Nullam nisi dui, eleifend et erat a, sollicitudin fringilla risus. Integer molestie purus id urna tristique volutpat. Duis interdum pharetra arcu vitae consectetur. Nunc at suscipit quam. Nunc sit
amet gravida risus, malesuada eleifend libero. Aenean quis nibh libero. Morbi ut sapien nec erat sodales tempor at in magna. Etiam pretium velit mi, quis auctor sapien fringilla sit amet. Maecenas ornare, sapien et posuere tempor, nunc justo tempus
odio, ac sodales ipsum lacus quis nisi. Suspendisse viverra turpis at nibh blandit, id sollicitudin purus fermentum.
</p>
</div>
</body>
</html>

Make text appear entirely inside div

I'm trying to have my text inside the 'container' div show up entirely but it seems to get cut off? .. It works if there is only a bit of text but if the text is more than 1 page it will cut it off.. Also the page seems to load very long because of the background image (defined in stylesheet.css) How do I fix this the best ? Thanks in advance!
* {
box-sizing: border-box;
}
#font-face {
font-family: 'zcool';
src: url('fonts/zcool.ttf') format('ttf');
local: url('fonts/zcool.ttf') format('ttf');
font-weight: normal;
font-style: normal;
}
html,
body {
height: 100%;
width: 100%;
}
body {
padding: 0;
margin: 0;
border: 0;
background-attachment: fixed;
background-size: 100% auto;
background-image: url("img/bg.png");
background-repeat: no-repeat;
background-size: 100% 100%;
}
#media (max-width: 768px) { /* when screen size is < 768px apply the following styles */
body {
padding: 0;
margin: 0;
border: 0;
background-attachment: fixed;
background-size: 100% auto;
background-image: url("img/bgm.png");
background-repeat: no-repeat;
background-size: 100% 100%;
}
}
ul#horizontal-list {
list-style: none;
}
ul#horizontal-list li {
display: inline;
}
ul {
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: center;
}
li a {
display: block;
color: white;
text-align: center;
padding: 16px;
text-decoration: none;
}
li a:hover {
background-color: red;
}
.navbar {
position: fixed;
top: 0;
height: 50px;
width: 100%;
background-color: black;
color: white;
text-align: center;
left: 0;
right: 0;
z-index: 1;
}
.navbar ul {
display: flex;
align-items: center;
justify-content: center;
list-style-type: none;
margin-top: 0px;
}
.header {
background-image: url(img/j.svg);
background-repeat: no-repeat;
background-size: 100% 100%;
height: 100%;
width: 100%;
margin-top: 10%;
margin-bottom: 10%;
}
#media (max-width: 768px) { /* when screen size is < 768px apply the following styles */
.header {
background-image: url("img/johnswork-mobile.svg");
background-repeat: no-repeat;
background-size: 100% 100%;
height: 100%;
width: 100%;
margin-top: 10%;
margin-bottom: 10%;
}
}
.body {
height: 100%;
width: 90%;
margin: auto;
padding: 0;
border: 0;
color: black;
padding-left: 5%;
padding-right: 5%;
overflow: hidden;
/*background-color: grey;*/
}
.johnswork {
background-image: url(img/johnswork.svg);
background-repeat: no-repeat;
background-size: 100% 100%;
height: 20%;
width: 100%;
margin-bottom: 5%;
}
.content {
margin: auto;
height: 100%;
width: 90%;
background-color: white;
color: black;
border-right: double;
border-left: double;
box-shadow: 0px -21px 28px 7px rgb(162, 27, 27);
text-align: justify;
font-size: 20px;
padding-top: 2%;
padding-bottom: 10%;
padding-left: 5%;
padding-right: 5%;
}
#media (max-width: 768px) { /* when screen size is < 768px apply the following styles */
.content {
margin: auto;
height: 100%;
width: 90%;
background-color: white;
color: black;
border-right: double;
border-left: double;
box-shadow: 0px -21px 28px 7px rgb(27, 125, 162);
text-align: justify;
font-size: 20px;
padding-top: 2%;
padding-bottom: 10%;
padding-left: 5%;
padding-right: 5%;
}
}
.social {
margin: auto;
display: flex;
justify-content: center;
}
.me {
float: left;
margin-right: 3%;
height: 100%;
}
.footer {
height: 50px;
width: 72%;
background-color: black;
color: white;
vertical-align: middle;
margin: auto auto 50px;
}
#copyright {
display: table;
}
#cpy{
display: table-cell;
vertical-align: middle;
}
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="stylesheet.css"/>
<!--<link rel="stylesheet" type="text/css" href="stylesheet-m.css" media="handheld" />-->
<link rel="icon" type="image/x-icon" href="img/favicon.ico"/>
<meta name="description" content="My Personal Portfolio">
<title>John's Work</title>
</head>
<body>
<nav class="navbar">
<ul>
<li>HOME</li>
<li>ABOUT</li>
<li>CONTACT</li>
</ul>
</nav>
<header class="header">
<!-- background defined in stylesheet.css-->
</header>
<section class="body">
<section class="content">
<section class="johnswork">
<!-- background defined in stylesheet.css-->
</section>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ac ipsum non diam faucibus dignissim. Praesent a dolor tincidunt, rutrum diam ut, convallis orci. Maecenas eleifend, sapien id blandit rutrum, enim augue cursus magna, vitae varius orci nulla eu arcu. Cras ultrices condimentum libero nec vulputate. Praesent id ante dignissim, congue elit id, iaculis eros. Aliquam lacus quam, facilisis et pulvinar quis, hendrerit varius erat. Duis feugiat imperdiet lobortis. Ut et faucibus dui. Integer quis bibendum tortor, at mattis dolor. Sed id lacus nec nisi iaculis blandit. Duis nec ligula orci. Quisque tincidunt, orci id tincidunt consequat, eros erat dictum urna, vel ultricies sem nisl eu nunc. Nulla facilisi. Suspendisse at malesuada magna, in suscipit purus.
Fusce facilisis pharetra dui, ut cursus orci maximus non. Cras nec magna ac odio ornare ornare. Proin id commodo eros. Phasellus dui est, malesuada non mi sit amet, fringilla rhoncus ante. Phasellus non elit id est cursus malesuada. Maecenas accumsan erat in urna pulvinar, sit amet egestas felis facilisis. Nullam tincidunt porta nulla, a consectetur sapien venenatis in. Phasellus elementum est sit amet sem accumsan tincidunt. In semper vulputate risus, sed sollicitudin libero consectetur eget. Curabitur pulvinar eleifend augue. Sed facilisis ligula sed arcu vulputate tempus.
Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut mi nisi, mattis sed est a, luctus aliquet metus. Integer fringilla, massa nec laoreet dapibus, odio sem convallis massa, a vestibulum tellus mi in massa. Sed at vulputate velit, id sagittis sem. Vestibulum ac libero massa. Vivamus et libero vel orci auctor sodales a a quam. Vivamus semper tortor eget lacus euismod, non dignissim tellus feugiat. Donec tincidunt nisi at ornare ullamcorper. Nulla at mi nulla. Phasellus ligula ante, vehicula sit amet mauris et, consectetur mollis odio.
Donec massa risus, ultricies et enim quis, vestibulum consectetur arcu. Nunc sed convallis dui, sagittis imperdiet metus. Sed non ultrices velit. Nullam arcu sem, varius non pulvinar id, convallis eget erat. Nam porta tincidunt lorem, non venenatis sapien hendrerit vitae. Suspendisse nec est leo. Nunc commodo, lectus nec facilisis laoreet, ex velit dapibus dui, et aliquet lacus est non velit. Vestibulum nisl velit, tempor vel lacus at, ultricies pellentesque nisi. Mauris velit tortor, aliquam a magna eget, efficitur fringilla erat. Praesent massa nisl, maximus sit amet viverra in, varius vel urna.
Pellentesque eget leo vitae neque dictum egestas at ullamcorper nulla. Aenean lacinia venenatis metus, in faucibus dolor sollicitudin eget. Sed volutpat sit amet urna vel molestie. Donec dignissim velit tortor, a blandit ligula commodo dapibus. Vestibulum ac dolor facilisis mauris maximus mattis. Nullam vitae libero ut ligula sodales accumsan et vel dui. Quisque dapibus, lacus accumsan interdum efficitur, tellus augue maximus ipsum, quis ultricies dolor justo in diam. Pellentesque id lobortis diam. Suspendisse mollis eget orci eu auctor. Nullam porttitor arcu mi, nec varius magna viverra quis. Fusce eleifend sodales turpis et hendrerit.
</section>
</section>
<footer class="footer" id="copyright" style="text-align:center">
<div id="cpy">© DA COSTA JOAO (2019)</div>
</footer>
</body>
</html>
As for the text cutting off, the below css seems to fix it without cutting off the image.
.body{
height: auto;
}
As for the background image, it may be the file size. I usually use https://compressor.io/ to reduce my file sizes while maintaining image quality.
Getting rid of
html,
body {
height: 100%;
}
Seems to fix the problem of the text getting cut off.
I am assuming you want an image with text going around it. You can try this out!
.image-container {
float: left;
margin: 0px 20px 5px 0px;
<section class="content">
<div class="image-container">
<img src="https://images.pexels.com/photos/374811/pexels-photo-374811.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" alt="">
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla ac ipsum non diam faucibus dignissim. Praesent a dolor tincidunt, rutrum diam ut, convallis orci. Maecenas eleifend, sapien id blandit rutrum, enim augue cursus magna, vitae varius orci nulla
eu arcu. Cras ultrices condimentum libero nec vulputate. Praesent id ante dignissim, congue elit id, iaculis eros. Aliquam lacus quam, facilisis et pulvinar quis, hendrerit varius erat. Duis feugiat imperdiet lobortis. Ut et faucibus dui. Integer
quis bibendum tortor, at mattis dolor. Sed id lacus nec nisi iaculis blandit. Duis nec ligula orci. Quisque tincidunt, orci id tincidunt consequat, eros erat dictum urna, vel ultricies sem nisl eu nunc. Nulla facilisi. Suspendisse at malesuada magna,
in suscipit purus. Fusce facilisis pharetra dui, ut cursus orci maximus non. Cras nec magna ac odio ornare ornare. Proin id commodo eros. Phasellus dui est, malesuada non mi sit amet, fringilla rhoncus ante. Phasellus non elit id est cursus malesuada.
Maecenas accumsan erat in urna pulvinar, sit amet egestas felis facilisis. Nullam tincidunt porta nulla, a consectetur sapien venenatis in. Phasellus elementum est sit amet sem accumsan tincidunt. In semper vulputate risus, sed sollicitudin libero
consectetur eget. Curabitur pulvinar eleifend augue. Sed facilisis ligula sed arcu vulputate tempus. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Ut mi nisi, mattis sed est a, luctus aliquet metus. Integer
fringilla, massa nec laoreet dapibus, odio sem convallis massa, a vestibulum tellus mi in massa. Sed at vulputate velit, id sagittis sem. Vestibulum ac libero massa. Vivamus et libero vel orci auctor sodales a a quam. Vivamus semper tortor eget lacus
euismod, non dignissim tellus feugiat. Donec tincidunt nisi at ornare ullamcorper. Nulla at mi nulla. Phasellus ligula ante, vehicula sit amet mauris et, consectetur mollis odio. Donec massa risus, ultricies et enim quis, vestibulum consectetur arcu.
Nunc sed convallis dui, sagittis imperdiet metus. Sed non ultrices velit. Nullam arcu sem, varius non pulvinar id, convallis eget erat. Nam porta tincidunt lorem, non venenatis sapien hendrerit vitae. Suspendisse nec est leo. Nunc commodo, lectus
nec facilisis laoreet, ex velit dapibus dui, et aliquet lacus est non velit. Vestibulum nisl velit, tempor vel lacus at, ultricies pellentesque nisi. Mauris velit tortor, aliquam a magna eget, efficitur fringilla erat. Praesent massa nisl, maximus
sit amet viverra in, varius vel urna. Pellentesque eget leo vitae neque dictum egestas at ullamcorper nulla. Aenean lacinia venenatis metus, in faucibus dolor sollicitudin eget. Sed volutpat sit amet urna vel molestie. Donec dignissim velit tortor,
a blandit ligula commodo dapibus. Vestibulum ac dolor facilisis mauris maximus mattis. Nullam vitae libero ut ligula sodales accumsan et vel dui. Quisque dapibus, lacus accumsan interdum efficitur, tellus augue maximus ipsum, quis ultricies dolor
justo in diam. Pellentesque id lobortis diam. Suspendisse mollis eget orci eu auctor. Nullam porttitor arcu mi, nec varius magna viverra quis. Fusce eleifend sodales turpis et hendrerit.
</p>
</section>

Fixed header overflowing parent container

I have a web page with a fixed header.
As you can see from the snippet below, the page isn't necessarily as wide as the viewport. To ensure the header width remains in sync with the rest of the page (and doesn't overflow), I use the following CSS on the app bar:
max-width: inherit;
width: inherit;
Simple fixed header example:
.page {
background-color: yellow;
margin: 0 auto;
max-width: 400px;
width: 100%;
}
.main {
background-color: aqua;
padding-top: 64px;
}
.app-bar {
background-color: red;
height: 64px;
max-width: inherit;
position: fixed;
top: 0;
width: inherit;
}
<div class="page">
<div class="app-bar">App bar</div>
<div class="main">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam feugiat nibh ac magna consequat luctus. Sed scelerisque mi nec tellus posuere pellentesque. Praesent varius et risus non fringilla. Maecenas nec sodales nulla, in ultricies erat. Phasellus
purus urna, suscipit quis dui nec, sollicitudin facilisis ipsum. In varius, dolor quis vestibulum finibus, nisl mauris interdum purus, tempus malesuada ante metus at sem. Nunc mauris tellus, blandit at ipsum non, convallis fringilla risus. Etiam vitae
sapien id dui aliquet tincidunt ut ut odio. Phasellus non metus egestas, faucibus nisi sed, lacinia dui. Donec convallis massa mi, quis dapibus magna sodales at. Sed gravida, justo ut placerat rhoncus, ligula quam fermentum magna, id vehicula turpis
arcu a enim. Vivamus eget volutpat nunc. Nam consequat sapien non sodales euismod. Integer euismod orci diam, et consequat mi feugiat sed. Proin aliquam porta nisi, ut aliquam enim facilisis ut.
</div>
</div>
However, I need to make some changes to the page structure to allow a full-height fixed left nav drawer. In order to do so, I need to create space by shifting the entire content to the right.
Required fixed header functionality:
.page {
background-color: yellow;
margin: 0 auto;
max-width: 400px;
width: 100%;
}
.app-content {
margin-left: 150px;
width: calc(100% - 150px);
}
.main {
background-color: aqua;
padding-top: 64px;
}
.app-bar {
background-color: red;
height: 64px;
max-width: inherit;
position: fixed;
top: 0;
width: inherit;
}
<div class="page">
<div class="app-content">
<div class="app-bar">App bar</div>
<div class="main">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam feugiat nibh ac magna consequat luctus. Sed scelerisque mi nec tellus posuere pellentesque. Praesent varius et risus non fringilla. Maecenas nec sodales nulla, in ultricies erat. Phasellus
purus urna, suscipit quis dui nec, sollicitudin facilisis ipsum. In varius, dolor quis vestibulum finibus, nisl mauris interdum purus, tempus malesuada ante metus at sem. Nunc mauris tellus, blandit at ipsum non, convallis fringilla risus. Etiam
vitae sapien id dui aliquet tincidunt ut ut odio. Phasellus non metus egestas, faucibus nisi sed, lacinia dui. Donec convallis massa mi, quis dapibus magna sodales at. Sed gravida, justo ut placerat rhoncus, ligula quam fermentum magna, id vehicula
turpis arcu a enim. Vivamus eget volutpat nunc. Nam consequat sapien non sodales euismod. Integer euismod orci diam, et consequat mi feugiat sed. Proin aliquam porta nisi, ut aliquam enim facilisis ut.
</div>
</div>
</div>
As you can see, the result is that the app-bar doesn't sync across the full width - instead it overflows the page container.
If I remove the width from app-content, the app-bar shrinks to it's content width.
What I'm looking for is to make the app-bar the same width as the app-content container, as it does in the first snippet.
Any advice appreciated as I'm running out of ideas.
Since width of your page is constant you can just give the app-bar it's desired width in this case 250px if I'm understanding you correctly:
.page {
background-color: yellow;
margin: 0 auto;
max-width: 400px;
width: 100%;
}
.app-content {
margin-left: 150px;
width: calc(100% - 150px);
}
.main {
background-color: aqua;
padding-top: 64px;
}
.app-bar {
background-color: red;
height: 64px;
max-width: 250px;
position: fixed;
top: 0;
width: inherit;
}
<div class="page">
<div class="app-content">
<div class="app-bar">App bar</div>
<div class="main">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam feugiat nibh ac magna consequat luctus. Sed scelerisque mi nec tellus posuere pellentesque. Praesent varius et risus non fringilla. Maecenas nec sodales nulla, in ultricies erat. Phasellus
purus urna, suscipit quis dui nec, sollicitudin facilisis ipsum. In varius, dolor quis vestibulum finibus, nisl mauris interdum purus, tempus malesuada ante metus at sem. Nunc mauris tellus, blandit at ipsum non, convallis fringilla risus. Etiam
vitae sapien id dui aliquet tincidunt ut ut odio. Phasellus non metus egestas, faucibus nisi sed, lacinia dui. Donec convallis massa mi, quis dapibus magna sodales at. Sed gravida, justo ut placerat rhoncus, ligula quam fermentum magna, id vehicula
turpis arcu a enim. Vivamus eget volutpat nunc. Nam consequat sapien non sodales euismod. Integer euismod orci diam, et consequat mi feugiat sed. Proin aliquam porta nisi, ut aliquam enim facilisis ut.
</div>
</div>
</div>
I don't know whether you can do that due to browser compatibility, but I would suggest using position: sticky.
.page {
background-color: yellow;
margin: 0 auto;
max-width: 400px;
width: 100%;
}
.app-content {
margin-left: 150px;
width: calc(100% - 150px);
position: relative;
}
.main {
background-color: aqua;
}
.app-bar {
background-color: red;
height: 64px;
max-width: inherit;
position: sticky;
top: 0;
left: 0;
z-index: 2;
width: 100%;
}
<div class="page">
<div class="app-bar">App bar</div>
<div class="app-content">
<div class="main">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam feugiat nibh ac magna consequat luctus. Sed scelerisque mi nec tellus posuere pellentesque. Praesent varius et risus non fringilla. Maecenas nec sodales nulla, in ultricies erat. Phasellus
purus urna, suscipit quis dui nec, sollicitudin facilisis ipsum. In varius, dolor quis vestibulum finibus, nisl mauris interdum purus, tempus malesuada ante metus at sem. Nunc mauris tellus, blandit at ipsum non, convallis fringilla risus. Etiam
vitae sapien id dui aliquet tincidunt ut ut odio. Phasellus non metus egestas, faucibus nisi sed, lacinia dui. Donec convallis massa mi, quis dapibus magna sodales at. Sed gravida, justo ut placerat rhoncus, ligula quam fermentum magna, id vehicula
turpis arcu a enim. Vivamus eget volutpat nunc. Nam consequat sapien non sodales euismod. Integer euismod orci diam, et consequat mi feugiat sed. Proin aliquam porta nisi, ut aliquam enim facilisis ut.
</div>
</div>
</div>

Make a Div Fill the Area Between a Header and Footer

To start, I am aware that this question has been asked many times previously, and answered about as many times as it has been asked. Unfortunately I have not been able to get the solutions provided here, here and here to work for me.
I have only been using html and css for a few weeks, teaching myself through Codecademy. Sadly Codecademy's positioning tutorials are littered with bugs so the code I have here is the product of much trial and error and I'm not sure if any of it has been setup "correctly".
Without further ado, here's my current code:
HTML
<!DOCTYPE html>
<html>
<head>
<title>Header Test</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
</head>
<body>
<div class="wrapper">
<div class="header"></div>
<div class="content"></div>
<div class="footer"></div>
</div>
</body>
</html>
CSS
html, body {
height:100%;
margin: 0;
padding: 0;
}
.wrapper {
min-height: 100%;
position: relative;
}
.header {
height: 75px;
padding: 10px;
background-color: red;
}
.content {
height:100%;
}
.footer {
width:100%;
height: 75px;
bottom: 0;
position: absolute;
background-color: red;
}
This code makes me a header and footer with a content div between them. However, the content div is 0px tall. I would like the div to stretch from the bottom of the header to the top of the footer.
Here's a JSFiddle of my current code. Thanks in advance for any help.
The 'modern' way is to use flexbox
DEMO
.wrapper {
min-height: 100%;
position: relative;
display:flex;
flex-direction: column;
justify-content: flex-start;
}
.content {
flex:1;
background:pink;
}
Edit: DEMO USING TABLE
Here is your solution.
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
.wrapper {
min-height: 100%;
position: relative;
}
.header {
height: 75px;
padding: 10px;
background-color: red;
}
.content {
height: 100%;
width: 100%;
position: absolute;
display: block;
background-color: blue;
}
.footer {
width: 100%;
height: 75px;
bottom: 0;
position: absolute;
background-color: orange;
}
<div class="wrapper">
<div class="header"></div>
<div class="content"></div>
<div class="footer"></div>
</div>
I think you need this code:
.content {
height:100vh;
}
Viewport-percentage lengths: the ‘vw’, ‘vh’, ‘vmin’, ‘vmax’ units
The viewport-percentage lengths are relative to the size of the initial containing block. When the height or width of the initial containing block is changed, they are scaled accordingly.[reference]
Your code is working actually. If <div class"content"> is empty then the height is 0px. Otherwise use fixed height value.
HTML:
<body>
<div id="header"></div>
<div id="content"><div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque malesuada diam eu aliquet pretium. Donec dapibus condimentum lectus a porta. Fusce sed augue bibendum, egestas nisi rhoncus, varius lectus. Nullam vitae erat vitae purus dapibus aliquet. Praesent id urna aliquet, interdum mi sit amet, dictum nunc. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Mauris facilisis sodales ligula, nec pulvinar neque ornare et. Vivamus ultrices odio venenatis lectus semper, at luctus sem tempus. Ut molestie sem ac faucibus pulvinar. Ut in massa et mauris congue accumsan at eu magna. Sed augue risus, varius eget vehicula eget, fringilla in magna. Proin tempus ante leo, non tempor justo cursus a. Sed a posuere nisl.
Nulla imperdiet nulla auctor tellus ultricies, quis cursus libero finibus. Praesent sed justo nec ex blandit pretium non in eros. Praesent a mollis ante. Donec sit amet vehicula quam, ut euismod dolor. Vivamus vitae faucibus felis. Ut eget condimentum arcu. Curabitur vel felis tortor. Quisque a semper neque. Fusce a diam ac elit fringilla sodales sit amet vel ligula.
Donec blandit congue commodo. Etiam dolor tellus, viverra et molestie vel, bibendum non diam. Vivamus dignissim ac sapien eget vulputate. Pellentesque eu ex nec tellus malesuada sollicitudin. Vivamus non erat eu est dapibus accumsan nec a erat. Donec a ligula tellus. Maecenas et ullamcorper urna.
Morbi maximus, quam a vulputate hendrerit, augue enim consectetur massa, vel tristique dui felis vel leo. Ut id pellentesque nisi, eget congue magna. Nunc vitae auctor quam. Etiam varius, nisi sed cursus faucibus, felis metus luctus enim, eu consectetur elit nulla ut magna. Donec mi tortor, ultricies eget fringilla vitae, fringilla et nisl. Vestibulum vestibulum neque leo, in viverra sapien vehicula quis. Donec fermentum placerat dignissim. Duis vestibulum dolor a tellus eleifend ultricies. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris quis suscipit diam. Vivamus tristique dignissim fermentum. Phasellus eu cursus ipsum. Quisque magna purus, ultrices quis dolor vitae, dignissim pharetra nisi. Sed sollicitudin blandit nulla, a consequat lorem congue in. Fusce a dapibus orci. Aenean sed laoreet ex.
Aenean eget volutpat dui, a eleifend sem. Fusce malesuada sodales dapibus. Cras gravida ornare mauris, a ullamcorper massa pulvinar eu. Proin facilisis dapibus commodo. Nullam ac sem ultrices, iaculis nulla at, pulvinar velit. Cras auctor, mauris sit amet viverra tristique, nunc turpis faucibus lacus, at rutrum massa diam eu nisi. Aenean facilisis metus tempor accumsan tristique. Phasellus condimentum mauris a neque iaculis pretium ut vitae ligula. Vivamus congue mi eget sagittis iaculis. Praesent urna ipsum, porta in eros et, commodo vulputate odio. Vestibulum bibendum arcu sit amet orci viverra pellentesque. Etiam pellentesque sodales nisi, sit amet consequat mi ornare ut. Donec non cursus velit.
</div>
</div>
<div id="footer"></div>
</body>
CSS:
html { height: 100%; }
body {
height:100%;
min-height: 100%;
background: #000000;
color: #FFFFFF;
position:relative;
}
#header {
height:50px;
width:100%;
top:0px;
left:0px;
background: #CCCCCC;
position:fixed;
}
#footer {
height:50px;
width:100%;
bottom:0px;
left:0px;
background: #CCCCCC;
position:fixed;
}
#content {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
height:100%;
padding: 0 20px;
}
#content > div {
padding: 70px 0;
}