I'm trying to make some kind of dictionary with flex. My elements are added from top to bottom then left to right (the flex element .dictionary grows on the right instead of the bottom. My .dic-entry entries stay coherent/together because they are each wrapped in an <article> tag. However, between them, there are "letter titles" .dic-letter-title and they should stay together with the next .dic-entry.
In a column layout I would do break-after: avoid, how could I achieve this effect with flex elements?
IMPORTANT EDIT: To clarify, I'm able to circumvent the problem and make the result look exactly as I want. However I'm looking for a semantically-correct solution. Not one where I have to wrap two element together with a meaningless element for example.
EDIT: As #Nisha suggested in the comment I could wrap .dic-letter-title and the first .dic-entry in a container, however I'd like to avoid doing that as it is not semantically correct. If I wanted to add a semantically-correct container, it would have to be around all the dic-entry sharing the same first letter, but then they would form a bloc and I don't want that either.
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%
}
body, main, article {
display: flex;
flex-flow: column;
}
main {
flex: 1 0 100%;
}
main, .container {
min-height: 0;
}
.dictionary {
display: flex;
flex-flow: column wrap;
align-content: flex-start;
overflow-x: scroll;
}
.dic-letter-title {
/* DEBUG: This isn't working */
break-after: avoid;
color: red;
}
.dic-entry, .dic-entry * {
display: block;
padding: 0;
}
.dic-entry * {
margin: 0;
}
.dic-entry {
width: 16ch;
padding: 0 2.5em 1.5em 0;
}
<article class="container">
<section class="dictionary small-text">
<h3 class="dic-letter-title">Aa</h3>
<article class="dic-entry"><h4>Aliquam consequat</h4>
<p>Aliquam consequat vestibulum magna nec consequat.</p></article>
<article class="dic-entry"><h4>Aliquam fermentum</h4>
<p>Aliquam fermentum quis arcu vitae maximus.</p></article>
<h3 class="dic-letter-title">Ll</h3>
<article class="dic-entry"><h4>Lorem ipsum</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p></article>
<h3 class="dic-letter-title">Mm</h3>
<article class="dic-entry"><h4>Mauris blandit</h4>
<p>Mauris blandit, enim a aliquam convallis, felis turpis ultricies dolor, in blandit velit lorem at nulla.</p></article>
<h3 class="dic-letter-title">Pp</h3>
<article class="dic-entry"><h4>Pellentesque habitant</h4>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p></article>
<article class="dic-entry"><h4>Phasellus</h4>
<p>Phasellus in bibendum nisi.</p></article>
<h3 class="dic-letter-title">Uu</h3>
<article class="dic-entry"><h4>Quisque nec eros</h4>
<p>Quisque nec eros quis orci venenatis porttitor vitae sed nunc.</p></article>
<h3 class="dic-letter-title">Uu</h3>
<article class="dic-entry"><h4>Sed vulputate</h4>
<p>Sed vulputate id orci sed maximus.</p></article>
</section>
</article>
EDIT: I tried #zangab's solution of using list which mases sense semantically. However, now the "letter-group" title is solidary with what comes next, however now it's the whole letter-group can't wrap because the li can't be broken.
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%
}
body, main, article, .disc-entry {
display: flex;
flex-flow: column;
}
main {
flex: 1 0 100%;
}
main, .container {
min-height: 0;
}
.dictionary {
display: flex;
flex-flow: column wrap;
align-content: flex-start;
overflow-x: scroll;
}
.dictionary li {
list-style-type: none;
}
.dic-letter-title {
/* DEBUG: This isn't working */
break-after: avoid;
color: red;
}
.dic-entry, .dic-entry * {
display: block;
padding: 0;
}
.dic-entry * {
margin: 0;
}
.dic-entry {
width: 16ch;
padding: 0 2.5em 1.5em 0;
}
<article class="container">
<ul class="dictionary small-text">
<li class="dic-letter">
<h3 class="dic-letter-title">Aa</h3>
<ul>
<li class="dic-entry">
<h4>Aliquam consequat</h4>
<p>Aliquam consequat vestibulum magna nec consequat.</p>
</li>
<li class="dic-entry">
<h4>Aliquam fermentum</h4>
<p>Aliquam fermentum quis arcu vitae maximus.</p>
</li>
</ul>
</li>
<li class="dic-letter">
<h3 class="dic-letter-title">Ll</h3>
<ul>
<li class="dic-entry">
<h4>Lorem ipsum</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</li>
</ul>
</li>
<li class="dic-letter">
<h3 class="dic-letter-title">Mm</h3>
<ul>
<li class="dic-entry">
<h4>Mauris blandit</h4>
<p>Mauris blandit, enim a aliquam convallis, felis turpis ultricies dolor, in blandit velit lorem at nulla.</p>
</li>
</ul>
</li>
<li class="dic-letter">
<h3 class="dic-letter-title">Pp</h3>
<ul>
<li class="dic-entry">
<h4>Pellentesque habitant</h4>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
</li>
<li class="dic-entry">
<h4>Phasellus</h4>
<p>Phasellus in bibendum nisi.</p>
</li>
</ul>
</li>
<li class="dic-letter">
<h3 class="dic-letter-title">Qq</h3>
<ul>
<li class="dic-entry">
<h4>Quisque nec eros</h4>
<p>Quisque nec eros quis orci venenatis porttitor vitae sed nunc.</p>
</li>
</ul>
</li>
<li class="dic-letter">
<h3 class="dic-letter-title">Uu</h3>
<ul>
<li class="dic-entry">
<h4>Sed vulputate</h4>
<p>Sed vulputate id orci sed maximus.</p>
</li>
</ul>
</li>
</ul>
</article>
have a look here:
* {
margin: 0;
padding: 0;
}
html, body {
height: 100%
}
body, main, article {
display: flex;
flex-flow: column;
}
main {
flex: 1 0 100%;
}
main, .container {
min-height: 0;
}
.dictionary {
display: flex;
flex-flow: column wrap;
align-content: flex-start;
overflow-x: scroll;
list-style-type: none;
}
.dic-letter-title {
color: red;
}
.dic-entry, .dic-entry * {
display: block;
padding: 0;
}
.dic-entry * {
margin: 0;
}
.dic-entry {
width: 16ch;
padding: 0 2.5em 1.5em 0;
}
<article class="container">
<ul class="dictionary small-text">
<li>
<h3 class="dic-letter-title">Aa</h3>
<article class="dic-entry">
<h4>Aliquam consequat</h4>
<p>Aliquam consequat vestibulum magna nec consequat.</p>
</article>
<article class="dic-entry">
<h4>Aliquam fermentum</h4>
<p>Aliquam fermentum quis arcu vitae maximus.</p>
</article>
</li>
<li>
<h3 class="dic-letter-title">Ll</h3>
<article class="dic-entry">
<h4>Lorem ipsum</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</article>
</li>
<li>
<h3 class="dic-letter-title">Mm</h3>
<article class="dic-entry">
<h4>Mauris blandit</h4>
<p>Mauris blandit, enim a aliquam convallis, felis turpis ultricies dolor, in blandit velit lorem at nulla.
</p>
</article>
<li>
<h3 class="dic-letter-title">Pp</h3>
<article class="dic-entry"><h4>Pellentesque habitant</h4>
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p></article>
<article class="dic-entry"><h4>Phasellus</h4>
<p>Phasellus in bibendum nisi.</p></article></li>
<li>
<h3 class="dic-letter-title">Uu</h3>
<article class="dic-entry"><h4>Quisque nec eros</h4>
<p>Quisque nec eros quis orci venenatis porttitor vitae sed nunc.</p></article></li>
<li>
<h3 class="dic-letter-title">Uu</h3>
<article class="dic-entry"><h4>Sed vulputate</h4>
<p>Sed vulputate id orci sed maximus.</p></article></li>
</ul>
</article>
Related
My grid was working perfectly until I made some changes, 5 days have passed without resolution with rigorous work, I have simplified it, for an easier read. I have also made sure to add clear fix's to the floats of elements inside the near top grid items.
I have used grid-template-areas and grid-template-columns to adjust the size of the columns and show where each grid item should go. However, when I render the web page all the items are aligned to the far left column, except for my navbar and hero image which have been set to 100% width, they are fine. The desired grid layout is detailed at the bottom of the CSS file standalone and with media queries.
have a good day, thanks for reading (I am a novice)
HTML CODE
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Home</title>
<link href="normalize.css" rel="stylesheet">
<link href="main.css" rel="stylesheet">
</head>
<body>
<div class="wrapper">
<header class="navbar">
<a id="top"></a>
<img class="logo" src="randimage.png" alt="title" style=height:20px;>
<nav class="topnav">
<ul>
<li>Learning journal</li>
<li>Tutorial</li>
<li>Contact me</li>
</ul>
</nav>
</header>
<div class="hero-image">
<div class="hero-text">
<h1>Learning Journal</h1>
<p>This is a log of my journey in learning how to design a web site.</p>
</div>
</div>
<nav class="week-nav">
<h2 class="contenthead">Weekly Posts</h2>
<ol>
<li><a href='#week1'>Introduction to Web Design</a></li>
<li><a href='#week2'>Learning how to make web pages</a></li>
<li><a href='#week3'>Learning about lists, quotes and tables</a></li>
<li><a href='#week4'>CSS basics</a></li>
<li><a href='#week5'>CSS box model & styling text</a></li>
<li><a href='#week6'>Responsive web design</a></li>
<li><a href='#week7'>RWD2</a></li>
<li><a href='#week8'>RWD3</a></li>
<li><a href='#week9'>HTML5 & CSS forms</a></li>
<li><a href='#week10'></a></li>
<li><a href='#week11'></a></li>
<li><a href='#ref'>References</a></li>
</ol>
</nav>
<div class="table">
<table>
<caption><strong>Personal timetable</strong></caption>
<tr>
<th>Day/Time</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
</tr>
<tr>
<td>9-10am</td>
<td>e</td>
<td>e</td>
<td>--</td>
</tr>
<tr>
<td>10-11am</td>
<td>e</td>
<td>e</td>
<td>e</td>
</tr>
<tr>
<td>11-12pm</td>
<td>e</td>
<td>e</td>
<td>e</td>
</tr>
<tr>
<td>12-1pm</td>
<td>e</td>
<td>--</td>
<td>--</td>
</tr>
<tr>
<td>1-2pm</td>
<td>--</td>
<td>e</td>
<td>--</td>
</tr>
<tr>
<td>2-3pm</td>
<td>e</td>
<td>--</td>
<td>--</td>
</tr>
<tr>
<td>3-4pm</td>
<td>e</td>
<td>--</td>
<td>--</td>
</tr>
<tr>
<td>4-5pm</td>
<td>e</td>
<td>--</td>
<td>--</td>
</tr>
</table>
</div>
<div class="main">
<main>
<h2>Learning Journal</h2>
<article>
<header class="post">
<a id="week8"></a>
<h3>Week 8:</h3>
<p>Published on<time datetime="2019-12-20"><strong> December 20, 2019</strong></time></p>
</header>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In molestie aliquet felis sed finibus. Proin eleifend arcu at est euismod eleifend. Ut vulputate lorem eu nisi condimentum suscipit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Mauris tempor non purus dignissim placerat. Ut commodo, lacus in ultricies mattis, diam augue sollicitudin nisl, sagittis gravida elit tellus eu ex. Nam pellentesque egestas nisi, ac semper nulla sagittis id. Donec ligula elit, aliquet eget placerat in, accumsan sit amet mi. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer lacinia odio ut ornare aliquam. Donec et erat vel sem volutpat lobortis eu vel massa. Nullam sit amet dui ac nibh dignissim mollis eget nec nibh.</p>
</article>
<article>
<header class="post">
<a id="week7"></a>
<h3>Week 7:</h3>
<p>Published on<time datetime="2019-12-18"><strong> December 18, 2019</strong></time></p>
</header>
<h3>Flexible media</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In molestie aliquet felis sed finibus. Proin eleifend arcu at est euismod eleifend. Ut vulputate lorem eu nisi condimentum suscipit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Mauris tempor non purus dignissim placerat. Ut commodo, lacus in ultricies mattis, diam augue sollicitudin nisl, sagittis gravida elit tellus eu ex. Nam pellentesque egestas nisi, ac semper nulla sagittis id. Donec ligula elit, aliquet eget placerat in, accumsan sit amet mi. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer lacinia odio ut ornare aliquam. Donec et erat vel sem volutpat lobortis eu vel massa. Nullam sit amet dui ac nibh dignissim mollis eget nec nibh.</p>
</article>
<article>
<header class="post">
<a id="week6"></a>
<h3>Week 6:</h3>
<p>Published on<time datetime="2019-12-16"><strong> December 16, 2019</strong></time></p>
</header>
<h3>Week 6 outline:</h3>
<ul>
<li>Reflection & changes</li>
<li>Wireframes</li>
<li>Responsive grid layout workflow</li>
<li>RWD for mobile</li>
<li>Media queries</li>
<li>Making images flexible</li>
<li>Testing responsiveness of web page</li>
</ul>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In molestie aliquet felis sed finibus. Proin eleifend arcu at est euismod eleifend. Ut vulputate lorem eu nisi condimentum suscipit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Mauris tempor non purus dignissim placerat. Ut commodo, lacus in ultricies mattis, diam augue sollicitudin nisl, sagittis gravida elit tellus eu ex. Nam pellentesque egestas nisi, ac semper nulla sagittis id. Donec ligula elit, aliquet eget placerat in, accumsan sit amet mi. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer lacinia odio ut ornare aliquam. Donec et erat vel sem volutpat lobortis eu vel massa. Nullam sit amet dui ac nibh dignissim mollis eget nec nibh.</p>
</article>
<article>
<header class="post">
<a id="week5"></a>
<h3>Week 5:</h3>
<p>Published on<time datetime="2019-12-10"><strong> December 10, 2019</strong></time></p>
</header>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In molestie aliquet felis sed finibus. Proin eleifend arcu at est euismod eleifend. Ut vulputate lorem eu nisi condimentum suscipit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Mauris tempor non purus dignissim placerat. Ut commodo, lacus in ultricies mattis, diam augue sollicitudin nisl, sagittis gravida elit tellus eu ex. Nam pellentesque egestas nisi, ac semper nulla sagittis id. Donec ligula elit, aliquet eget placerat in, accumsan sit amet mi. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer lacinia odio ut ornare aliquam. Donec et erat vel sem volutpat lobortis eu vel massa. Nullam sit amet dui ac nibh dignissim mollis eget nec nibh.</p>
</article>
<p>Go to top</p>
</main>
</div>
<div class="aside">
<aside>
<a id="ref"></a>
<h2 class="contenthead">References</h2>
<ul>
<li>Examples of Web Standards</li>
<li>HTML5: Structure, Syntax and Semantics</li>
<li>HTML definitions & concept clarity</li>
<li>HTML elements reference</li>
<li>HTML Lists</li>
<li>Quoting framework</li>
<li>Type, class and ID selectors</li>
</ul>
</aside>
</div>
<div class="footer">
<footer>
Email [myname]<br>
<small>© 2020, fname sname.</small>
</footer>
</div>
</div>
</body>
</html>
CSS CODE
#import url('https://fonts.googleapis.com/css?family=Oswald&display=swap');
/*importing google font*/
* {box-sizing: border-box;}
#wrapper {
display: grid;
max-width: 100%;
margin: 0 auto;
}
body {
margin: 0;
padding: 0;
background: #fff;
font-family: "helvetica neue", sans-serif;
font-size: 1em;
}
body {
/*background-image: url("/ci435/images/BG_IMAGE.png");*/
/*background-repeat: repeat;*/
/*un-comment these when you have created round boxes for each element containing raw text*/
}
.navbar {
max-width: 100%;
padding: 1em 1em;
background: #000;
height: 3em;
width: 100%;
grid-template-columns: 1fr 1fr 1fr 1fr;
}
a { text-decoration: none; color: #2c3ad1; }
a:hover { text-decoration: underline; }
a:visited { color: #5c13bd; }
a:active { color: #e8d05a; }
.topnav {
height: 3em;
font-weight: bold;
list-style: none;
float: right;
}
main {
clear: left;
}
.topnav li {
display: inline-block;
text-transform: uppercase;
line-height: 1.2em;
font-size: 0.7em;
text-indent: 3em;
}
.topnav ul {
position: relative;
bottom: 2.5em;
right: 1.6em;
}
.topnav a:link { color: lightgrey;}
.topnav a:hover {
color: #fff;
border-bottom: 1000px #fff
}
.topnav a:visited { color: #fff; }
.logo {
height: 20px;
width: 100%;
float: left;
}
.navbar:after {
content: "";
visibility: hidden;
display: block;
clear: both;
}
table {
background-color: #FFF;
border: solid 4px #4682B4;
border-spacing: 0;
text-align: center;
}
tbody tr:nth-child(even) {
background-color: #B0C4DE;
}
th {
background-color: #4682B4;
padding: 3px;
}
caption {
font-size: 1.3em;
padding-bottom: 0.5em;
/*space between caption and the table underneath*/
}
.hero-image {
background-image: linear-gradient(to bottom, rgba(0, 175, 255, 0.4), rgba(117, 19, 93, 0.73)), url("/ci435/images/bannerImages/lj.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
width: 100%;
height: 70vh;
/*justify-content: center;*/
}
.hero-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
}
/*GRID LAYOUT*/
.navbar {
grid-area: navbar;
}
.hero-image {
grid-area: hero;
}
.week-nav {
grid-area: week-nav;
}
.table {
grid-area: table;
}
main {
grid-area: main;
}
aside {
grid-area: aside;
}
footer {
grid-area: footer;
}
/*LAYOUT STYLES*/
#wrapper {
display: grid;
grid-template-areas:
"navbar"
"hero"
"week-nav"
"table"
"main"
"aside"
"footer";
}
#media (min-width: 750px) {
#wrapper {
grid-template-columns: 3fr 7fr;
grid-template-areas:
"navbar navbar"
"hero hero"
"week-nav table"
"week-nav main"
"aside main"
"footer footer";
}
}
#media (min-width: 1000px) {
#wrapper {
grid-template-columns: 1fr 3fr 1fr;
grid-template-rows: auto;
grid-template-areas:
"navbar navbar navbar"
"hero hero hero"
"week-nav table aside"
"week-nav main aside"
"footer footer footer";
}
}
#media (max-width: 500px) {
table {
display:none;
}
}
It looks like your issues are coming from your css selectors.
First, your grid isn't getting applied because in your css, you use an id selector (#wrapper), but in your html you give it the class, not id, "wrapper". Changing either the html to an id or the css to a class will fix this - if you think it is a wrapper pattern you will reuse then set it as a class, otherwise I'd recommend changing the html to set id="wrapper".
Next, the selectors you use to assign the grid-areas for main, aside, and footer are all the tag selectors. The issue here is that each of your main, aside, and footer elements are wrapped in divs inside of wrapper, so hierarchically it's actually #wrapper -> div container -> main/aside/footer. The grid-area attributes of each main/aside/footer are therefore unused as they look in their immediate parent, the div container, for the grid-template-areas when it is really in the #wrapper. To fix this, you can either move the grid-area attributes in your css from the tag selector to the div container selector, or if the div containers are otherwise unused, remove them entirely.
Here is the modified css to work with grid:
#import url("https://fonts.googleapis.com/css?family=Oswald&display=swap");
/*importing google font*/
* {
box-sizing: border-box;
}
#wrapper {
display: grid;
max-width: 100%;
margin: 0 auto;
}
body {
margin: 0;
padding: 0;
background: #fff;
font-family: "helvetica neue", sans-serif;
font-size: 1em;
}
body {
/*background-image: url("/ci435/images/BG_IMAGE.png");*/
/*background-repeat: repeat;*/
/*un-comment these when you have created round boxes for each element containing raw text*/
}
.navbar {
grid-area: navbar;
max-width: 100%;
padding: 1em 1em;
background: #000;
height: 3em;
width: 100%;
grid-template-columns: 1fr 1fr 1fr 1fr;
}
a {
text-decoration: none;
color: #2c3ad1;
}
a:hover {
text-decoration: underline;
}
a:visited {
color: #5c13bd;
}
a:active {
color: #e8d05a;
}
.topnav {
height: 3em;
font-weight: bold;
list-style: none;
float: right;
}
main {
clear: left;
}
.topnav li {
display: inline-block;
text-transform: uppercase;
line-height: 1.2em;
font-size: 0.7em;
text-indent: 3em;
}
.topnav ul {
position: relative;
bottom: 2.5em;
right: 1.6em;
}
.topnav a:link {
color: lightgrey;
}
.topnav a:hover {
color: #fff;
border-bottom: 1000px #fff;
}
.topnav a:visited {
color: #fff;
}
.logo {
height: 20px;
width: 100%;
float: left;
}
.navbar:after {
content: "";
visibility: hidden;
display: block;
clear: both;
}
table {
background-color: #fff;
border: solid 4px #4682b4;
border-spacing: 0;
text-align: center;
}
tbody tr:nth-child(even) {
background-color: #b0c4de;
}
th {
background-color: #4682b4;
padding: 3px;
}
caption {
font-size: 1.3em;
padding-bottom: 0.5em;
/*space between caption and the table underneath*/
}
.hero-image {
background-image: linear-gradient(
to bottom,
rgba(0, 175, 255, 0.4),
rgba(117, 19, 93, 0.73)
),
url("/ci435/images/bannerImages/lj.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
width: 100%;
height: 70vh;
/*justify-content: center;*/
}
.hero-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
}
/*GRID LAYOUT*/
.navbar {
grid-area: navbar;
}
.hero-image {
grid-area: hero;
}
.week-nav {
grid-area: week-nav;
}
.table {
grid-area: table;
}
.main {
grid-area: main;
}
.aside {
grid-area: aside;
}
.footer {
grid-area: footer;
}
/*LAYOUT STYLES*/
.wrapper {
display: grid;
grid-template-areas:
"navbar"
"hero"
"week-nav"
"table"
"main"
"aside"
"footer";
}
#media (min-width: 750px) {
.wrapper {
grid-template-columns: 3fr 7fr;
grid-template-areas:
"navbar navbar"
"hero hero"
"week-nav table"
"week-nav main"
"aside main"
"footer footer";
}
}
#media (min-width: 1000px) {
.wrapper {
grid-template-columns: 1fr 3fr 1fr;
grid-template-rows: auto;
grid-template-areas:
"navbar navbar navbar"
"hero hero hero"
"week-nav table aside"
"week-nav main aside"
"footer footer footer";
}
}
#media (max-width: 500px) {
table {
display: none;
}
}
Hope this helps!
so I have this project where I was given a screenshot of a website and have to replicate it while using HTML and CSS code purely. But I have gotten myself into a little predicament where my navbar has excess space that I don't want because I want a search bar to go where that excess space is at.
html {
background-color: lightgrey;
font-size: 100%;
}
body{
margin: 5%;
margin-top: 0;
font-family: Georgia, "Times New Roman", Times, serif, Arial, Helvetica, sans-serif;
}
/* Navigation Bar*/
nav ul{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #e9eed0
}
#current a{
background-color: #b8d03b;
color: white;
}
.nav li {
float: left;
border-right: 1px solid #bbb
}
.nav li a {
display: block;
color: #8c8f7d;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* Search Bar */
.search {
float: right;
}
/* Heading */
.heading{
background-color: #f6f6f6;
border: 1px solid #b8d03b;
border-bottom:.5px solid #b8d03b;
}
/* Main text area */
.main {
display: block;
background-color: #ffffff;
color: grey;
border: 1px solid #b8d03b;
float: left;
}
.content{
width: 50%;
float: left;
padding: 5px 15px;
}
.middle{
width:30%;
float: left;
padding: 5px 15px;
margin: 0px 5px 5px 5px;
}
.sidebar{
width: 10%;
padding: 5px 15px;
float: left;
}
/* Calendar */
.october{
text-align: center;
}
.weekdays {
margin: 0;
padding: 10px 0;
background-color: #cccccc;
text-align: center;
}
.weekdays li {
display: inline-block;
color: #ffffff;
width: 10%;
text-align: center;
}
.days {
text-align: center;
padding: 10px 0;
background: #eee;
margin: 0;
}
.days li {
list-style-type: none;
display: inline-block;
width: 10%;
text-align: center;
margin-bottom: 5px;
font-size:12px;
color: #777;
}
.days li .active {
color: #3c8cd7 !important
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title> Final Project </title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header role='banner'>
<nav>
<ul class="nav">
<li id="current">Home </li>
<li>ELA </li>
<li> Photos</li>
<li> About</li>
<li> Contact</li>
</ul>
</nav>
</header>
<div class="search">
<form method="get" action="search-results.php" role="search">
<label for="search"> Search: </label>
<input type="search" size="30">
<input type="submit" value="Search" />
</div>
<div class="heading">
<p><span> News Flash</span> By Guillermo Molina </p>
<p><small>>> Home</small></p>
</div>
<div class="main">
<article class="content">
<p><small>posted on Novermber 16, 2017 by Guillermo Molina</small></p>
<h1>About This Template</h1>
<p><strong>News Flash</strong> Denec leo. Vivamus fermnetum nibh in augue.
Praesent a lacus at erna congue rutrum. Nulla enim erosm porttitor eu, tempus
id, varius non, nib. Duis enim nula luctus eu, dapibus lacinia, venenatis id quam.
Vestibulum imperdiet, magna nec eleifend rutrum, nunc lectus vestibulum velit, euismod lacinia quam nisl id lorem. Quisque erat.
</p>
<p>Vestibulum imperdiet, magna nec eleifend rutrum, nunc lectus vestibulum
velit, euismod lacinia quam nisl id lorem. Quisque erat.</p>
<h2>A Heading Level 2</h2>
<p>This paragraph is followed by a sample unordered list:</p>
<ul>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Urnanet non molestie semper</li>
<li>Proin gravida orci porttitor</li>
</ul>
<h3>Heading Level 3</h3>
<p>While this is followed by a blockquote:</p>
<blockquote cite="http://www.google.com">
Donec leo, vivamus nibh in augue praesent a lacus at urna congue rutrum. Quisque dictum integer nisl risus, sagittis convallis,
rutrum id, congue, and nibh.
</blockquote>
<p> Comments(33) Permalink </p>
<hr>
<p>TAGS: DOLOR IPSUM SIT AMET DOLOR IPSUM LOREM SIT AMET </p>
</article>
<section class="middle">
<h2>Recent Posts</h2>
<h3>Aliquam Libero</h3>
<p>Nullam ante orci, eget, tempus quis, ultrices in, est. Curabitur sit amet nulla. Nam in massa. Sed vel tellus. Curabitur sem urna,
consequat vel, sescipit in, mattis placerat, nulla. Sed ac leo. Pellentesque imperdiet.More...</p>
<h3>Semper Vestibulum</h3>
<p>DOnec leo, vivamus fermentum nibh in augue praesent a lacus at urna congue rutrum. Quisque dictum integer nisl risus, sagittis convallis, rutrum id,
congue, and nibh More... </p>
</section>
<aside class="sidebar">
<h2>Categories</h2>
Aliquam libero
Consectetuer elit
Metus pellentesque
Suspendisse mauris
Urnanet molestie semper
Proin orci porttitor
<h2>Archives</h2>
September(23)
August(31)
July(31)
June(30)
(31)
<h2>Calendar</h2>
<p class="october">October 2017</p>
<ul class="weekdays">
<li>M</li>
<li>T</li>
<li>W</li>
<li>T</li>
<li>F</li>
<li>S</li>
<li>S</li>
</ul>
<ul class="days">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li><span class="active">10</span></li>
<li>11</li>
<li>12</li>
<li>13</li>
<li>14</li>
<li>15</li>
<li>16</li>
<li>17</li>
<li>18</li>
<li>19</li>
<li>20</li>
<li>21</li>
<li>22</li>
<li>23</li>
<li>24</li>
<li>25</li>
<li>26</li>
<li>27</li>
<li>28</li>
<li>29</li>
<li>30</li>
<li>31</li>
</ul>
</aside>
</div>
</body>
</html>
I'm wondering changes I can make to my code in order to make the search bar be right next to the navbar while getting rid of the excess space that the navbar has.
html {
background-color: lightgrey;
font-size: 100%;
}
body{
margin: 5%;
margin-top: 0;
font-family: Georgia, "Times New Roman", Times, serif, Arial, Helvetica, sans-serif;
}
/* Navigation Bar*/
nav ul{
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #e9eed0
}
#current a{
background-color: #b8d03b;
color: white;
}
.nav li {
float: left;
border-right: 1px solid #bbb
}
.nav li a {
display: block;
color: #8c8f7d;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* Search Bar */
.search {
float: right;
}
/* Heading */
.heading{
background-color: #f6f6f6;
border: 1px solid #b8d03b;
border-bottom:.5px solid #b8d03b;
}
/* Main text area */
.main {
display: block;
background-color: #ffffff;
color: grey;
border: 1px solid #b8d03b;
float: left;
}
.content{
width: 50%;
float: left;
padding: 5px 15px;
}
.middle{
width:30%;
float: left;
padding: 5px 15px;
margin: 0px 5px 5px 5px;
}
.sidebar{
width: 10%;
padding: 5px 15px;
float: left;
}
/* Calendar */
.october{
text-align: center;
}
.weekdays {
margin: 0;
padding: 10px 0;
background-color: #cccccc;
text-align: center;
}
.weekdays li {
display: inline-block;
color: #ffffff;
width: 10%;
text-align: center;
}
.days {
text-align: center;
padding: 10px 0;
background: #eee;
margin: 0;
}
.days li {
list-style-type: none;
display: inline-block;
width: 10%;
text-align: center;
margin-bottom: 5px;
font-size:12px;
color: #777;
}
.days li .active {
color: #3c8cd7 !important
}
/** Added ***/
nav{
width: 100%;
}
.navbar{
float: left
}
.search{
float: right;
}
.clearfix{
clear: both;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title> Final Project </title>
<link rel="stylesheet" href="style.css">
<style>
nav{
width: 100%;
}
.navbar{
float: left
}
.search{
float: right;
}
.clearfix{
clear: both;
}
</style>
</head>
<body>
<header role='banner'>
<nav>
<div class="navbar">
<ul class="nav">
<li id="current">Home </li>
<li>ELA </li>
<li> Photos</li>
<li> About</li>
<li> Contact</li>
</ul>
</div>
<div class="search">
<form method="get" action="search-results.php" role="search">
<label for="search"> Search: </label>
<input type="search" size="30">
<input type="submit" value="Search" />
</form>
</div>
<div class="clearfix"></div>
</nav>
</header>
<div class="heading">
<p><span> News Flash</span> By Guillermo Molina </p>
<p><small>>> Home</small></p>
</div>
<div class="main">
<article class="content">
<p><small>posted on Novermber 16, 2017 by Guillermo Molina</small></p>
<h1>About This Template</h1>
<p><strong>News Flash</strong> Denec leo. Vivamus fermnetum nibh in augue.
Praesent a lacus at erna congue rutrum. Nulla enim erosm porttitor eu, tempus
id, varius non, nib. Duis enim nula luctus eu, dapibus lacinia, venenatis id quam.
Vestibulum imperdiet, magna nec eleifend rutrum, nunc lectus vestibulum velit, euismod lacinia quam nisl id lorem. Quisque erat.
</p>
<p>Vestibulum imperdiet, magna nec eleifend rutrum, nunc lectus vestibulum
velit, euismod lacinia quam nisl id lorem. Quisque erat.</p>
<h2>A Heading Level 2</h2>
<p>This paragraph is followed by a sample unordered list:</p>
<ul>
<li>Consectetuer adipiscing elit</li>
<li>Metus aliquam pellentesque</li>
<li>Urnanet non molestie semper</li>
<li>Proin gravida orci porttitor</li>
</ul>
<h3>Heading Level 3</h3>
<p>While this is followed by a blockquote:</p>
<blockquote cite="http://www.google.com">
Donec leo, vivamus nibh in augue praesent a lacus at urna congue rutrum. Quisque dictum integer nisl risus, sagittis convallis,
rutrum id, congue, and nibh.
</blockquote>
<p> Comments(33) Permalink </p>
<hr>
<p>TAGS: DOLOR IPSUM SIT AMET DOLOR IPSUM LOREM SIT AMET </p>
</article>
<section class="middle">
<h2>Recent Posts</h2>
<h3>Aliquam Libero</h3>
<p>Nullam ante orci, eget, tempus quis, ultrices in, est. Curabitur sit amet nulla. Nam in massa. Sed vel tellus. Curabitur sem urna,
consequat vel, sescipit in, mattis placerat, nulla. Sed ac leo. Pellentesque imperdiet.More...</p>
<h3>Semper Vestibulum</h3>
<p>DOnec leo, vivamus fermentum nibh in augue praesent a lacus at urna congue rutrum. Quisque dictum integer nisl risus, sagittis convallis, rutrum id,
congue, and nibh More... </p>
</section>
<aside class="sidebar">
<h2>Categories</h2>
Aliquam libero
Consectetuer elit
Metus pellentesque
Suspendisse mauris
Urnanet molestie semper
Proin orci porttitor
<h2>Archives</h2>
September(23)
August(31)
July(31)
June(30)
(31)
<h2>Calendar</h2>
<p class="october">October 2017</p>
<ul class="weekdays">
<li>M</li>
<li>T</li>
<li>W</li>
<li>T</li>
<li>F</li>
<li>S</li>
<li>S</li>
</ul>
<ul class="days">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li><span class="active">10</span></li>
<li>11</li>
<li>12</li>
<li>13</li>
<li>14</li>
<li>15</li>
<li>16</li>
<li>17</li>
<li>18</li>
<li>19</li>
<li>20</li>
<li>21</li>
<li>22</li>
<li>23</li>
<li>24</li>
<li>25</li>
<li>26</li>
<li>27</li>
<li>28</li>
<li>29</li>
<li>30</li>
<li>31</li>
</ul>
</aside>
</div>
</body>
</html>
You have to add some more classes,
extra css
nav{
width: 100%;
}
.navbar{
float: left
}
.search{
float: right;
}
.clearfix{
clear: both;
}
And nav html little modified
<nav>
<div class="navbar">
<ul class="nav">
<li id="current">Home </li>
<li>ELA </li>
<li> Photos</li>
<li> About</li>
<li> Contact</li>
</ul>
</div>
<div class="search">
<form method="get" action="search-results.php" role="search">
<label for="search"> Search: </label>
<input type="search" size="30">
<input type="submit" value="Search" />
</form>
</div>
<div class="clearfix"></div>
</nav>
Just use the float:right and float:left and then clear:both.
Check this..
In your CSS rules add this:
header {
display: inline-block;
}
div.search {
line-height: 45px;
}
You only need the first one, the second is purely decorative
I've written CSS that should hide the container div in the middle of the page, when the list div on the left is hovered over.
I've got a feeling that giving the container div a fixed position is causing this, but I'm not quite sure. The code seems correct.
Html
<section class="container">
<div class="description">
<h2>Writer</h2>
<p>Lorem ipsum dolor sit amet, suspendisse nam habitasse pellentesque arcu quae dignissim, amet magna diam aenean. Amet ipsum aenean, massa posuere maecenas nam lectus nibh lacus, nisl lacus magna nullam leo quis. Mi elit ante nunc, mi odio congue rhoncus dui quis dictum, lectus eleifend aliquam sed venenatis vitae lorem, potenti non dictum sit. Condimentum nonummy vitae tristique, pede nullam pretium arcu vestibulum dictum</p>
<p>Lorem ipsum dolor sit amet, suspendisse nam habitasse pellentesque arcu quae dignissim, amet magna diam aenean. Amet ipsum aenean, massa posuere maecenas nam lectus nibh lacus, nisl lacus magna nullam leo quis.</p>
</div>
</section>
<div class="list">
<ul class="projectList">
<li class="projectImage">Philomena Kwao<span><img src="helene images/philomena.jpg" alt="" height="" width="" /></span></li>
</ul>
</div>
<div>
css
.container {
position:absolute;
justify-content:center;
align-items:center;
box-sizing:border-box;
display:flex;
width:500px;
left:325px;
align-content:space-around;
}
.list {
width:325px;
margin: 20px 30px 20px 0;
box-sizing:bordr-box;
overflow-x:hidden;
}
ul {
list-style-type:none;
margin:0;
padding:0
}
.projectImage img {
display:none;
}
.list .projectImage:hover img {
display: block;
margin: 0;
top: 20%;
left: 50%;
transform: translate(-50%);
position: absolute;
display: block;
/* width: 100%;
height: 100%; */
}
.list:hover + section.container {
display: none;
}
.list:hover + section.container would only work if .list would be the preceding sibling of section.container. But your section.container is placed before .list.
The only way to make it work is to place .list before section.container. To display section besides .list, I used float: left; on .list.
Working example: https://codepen.io/anon/pen/PmJZgm?editors=1100
Note 1: you might have to tweak the margins/paddings a bit.
Note 2: If you place any content after section, when hiding it the rest of the content will jump up. If you don't want this, you probably want to try
.list:hover + section.container {
opacity: 0;
}
If you move .list before .container, your selector will work. I added a parent element (main) to .list and .container and used flex on the parent instead of using position: absolute on .container to get it beside .list.
#helene, body, html {
width:100%
}
body {
background-color:#FFFAF1;
}
#site {
height:100%;
width:100%;
box-sizing:border-box;
vertical-align:middle;
overflow:hidden;
display:block;
}
.title {
position:fixed:
z-index:10;
text-align:center;
}
.container {
justify-content:center;
align-items:center;
box-sizing:border-box;
display:flex;
flex: 0 0 500px;
align-content:space-around;
}
.list {
flex: 0 0 325px;
margin: 20px 30px 20px 0;
box-sizing:bordr-box;
overflow-x:hidden;
}
ul {
list-style-type:none;
margin:0;
padding:0
}
.projectImage img {
display:none;
}
.list .projectImage:hover img {
display: block;
margin: 0;
top: 20%;
left: 50%;
transform: translate(-50%);
position: absolute;
display: block;
/* width: 100%;
height: 100%; */
}
.list:hover + section.container {
display: none;
}
main {
display: flex;
}
<div id="helene">
<div id="site">
<header class="title">
<h1> Helene Selam Kleih</h1>
</header>
<main>
<div class="list">
<h2>In Conversation With-</h2>
<ul class="projectList">
<li class="projectImage">Philomena Kwao<span><img src="helene images/philomena.jpg" alt="" height="" width="" /></span></li>
<li class="projectImage">Philomena Kwao<span><img src="" alt="" height="" width="" /></span></li>
<li class="projectImage">Philomena Kwao<span><img src="" alt="" height="" width="" /></span></li>
<li class="projectImage">Philomena Kwao<span><img src="" alt="" height="" width="" /></span></li>
<li class="projectImage">Philomena Kwao<span><img src="" alt="" height="" width="" /></span></li>
<li class="projectImage">Philomena Kwao<span><img src="" alt="" height="" width="" /></span></li>
<li class="projectImage">Philomena Kwao<span><img src="" alt="" height="" width="" /></span></li>
<li class="projectImage">Philomena Kwao<span><img src="" alt="" height="" width="" /></span></li>
<li class="projectImage">Philomena Kwao<span><img src="" alt="" height="" width="" /></span></li>
</ul>
<h2>Articles - </h2>
<ul class="projectList">
<li class="projectImage">Philomena Kwao<span><img src="" alt="" height="" width="" /></span></li>
<li class="projectImage">Philomena Kwao<span><img src="" alt="" height="" width="" /></span></li>
<li class="projectImage">Philomena Kwao<span><img src="" alt="" height="" width="" /></span></li>
</ul>
</div>
<section class="container">
<div class="description">
<h2>Writer</h2>
<p>Lorem ipsum dolor sit amet, suspendisse nam habitasse pellentesque arcu quae dignissim, amet magna diam aenean. Amet ipsum aenean, massa posuere maecenas nam lectus nibh lacus, nisl lacus magna nullam leo quis. Mi elit ante nunc, mi odio congue
rhoncus dui quis dictum, lectus eleifend aliquam sed venenatis vitae lorem, potenti non dictum sit. Condimentum nonummy vitae tristique, pede nullam pretium arcu vestibulum dictum</p>
<p>Lorem ipsum dolor sit amet, suspendisse nam habitasse pellentesque arcu quae dignissim, amet magna diam aenean. Amet ipsum aenean, massa posuere maecenas nam lectus nibh lacus, nisl lacus magna nullam leo quis.</p>
</div>
</section>
</main>
</div>
</div>
I'm using flexbox to align 3 items horizontally. The 3 aside items under the section element with the class of .main are aligned across when the viewport is the size of the desktop's.
I want for the three flex-items to stack vertically on top of each other as I manually shrink the viewport on my desktop browser.
I've used display: flex for the parent container as well as flex-direction: row flex-wrap: wrap
My problem is that as I shrink the viewport width, the three flex-items just get narrower as they're next to each other. They don't stack vertically as expected.
Any ideas would help!
here's the html
<!DOCTYPE HTML>
<html>
<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" href = "screen.css">
<title>Creating a Responsive Web Design</title>
</head>
<body>
<div id = "page">
<header>
<a class ="logo" href="#" title="Everyday Things">
<img src="graphics/logo.svg" />
</a>
<div class="hero">
<h1>Add interest with natural textures</h1>
<a class="btn" title="Get advice from top designers" href="#">Get advice from top designers</a>
</div>
</header>
<section class="main">
<aside>
<div class="content">
<h3>What's trending</h3>
<p>Lorem ipsum dolor sit amet, consect etuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis.</p>
</div>
</aside>
<aside>
<div class="content">
<h3>Where to find it</h3>
<p>Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim. Lorem ipsum dolor sit amet, consect.</p>
</div>
</aside>
<aside>
<div class="content">
<h3>Tools of the trade</h3>
<p>Nullam sit amet enim. Lorem ipsum dolor sit amet, consect etuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci rhoncus neque, id pulvinar odio.</p>
</div>
</aside>
</section>
<section class="atmosphere">
<article>
<h2>Creating a modern atmosphere</h2>
<p>Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Lorem ipsum dolor sit amet etuer adipiscing elit. Pulvinar odio lorem non turpis. Nullam sit amet enim lorem.</p>
Learn More
</article>
</section>
<section class="how-to">
<aside>
<div>
<img src="graphics/photo_seating.jpg"/>
<h4>How-To: Seating</h4>
<p>Consectetuer adipiscing elit. Morbi commodo ipsum sed gravida orci magna rhoncus pulvinar odio lorem.</p>
<a title="Learn how to choose the proper seating." href="http://codifydesign.com">Learn more</a>
</div>
</aside>
<aside>
<div>
<img src="graphics/photo_lighting.jpg"/>
<h4>How-To: Lighting</h4>
<p>Morbi commodo, ipsum sed pharetra gravida magna rhoncus neque id pulvinar odio lorem non turpis nullam sit amet.</p>
<a title="Learn how to choose the proper lighting." href="http://codifydesign.com">Learn more</a>
</div>
</aside>
<blockquote>
<p class="quote">Lorem ipsum dolor sit amet conse ctetuer adipiscing elit. Morbi comod sed dolor sit amet consect adipiscing elit.</p>
<p class="credit">Author Name Business Title Company</p>
</blockquote>
</section>
<nav>
<ul>
<li>
About Us
<ul>
<li>
sub-link-one
</li>
<li>
sub-link-two
</li>
<li>
sub-link-three
<ul>
<li>
sub-sub-link-one
</li>
<li>
sub-sub-link-two
</li>
</ul>
</li>
</ul>
</li>
<li>
Design Corner
<ul>
<li>
sub-link-one
</li>
<li>
sub-link-two
</li>
</ul>
</li>
<li>
Products
</li>
<li>
Contact us
</li>
</ul>
</nav>
<footer></footer>
</div>
</body>
</html>
Here's the css:
/* CSS Document for Screens */
#import url('https://fonts.googleapis.com/css?family=Open+Sans');
#import 'reset.css';
/* apply a natural box layout model to all elements, but allowing components to change */
*, *:before, *:after {
box-sizing: inherit;
}
html{
box-sizing: border-box;
font-size: 16px;
}
body{
font-family: 'Open Sans', sans-serif;
}
#page{
margin: 2em;
}
h1, h2, h3, h4{
font-weight: 700;
}
h1{
margin: 0 0 1em 0;
font-size: 2.8em;
}
h2{
margin: 0 0 0.5em 0;
font-size: 1.6em;
}
h3{
font-size: 1.3em;
margin: 0 0 0.5em 0;
}
h4{
font-size: 1em;
margin: 0 0 1.5em 0;
}
p{
margin: 0 0 1em 0;
}
a{
color: #007eff;
}
a:visited{
color: #65b1ff
}
/*header styles*/
header{
background: url('graphics/banner_1200.jpg') center center/cover no-repeat;
display: flex;
height: 430px;
justify-content: space-around;
/*padding: 2em;*/
}
.logo{
height: 66px;
width: 160px;
}
.hero{
flex-basis: 42%;
align-self: center;
}
.hero h1{
color: #fff;
line-height: 1.05em;
}
/*Section styles*/
.main{
margin: 4em;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
}
.main aside{
padding: 0 1%;
flex-basis: 30%;
}
.main aside .content h3{
margin-bottom: 1.45em;
}
.main aside .content p{
line-height: 1.5em;
}
Give them a min-width
.main aside{
padding: 0 1%;
flex-basis: 30%;
min-width: 300px;
}
Sample
/* CSS Document for Screens */
#import url('https://fonts.googleapis.com/css?family=Open+Sans');
#import 'reset.css';
/* apply a natural box layout model to all elements, but allowing components to change */
*, *:before, *:after {
box-sizing: inherit;
}
html{
box-sizing: border-box;
font-size: 16px;
}
body{
font-family: 'Open Sans', sans-serif;
}
#page{
margin: 2em;
}
h1, h2, h3, h4{
font-weight: 700;
}
h1{
margin: 0 0 1em 0;
font-size: 2.8em;
}
h2{
margin: 0 0 0.5em 0;
font-size: 1.6em;
}
h3{
font-size: 1.3em;
margin: 0 0 0.5em 0;
}
h4{
font-size: 1em;
margin: 0 0 1.5em 0;
}
p{
margin: 0 0 1em 0;
}
a{
color: #007eff;
}
a:visited{
color: #65b1ff
}
/*header styles*/
header{
background: url('graphics/banner_1200.jpg') center center/cover no-repeat;
display: flex;
height: 430px;
justify-content: space-around;
/*padding: 2em;*/
}
.logo{
height: 66px;
width: 160px;
}
.hero{
flex-basis: 42%;
align-self: center;
}
.hero h1{
color: #fff;
line-height: 1.05em;
}
/*Section styles*/
.main{
margin: 4em;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
}
.main aside{
padding: 0 1%;
flex-basis: 30%;
min-width: 300px;
}
.main aside .content h3{
margin-bottom: 1.45em;
}
.main aside .content p{
line-height: 1.5em;
}
<!DOCTYPE HTML>
<html>
<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" href = "screen.css">
<title>Creating a Responsive Web Design</title>
</head>
<body>
<div id = "page">
<header>
<a class ="logo" href="#" title="Everyday Things">
<img src="graphics/logo.svg" />
</a>
<div class="hero">
<h1>Add interest with natural textures</h1>
<a class="btn" title="Get advice from top designers" href="#">Get advice from top designers</a>
</div>
</header>
<section class="main">
<aside>
<div class="content">
<h3>What's trending</h3>
<p>Lorem ipsum dolor sit amet, consect etuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis.</p>
</div>
</aside>
<aside>
<div class="content">
<h3>Where to find it</h3>
<p>Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim. Lorem ipsum dolor sit amet, consect.</p>
</div>
</aside>
<aside>
<div class="content">
<h3>Tools of the trade</h3>
<p>Nullam sit amet enim. Lorem ipsum dolor sit amet, consect etuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci rhoncus neque, id pulvinar odio.</p>
</div>
</aside>
</section>
<section class="atmosphere">
<article>
<h2>Creating a modern atmosphere</h2>
<p>Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Lorem ipsum dolor sit amet etuer adipiscing elit. Pulvinar odio lorem non turpis. Nullam sit amet enim lorem.</p>
Learn More
</article>
</section>
<section class="how-to">
<aside>
<div>
<img src="graphics/photo_seating.jpg"/>
<h4>How-To: Seating</h4>
<p>Consectetuer adipiscing elit. Morbi commodo ipsum sed gravida orci magna rhoncus pulvinar odio lorem.</p>
<a title="Learn how to choose the proper seating." href="http://codifydesign.com">Learn more</a>
</div>
</aside>
<aside>
<div>
<img src="graphics/photo_lighting.jpg"/>
<h4>How-To: Lighting</h4>
<p>Morbi commodo, ipsum sed pharetra gravida magna rhoncus neque id pulvinar odio lorem non turpis nullam sit amet.</p>
<a title="Learn how to choose the proper lighting." href="http://codifydesign.com">Learn more</a>
</div>
</aside>
<blockquote>
<p class="quote">Lorem ipsum dolor sit amet conse ctetuer adipiscing elit. Morbi comod sed dolor sit amet consect adipiscing elit.</p>
<p class="credit">Author Name Business Title Company</p>
</blockquote>
</section>
<nav>
<ul>
<li>
About Us
<ul>
<li>
sub-link-one
</li>
<li>
sub-link-two
</li>
<li>
sub-link-three
<ul>
<li>
sub-sub-link-one
</li>
<li>
sub-sub-link-two
</li>
</ul>
</li>
</ul>
</li>
<li>
Design Corner
<ul>
<li>
sub-link-one
</li>
<li>
sub-link-two
</li>
</ul>
</li>
<li>
Products
</li>
<li>
Contact us
</li>
</ul>
</nav>
<footer></footer>
</div>
</body>
</html>
Or use a media query to switch the flex direction
#media screen and (max-width: 600px) {
.main{
flex-direction: column;
}
}
Sample
/* CSS Document for Screens */
#import url('https://fonts.googleapis.com/css?family=Open+Sans');
#import 'reset.css';
/* apply a natural box layout model to all elements, but allowing components to change */
*, *:before, *:after {
box-sizing: inherit;
}
html{
box-sizing: border-box;
font-size: 16px;
}
body{
font-family: 'Open Sans', sans-serif;
}
#page{
margin: 2em;
}
h1, h2, h3, h4{
font-weight: 700;
}
h1{
margin: 0 0 1em 0;
font-size: 2.8em;
}
h2{
margin: 0 0 0.5em 0;
font-size: 1.6em;
}
h3{
font-size: 1.3em;
margin: 0 0 0.5em 0;
}
h4{
font-size: 1em;
margin: 0 0 1.5em 0;
}
p{
margin: 0 0 1em 0;
}
a{
color: #007eff;
}
a:visited{
color: #65b1ff
}
/*header styles*/
header{
background: url('graphics/banner_1200.jpg') center center/cover no-repeat;
display: flex;
height: 430px;
justify-content: space-around;
/*padding: 2em;*/
}
.logo{
height: 66px;
width: 160px;
}
.hero{
flex-basis: 42%;
align-self: center;
}
.hero h1{
color: #fff;
line-height: 1.05em;
}
/*Section styles*/
.main{
margin: 4em;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-between;
}
.main aside{
padding: 0 1%;
flex-basis: 30%;
}
.main aside .content h3{
margin-bottom: 1.45em;
}
.main aside .content p{
line-height: 1.5em;
}
#media screen and (max-width: 600px) {
.main{
flex-direction: column;
}
}
<!DOCTYPE HTML>
<html>
<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" href = "screen.css">
<title>Creating a Responsive Web Design</title>
</head>
<body>
<div id = "page">
<header>
<a class ="logo" href="#" title="Everyday Things">
<img src="graphics/logo.svg" />
</a>
<div class="hero">
<h1>Add interest with natural textures</h1>
<a class="btn" title="Get advice from top designers" href="#">Get advice from top designers</a>
</div>
</header>
<section class="main">
<aside>
<div class="content">
<h3>What's trending</h3>
<p>Lorem ipsum dolor sit amet, consect etuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis.</p>
</div>
</aside>
<aside>
<div class="content">
<h3>Where to find it</h3>
<p>Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim. Lorem ipsum dolor sit amet, consect.</p>
</div>
</aside>
<aside>
<div class="content">
<h3>Tools of the trade</h3>
<p>Nullam sit amet enim. Lorem ipsum dolor sit amet, consect etuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci rhoncus neque, id pulvinar odio.</p>
</div>
</aside>
</section>
<section class="atmosphere">
<article>
<h2>Creating a modern atmosphere</h2>
<p>Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Lorem ipsum dolor sit amet etuer adipiscing elit. Pulvinar odio lorem non turpis. Nullam sit amet enim lorem.</p>
Learn More
</article>
</section>
<section class="how-to">
<aside>
<div>
<img src="graphics/photo_seating.jpg"/>
<h4>How-To: Seating</h4>
<p>Consectetuer adipiscing elit. Morbi commodo ipsum sed gravida orci magna rhoncus pulvinar odio lorem.</p>
<a title="Learn how to choose the proper seating." href="http://codifydesign.com">Learn more</a>
</div>
</aside>
<aside>
<div>
<img src="graphics/photo_lighting.jpg"/>
<h4>How-To: Lighting</h4>
<p>Morbi commodo, ipsum sed pharetra gravida magna rhoncus neque id pulvinar odio lorem non turpis nullam sit amet.</p>
<a title="Learn how to choose the proper lighting." href="http://codifydesign.com">Learn more</a>
</div>
</aside>
<blockquote>
<p class="quote">Lorem ipsum dolor sit amet conse ctetuer adipiscing elit. Morbi comod sed dolor sit amet consect adipiscing elit.</p>
<p class="credit">Author Name Business Title Company</p>
</blockquote>
</section>
<nav>
<ul>
<li>
About Us
<ul>
<li>
sub-link-one
</li>
<li>
sub-link-two
</li>
<li>
sub-link-three
<ul>
<li>
sub-sub-link-one
</li>
<li>
sub-sub-link-two
</li>
</ul>
</li>
</ul>
</li>
<li>
Design Corner
<ul>
<li>
sub-link-one
</li>
<li>
sub-link-two
</li>
</ul>
</li>
<li>
Products
</li>
<li>
Contact us
</li>
</ul>
</nav>
<footer></footer>
</div>
</body>
</html>
Looks like you confused flex-direction: row with flex-direction: column! If you want to stack them in a column, use the column flex direction :)
I'm trying to create a layout - with a left floating div with vertical video/speaker/information divs and a right floating div with chapters - where the containers for chapters and information both cover the rest of the remaining height, with vertical scroll.
An example layout can be found at http://codepen.io/westis/pen/NPLwmy, with the HTML and CSS below. The embedded video is just an example video.
html, body {
font-family: arial, helvetica;
height: 100%;
margin: 0;
}
.title {
font-size: 1.5em;
padding: 0.5em;
margin-top: 0;
margin-bottom: 1em;
border-bottom: 3px solid #000;
text-transform: uppercase;
}
.main-container {
height: 100%;
display: flex;
display: -webkit-flex;
flex-direction: row;
-webkit-flex-direction: row;
}
.left {
width: 59%;
margin-right: 2%;
float: left;
flex-direction: column;
display: flex;
position:relative;
flex-grow: 1;
}
.right {
float: right;
width: 39%;
background: #ff8100;
flex-direction: column;
display: flex;
position:relative;
flex-grow: 1;
}
.video {
position: relative;
padding-bottom: 57.25%;
padding-top: 25px;
height: 0;
z-index: 99;
flex: 1 1 auto;
}
.video iframe, .video video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.speaker-container {
display: block;
width: 100%;
flex: 1 0 auto;
background: #ccc;
}
.speaker {
display: block;
float: left;
padding: 0.5em;
line-height: 1.5em;
}
.main-container h2 {
font-size: 1.5em;
line-height: 1.5;
font-style: normal;
font-weight: 400;
margin: 0;
}
.info-container {
overflow-y: auto;
flex: 1 0.5 auto;
margin-top: 1em;
}
.info {
background: #739bd2;
padding: 0.5em;
}
.chapter-container {
min-height: 200px;
overflow-y: auto;
}
.chapter-list {
padding: 0;
border-bottom: 1px solid #444;
margin: 0;
list-style: none;
}
.chapter {
display: block;
}
.chapter a {
padding: 0.5em 1em;
border-top: 1px solid #000;
text-decoration: none;
color: #000;
display: block;
}
h2 {
flex: 0 0 auto;
}
footer {
clear: both;
background: #000;
color: #fff;
padding: 1em;
}
<h1 class="title">Agenda title</h1>
<div class="main-container">
<div class="left">
<div class="video"><iframe width="560" height="315" src="https://www.youtube.com/embed/lbtxvWsNERY?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe></div>
<div class="speaker-container">
<div class="speaker">Some name
</div>
</div>
<div class="info-container">
<div class="info scrollbox">
<h2 class="info-title">Chapter 1</h2>
<div class="info-text"><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas at lobortis sapien. Vivamus lacinia egestas diam et faucibus. Curabitur ac mi fermentum, sodales arcu a, consectetur ipsum. Cras blandit lorem quis erat viverra, at iaculis enim consectetur. Vestibulum vel fermentum erat. Nam at justo ac elit pellentesque semper. Vivamus fringilla mattis nisl ut convallis. Nullam urna sem, pharetra sit amet hendrerit convallis, facilisis sed tortor. Integer suscipit hendrerit sollicitudin. Phasellus tristique orci enim, sit amet varius nulla faucibus quis.</p>
<p>Fusce massa quam, eleifend a ligula ut, porttitor suscipit turpis. Fusce id metus vitae nisi efficitur consequat in vitae arcu. Phasellus euismod hendrerit euismod. Vivamus maximus, nibh in dignissim viverra, massa eros lobortis lorem, at mollis elit purus at felis. Sed iaculis sed lacus a tristique. Mauris porta sodales massa, vel ultricies eros tristique a. Phasellus dolor justo, porta egestas elementum nec, interdum ut orci. Donec id orci nisl. Quisque sed erat nisi. Etiam ultrices nulla sit amet augue ultrices, ut ornare urna mattis.</p>
<p>Sed tortor ante, bibendum nec justo vel, efficitur tincidunt ex. Vestibulum condimentum neque et tincidunt dignissim. Maecenas eu erat ligula. Morbi quis dui a tortor hendrerit euismod. Aenean nibh odio, maximus sed nibh vitae, sagittis egestas sem. Fusce sapien nulla, malesuada molestie eros et, tristique lobortis libero. Quisque eget purus tortor. Sed eros odio, ultrices id ornare non, varius eu tellus. Morbi ante lectus, aliquam fermentum ligula sed, hendrerit luctus turpis. Duis sem neque, tincidunt ut gravida nec, lobortis at eros. Proin ullamcorper dui eu feugiat egestas. Nulla facilisi. Suspendisse a mollis arcu.</p></div>
</div>
</div>
</div>
<div class="right">
<h2>Chapters</h2>
<div class="chapter-container">
<ul class="chapter-list">
<li class="chapter">chapter 1</li>
<li class="chapter">chapter 2</li>
<li class="chapter">chapter 3</li>
<li class="chapter">chapter 4</li>
<li class="chapter">chapter 5</li>
<li class="chapter">chapter 6</li>
<li class="chapter">chapter 7</li>
<li class="chapter">chapter 8</li>
<li class="chapter">chapter 9</li>
<li class="chapter">chapter 10</li>
<li class="chapter">chapter 11</li>
<li class="chapter">chapter 12</li>
<li class="chapter">chapter 13</li>
<li class="chapter">chapter 14</li>
<li class="chapter">chapter 15</li>
<li class="chapter">chapter 16</li>
<li class="chapter">chapter 17</li>
<li class="chapter">chapter 18</li>
<li class="chapter">chapter 19</li>
<li class="chapter">chapter 20</li>
</ul>
</div>
</div>
</div>
<footer>Some footer</footer>
Using flex I have more or less accomplished what I want. But my questions are:
Is it possible to set a min-height to a flex-item, so that the flex
container increases beyond 100% height? As it is now, the info
container below the video and speaker container disappears when
browser is not tall enough.
Also, I seem to need to put flex-shrink to 0 for the
speaker-container div, or else it does not always show. But when
decreasing the browser height, this means that the
speaker-container (flex item) displays on top of the footer. How
can I avoid that?
The issue that CSS flexbox doesn't work properly in IE 10 and below probably
means I cannot accomplish this kind of layout for those
browsers? Some users will use IE9/IE10 so I would either need a fallback or they'd have to accept only having a page scroll.