Responsive CSS floats to align vertically without any white space on top - css
I am creating an responsive web page. I have two articles floated left and two asides floated right. I would like the two asides to align vertically at the top with the first article. Originally the asides aligned perfectly with the articles as in the HTML I put the asides in between the two articles.
But when making the page responsive, I found that when I tried to collapse the asides to the bottom of the page, beneath the articles, they showed up in the middle of the two articles when I wanted the asides to show up underneath the two articles. So I moved the asides to the bottom of the page in my HTML, and thus my problem was created.
I have tried to clear the floats and to display both the articles and asides with inline-block but I wasn't able to make it work.
EDIT: A person suggested (and then deleted their response?) absolute positioning the asides. I have tried to do this, but I feel like it messes up the responsive design so I would like to avoid it if possible.
Here is the JSfiddle.
#charset"utf-8";
/* CSS Document */
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after, q:before, q:after {
content:'';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
/* End of CSS reset */
/* apply a natural box layout model to all elements, but allowing components to change */
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
/* General styles */
/* Background pattern from Subtle Patterns, by Atle Mo: http://subtlepatterns.com/green-cup/ */
body {
line-height: 1.4;
background-image: url(../images/green_cup.png);
}
.wrapper {
width: 960px;
/* 960px; */
margin: 0 auto;
}
/* Header styles */
header {
font-family:'Playfair Display', serif;
font-size: 23px;
}
.header-text {
margin: 0 auto;
width: 800px;
font-family:'Playfair Display', serif;
text-align: center;
color: #1d464f;
font-size: 2.1em;
/* 50px; */
}
.header-text-below {
margin: 0 auto;
width: 800px;
text-align: center;
font-family:'Merriweather', serif;
font-size: 1.1em;
/* 25px; */
color: #256139;
padding-bottom: 10px;
}
/* End Header styles */
/* Nav */
nav {
width: 100%;
background-color: white;
border-bottom: 4px solid #78605C;
height: 60px;
}
nav ul {
padding-top: 7px;
margin-left: 19%;
}
nav li {
float: left;
display: block;
text-align: center;
list-style-type: none;
width: 19%;
}
nav a {
display: block;
font-family:'Playfair Display', serif;
color: #2A879C;
text-decoration: none;
font-size: 30px;
}
nav a:hover, nav a:focus, nav a:active {
color: #78605C;
}
/* Typography */
h1 {
color: #1d464f;
}
.article-header {
color: #1d464f;
padding-top: 4px;
font-size: 35px;
}
p {
font-family:'Merriweather', serif;
line-height: 1.4em;
font-size: 1em;
}
.date-circle {
font-family:'Merriweather', serif;
border-radius: 50%;
background-color: #78605C;
color: white;
height: 60px;
width: 60px;
float: left;
font-size: 14px;
text-align: center;
padding-top: 20px;
margin-right: 10px;
margin-bottom: 5px;
clear: both;
}
.read-more a {
color: #78605C;
font-family:'Merriweather', serif;
text-decoration: none;
font-weight: bold;
}
.featured {
color: #256139;
font-family:'Merriweather', serif;
font-weight: bold;
font-size: 20px;
}
/* End Typography */
img {
max-width: 100%;
height: auto;
}
/* Articles */
article {
float: left;
display: inline-block;
width: 67.39%;
/* 620px / 960px = 67.39%, target / context = result */
padding: 10px;
padding-top: 10px;
background-color: white;
}
article:nth-of-type(2) {
margin-bottom: 20px;
}
.clear {
clear: left;
}
/* Borders of articles and asides */
article:nth-of-type(1) {
border-top-style: solid;
border-right-style: solid;
border-bottom-style: none;
border-left-style: solid;
border-color: #DED8AA;
border-width: 4px;
}
article:nth-of-type(2) {
border-top-style: none;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-color: #DED8AA;
border-width: 4px;
}
aside:nth-of-type(1) {
border-top-style: solid;
border-right-style: solid;
border-bottom-style: none;
border-left-style: solid;
border-color: #DED8AA;
border-width: 4px;
}
aside:nth-of-type(2) {
border-top-style: none;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-color: #DED8AA;
border-width: 4px;
}
/* End borders */
/* Aside, right side div */
aside {
float: right;
width: 31.25%;
/* 300px / 960px = 31.25%, target / context = result */
padding: 10px;
padding-top: 10px;
background-color: white;
}
/* Font awesome styling, social media icons from: http://fortawesome.github.io/Font-Awesome/ */
.iconContact {
width: 235px;
margin: 0 auto;
}
.iconContact a {
color: #2A879C;
transition: color 0.3s ease;
text-align: center;
float: left;
display: inline-block;
padding: 10px;
}
.iconContact a:hover {
color: #78605C;
}
/* Media queries
Your blog web page should be usable at the following sizes at a minimum:
i. Smartphone – portrait (320px wide)
ii. Smartphone – landscape (480px wide)
iii. Tablet – portrait (768px wide)
iv. Tablet – landscape(1024px wide)
v. Desktop – widths wider than 1024px
*/
#media only screen and (max-width: 1080px) {
main {
width: 90%;
margin: 0 auto;
}
.article-header {
padding-top: 8px;
font-size: 1.2em;
/* 35px; */
}
#media only screen and (max-width: 980px) {
.wrapper {
width: 80%;
/* 960px; */
margin: 0 auto;
}
nav ul {
padding-top: 7px;
margin-left: 0;
}
nav li {
float: left;
display: block;
text-align: center;
list-style-type: none;
width: 25%;
}
.header-text {
margin: 0 auto;
width: 80%;
/* 800px; */
font-family:'Playfair Display', serif;
text-align: center;
color: #1d464f;
font-size: 2.1em;
/* 50px; */
}
.header-text-below {
margin: 0 auto;
width: 80%;
/* 800px; */
text-align: center;
font-family:'Merriweather', serif;
font-size: 1.1em;
/* 25px; */
color: #256139;
padding-bottom: 10px;
}
main {
width: 100%;
margin: 0 auto;
}
.article-header {
padding-top: 8px;
font-size: 1.2em;
/* 35px; */
}
.iconContact a {
padding: 6px;
}
}
#media only screen and (max-width: 920px) {
.iconContact a {
padding: 4px;
}
}
#media only screen and (max-width: 890px) {
.header-text-below {
font-size: 1em;
/* 25px; */
}
}
#media only screen and (max-width: 860px) {
.iconContact a {
padding: 3px;
}
#media only screen and (max-width: 830px) {
.iconContact a {
padding: 2px;
}
}
#media only screen and (max-width: 800px) {
.header-text-below {
font-size: 0.9em;
/* 25px; */
}
.iconContact a {
padding: 1px;
}
#media only screen and (max-width: 890px) {
.header-text-below {
font-size: 1em;
/* 25px; */
}
}
#media only screen and (max-width: 768px) {
aside {
float: none;
width: 100%;
}
article {
width: 100%;
}
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>A Healthy Zest; A food blog begins</title>
<link rel="stylesheet" type="text/css" href="styles/styles.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link href='http://fonts.googleapis.com/css?family=Playfair+Display:400,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Merriweather' rel='stylesheet' type='text/css'>
<!-- Responsive media queries -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<nav>
<ul>
<li>Home
</li>
<li>About
</li>
<li>Recipes
</li>
<li>Contact
</li>
</ul>
</nav>
<div class="wrapper">
<header>
<h1 class="header-text"> A Healthy Zest </h1>
<h2 class="header-text-below"> Carefully curated recipes for those on the go </h2>
</header>
<main>
<!-- Articles, left hand side -->
<article>
<header>
<div class="date-circle">May 02</div>
<h1 class="article-header">Organic Italian pizza</h1>
</header>
<!--- Image in blog post, figure -->
<figure>
<img src="images/pizza-600.jpg" alt="Delicious Italian Cheese and Tomato Pizza" width="600" height="400">
</figure>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent volutpat lectus quis tellus venenatis pellentesque. Vestibulum et aliquam ipsum. Suspendisse dapibus nibh arcu. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed posuere urna ut tortor vulputate porttitor. Maecenas eget ultrices felis, at luctus justo. Etiam blandit placerat lacus vel tristique. Suspendisse ultrices iaculis eros sed molestie. Nulla eget ante eleifend, vulputate nunc in, congue orci. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Proin id tellus dolor. Aenean maximus eros porttitor erat consequat, vel iaculis dui faucibus. Vestibulum aliquet lorem at mi pretium ultricies. Suspendisse tempor pulvinar rutrum. Morbi consequat eget nunc id lobortis. Pellentesque ut tincidunt lectus. In hac habitasse platea dictumst. Duis gravida neque sit amet nunc vestibulum, non interdum ante dictum. Fusce semper pharetra lectus nec auctor. Sed dignissim cursus leo, et porttitor sem porta quis. Etiam facilisis volutpat neque, vitae rutrum purus fermentum vitae. Donec sed nunc dolor. Sed sed rutrum mi. Sed malesuada lobortis aliquet. Praesent vel nisl in massa dictum varius. Nullam nec magna arcu. Vivamus at dolor id neque iaculis rhoncus. Suspendisse aliquet libero felis, vitae tincidunt lectus placerat a. Duis a dictum lacus. Donec ut libero diam. Phasellus scelerisque mattis felis, ut malesuada neque pellentesque et. In arcu sem, convallis ac fermentum sed, consequat et tellus. Donec eu orci quis sapien aliquet porttitor sit amet eu metus. Etiam non sodales risus. Suspendisse placerat sem eu dolor porta tempor.</p>
<p class="read-more"> Read more...
</p>
</article>
<article>
<header>
<div class="date-circle">April 08</div>
<h1 class="article-header">Healthy whole-grain sandwich</h1>
</header>
<!--- Image in blog post, figure -->
<figure>
<img src="images/sandwich-600.jpg" alt="Healthy sandwich with lettuce, egg and cream cheese" width="600" height="400">
</figure>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent volutpat lectus quis tellus venenatis pellentesque. Vestibulum et aliquam ipsum. Suspendisse dapibus nibh arcu. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed posuere urna ut tortor vulputate porttitor. Maecenas eget ultrices felis, at luctus justo. Etiam blandit placerat lacus vel tristique. Suspendisse ultrices iaculis eros sed molestie. Nulla eget ante eleifend, vulputate nunc in, congue orci. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Proin id tellus dolor. Aenean maximus eros porttitor erat consequat, vel iaculis dui faucibus. Vestibulum aliquet lorem at mi pretium ultricies. Suspendisse tempor pulvinar rutrum. Morbi consequat eget nunc id lobortis. Pellentesque ut tincidunt lectus. In hac habitasse platea dictumst. Duis gravida neque sit amet nunc vestibulum, non interdum ante dictum. Fusce semper pharetra lectus nec auctor. Sed dignissim cursus leo, et porttitor sem porta quis. Etiam facilisis volutpat neque, vitae rutrum purus fermentum vitae. Donec sed nunc dolor. Sed sed rutrum mi. Sed malesuada lobortis aliquet. Praesent vel nisl in massa dictum varius. Nullam nec magna arcu. Vivamus at dolor id neque iaculis rhoncus. Suspendisse aliquet libero felis, vitae tincidunt lectus placerat a. Duis a dictum lacus. Donec ut libero diam. Phasellus scelerisque mattis felis, ut malesuada neque pellentesque et. In arcu sem, convallis ac fermentum sed, consequat et tellus. Donec eu orci quis sapien aliquet porttitor sit amet eu metus. Etiam non sodales risus. Suspendisse placerat sem eu dolor porta tempor.</p>
<p class="read-more">
Read more...
</p>
</article>
<!-- Aside, right sidebar, author bio-->
<aside>
<!-- Social media icons -->
<div class="iconContact">
<a href="#">
<i class="fa fa-facebook fa-3x"></i>
</a>
</div>
<div class="iconContact">
<a href="#">
<i class="fa fa-twitter fa-3x"></i>
</a>
</div>
<div class="iconContact">
<a href="#">
<i class="fa fa-instagram fa-3x"></i>
</a>
</div>
<div class="iconContact">
<a href="#">
<i class="fa fa-pinterest fa-3x"></i>
</a>
</div>
<!-- Social media icons end -->
<figure>
<img src="images/author-300.png" alt="Picture of the author of the food blog" width="300" height="294">
</figure>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent volutpat lectus quis tellus venenatis pellentesque. Vestibulum et aliquam ipsum. Suspendisse dapibus nibh arcu. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed posuere urna ut tortor vulputate porttitor. Maecenas eget ultrices felis, at luctus justo. Etiam blandit placerat lacus vel tristique.</p>
</aside>
<!-- Aside, right sidebar, featured posts -->
<aside>
<h1 class="featured">Featured Posts</h1>
<a href="#">
<figure>
<img src="images/smoothie-300.jpg" alt="Delicious Green Smoothie with bananas and strawberries on the side" width="300" height="200">
</figure>
</a>
<a href="#">
<figure>
<img src="images/oatmeal-300.jpg" alt="Healthy oatmeal with bananas and nuts sprinkled on top" width="300" height="200">
</figure>
</a>
</aside>
<div class="clear"></div>
</div>
<!-- end wrapper -->
</main>
<footer class="clear"></footer>
</body>
</html>
I suggest using the flexible box model to accomplish what you want.
Remove all floats.
Turn your containing element <main> into a flexbox container:
main {
display: flex;
}
Put all of your left side content into a <div id="left"> and all of your right side content into <div id="right">.
Now lets remove the grow and shrink properties from these divs:
#left, #right {
flex-grow: 0;
flex-shrink: 0;
}
Now when you want to use a mobile layout, you can have your media queries set flex-direction: column; and flex-grow: 1; and your right side content will drop down underneath your left side content.
You will probably need to move some of your attributes that you gave to each article and aside into their respective left/right column tag.
Here is a jsfiddle
This is a great reference for flexboxes.
Related
CSS grid layout appears to float left?
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!
Columns not behaving correctly on small screen
I have a web page which displays 2 columns. On a PC the two columns display exactly as I want them, but something goes wrong when viewed on a mobile screen. On mobile screen I want the second column to drop below the first column and I want both columns to be centered on the screen, but what happens is that the first column is on the left of the screen and the second column (which is a Facebook feed) is too wide for the screen, even though I set the width at 80%. Here is my html: <div class="section group"> <div class="col span_1_of_2"> <img class="img11" src="images/trout.jpg" alt="trout" title="The Trout Inn"> <hr style="width: 100%"/> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer finibus neque eu felis condimentum ullamcorper. Aliquam erat volutpat. Phasellus viverra lectus dignissim ex ultricies ornare. Donec interdum massa non neque consectetur, eget molestie libero faucibus. Nulla gravida finibus libero, eu dictum turpis porta a. Donec ex tellus, dictum et massa eget, mattis suscipit justo. Vivamus tempus enim at nibh lobortis semper vitae sed mi. Mauris efficitur ipsum a nulla ultricies, sed ultrices ligula dignissim </div> <div class="col span_2_of_2"> <label>Our Facebook Feed</label> <iframe src="https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2Ftesttest%2F&tabs=timeline&width=340&height=1000&small_header=true&adapt_container_width=true&hide_cover=false&show_facepile=true&appId=999999" width="340" height="1000" style="border:none;overflow:hidden" allow="encrypted-media"></iframe> </div> </div><!-- section group --> and here is my css: /* SECTIONS */ .section { clear: both; padding: 0px; margin: auto; width: 60%; } /* COLUMN SETUP */ .col { display: block; float:left; margin: 1% 0 1% 1.6%; } .col:first-child { margin-left: 0; } /* GROUPING */ .group:before, .group:after { content:""; display:table; } .group:after { clear:both; } .group { zoom:1; /* For IE 6/7 */ } /* GRID OF TWO */ .span_1_of_2 { width: 63.1%; padding-right: 15px; border-right-style: solid; border-color: #444444; border-width: 1px; } .span_2_of_2 { width: 32.2%; } /* IF screen is LESS THAN 480 PIXELS */ #media only screen and (max-width: 480px) { /* SECTIONS */ .section { clear: both; padding: 0px; margin: auto; width: 90%; } /* COLUMN SETUP */ .col { display: block; margin: auto; } .col:first-child { margin-left: 0; } /* GROUPING */ .group:before, .group:after { content:""; display:block; margin: auto; } .group:after { clear:both; } /* GRID OF THREE */ .span_1_of_2 { padding: 0px; border: none; display: block; margin: auto; width: 70%; } .span_2_of_2 { padding: 0px; border: none; display: block; margin: auto; width: 50%; } } I have tried changing lots of parameters in the css but cannot make it work and now I am lost for options. Can anyone help me to get these columns aligned? Many Thanks Tog
by using flex & flex direction you can change how the columns are placed. you can read more here https://css-tricks.com/snippets/css/a-guide-to-flexbox/ .section{display:flex;flex-direction:column;} .span_1_of_2{flex:1;padding:5px;} .span_2_of_2{flex:1;padding:5px} #media screen and (min-width:768px){ .section{display:flex;flex-direction:row;} } <div class="section group"> <div class="col span_1_of_2"> <img class="img11" src="images/trout.jpg" alt="trout" title="The Trout Inn"> <hr style="width: 100%"/> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer finibus neque eu felis condimentum ullamcorper. Aliquam erat volutpat. Phasellus viverra lectus dignissim ex ultricies ornare. Donec interdum massa non neque consectetur, eget molestie libero faucibus. Nulla gravida finibus libero, eu dictum turpis porta a. Donec ex tellus, dictum et massa eget, mattis suscipit justo. Vivamus tempus enim at nibh lobortis semper vitae sed mi. Mauris efficitur ipsum a nulla ultricies, sed ultrices ligula dignissim </div> <div class="col span_2_of_2"> <label>Our Facebook Feed</label> <iframe src="https://www.facebook.com/plugins/page.php?href=https%3A%2F%2Fwww.facebook.com%2Ftesttest%2F&tabs=timeline&width=340&height=1000&small_header=true&adapt_container_width=true&hide_cover=false&show_facepile=true&appId=999999" width="340" height="1000" style="border:none;overflow:hidden" allow="encrypted-media"></iframe> </div> </div><!-- section group -->
Div should not be over Div with background image with divs inside
Div should not be over Div with background image with divs inside, but for some reason the about div is displayed over the nav: body { margin: 0; padding: 0; /*background-color: blue;*/ } .divider { background-color: #be2b27; width: 100%; height: 100px; position: absolute; display: block; padding: 0; } .divider h1 { font-family: "Nexa Light"; font-size: 2em; color: white; text-align:left; padding-left: 10px; } .lorem-text { font-family: "Menlo"; font-size: 1.2em; color: white; } .start-section { margin-top: 30px; /* position: absolute; */ padding-left: 20px; padding-top: 20px; } #start-bg { background-image: url(water.jpg); background-color:#9abee1; background-repeat: round; height:100%; position: absolute; } #home-head { font-family: 'Nexa Light'; /* font-size: ; */ padding-top: 30px; color: white; } .nav { } <div id="start-bg"> <!--<div class="nav"...>...</div>--> <div class="start-section"> <h1 id="home-head">Landing Page</h1> <p class="lorem-text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ornare est in maximus vestibulum. Mauris eu tincidunt quam.<br> In commodo neque id tortor mattis, non consectetur ante tincidunt. Nunc ultrices ultricies purus, id finibus justo eleifend sit amet.<br> Sed in iaculis libero, et gravida nibh. Proin mollis, nibh eu rhoncus scelerisque, orci ex posuere mi, id pharetra purus est suscipit sapien. Aliquam fermentum dignissim ultricies. Cras vitae neque tincidunt, tristique neque at, ornare leo.<br> Integer gravida lectus sed venenatis auctor. Vestibulum sed ligula eget dui ultrices luctus.<br> Etiam dapibus auctor sollicitudin. Nam vel dui non lorem semper scelerisque. Donec sed condimentum mauris. Maecenas ac enim sit amet orci sodales porta. </p> <img src="http://via.placeholder.com/350x150"> <img src="http://via.placeholder.com/350x150"> <img src="http://via.placeholder.com/350x150"><br> <img src="http://via.placeholder.com/350x150"> <img src="http://via.placeholder.com/350x150"> <img src="http://via.placeholder.com/350x150"><br> </div> </div> <div class="divider"> <h1>About</h1> </div> There must be something wrong with the positions or something or the fact that when the div has a background image it is not registered as holding any content so the about div is displayed above it. What do I need to do? I want the div to be displayed after the background image ends and stays there when I remove the images. If you need the nav html and css code i will give it to you.
#start-bg { background-image: url(water.jpg); background-color:#9abee1; background-repeat: round; height:100%; position: absolute; } If you remove: position: absolute; Red bar go to bottom bottom of the page.
Cant get my custom font to display
I'm back, and doing yet another school project. I'm trying to get my site to use some custom font that I found online. This is my JSFiddle link to my code, and my HTML code is as follows: <!doctype html> <html> <head> <title> | Bat-tection | </title> <meta charset="utf-8"> <link href="Styles/index.css" rel="stylesheet" type="text/css"> </head> <body> <div id="wrapper"> <header> <h1 id="title"> Bat-Tection </h1> <h6 id="ctrtitle"> The only home protection service you will ever need! </h6> <nav> <ul> <li>Home</li> <li>About</li> <li>Products</li> <li>Services</li> <li>Contact</li> </ul> </nav> </header> <aside> <p>The Sidebar Content</p> <p>The Sidebar Content</p> <p>The Sidebar Content</p> <p>The Sidebar Content</p> <p>The Sidebar Content</p> <p>The Sidebar Content</p> <p>The Sidebar Content</p> </aside> <section class="text"> <article> <h2>Article One Heading</h2> <p> Article One Content<img src="../Tuts/Images/pic07.jpg" alt="A Generic Image Caption Here" class="rgt"> </p> <p> Vestibulum mi felis, sollicitudin nec iaculis at, facilisis a dolor. Curabitur posuere vulputate egestas. Vestibulum a leo id sapien commodo aliquam commodo quis dui. Phasellus at leo id elit dignissim egestas a eu elit. Quisque bibendum tellus at placerat luctus. Nulla blandit erat ipsum, eu molestie purus sollicitudin sit amet. Sed vehicula tortor quis libero finibus fringilla. Nam nibh mauris, lacinia a suscipit et, fringilla non lorem. Vestibulum tempor vel ligula ut interdum. Donec convallis porttitor est sit amet porttitor. Sed ullamcorper mauris nibh, id fermentum velit iaculis quis. Etiam rutrum blandit hendrerit. Proin a laoreet purus. </p> <p> Curabitur sed leo ligula. Duis sed bibendum mi. Quisque fermentum, lacus in suscipit vulputate, tellus eros tempus metus, non convallis justo augue et turpis. Sed ut tempor elit. Pellentesque congue turpis turpis, nec lobortis arcu sollicitudin non. Nunc pellentesque luctus massa ac faucibus. Nulla ac libero ut diam consectetur euismod sed eget odio. Phasellus maximus justo eget ultricies consectetur. Curabitur nec mi lectus. Nunc vel varius enim. Praesent pulvinar nisi volutpat, facilisis ligula at, volutpat lorem. Mauris nec cursus libero, eget dictum arcu. Praesent tristique lacinia erat sed vestibulum. Cras vestibulum tellus vel urna bibendum eleifend. Proin non nisi ut sapien mattis blandit ut in tellus. Maecenas congue magna nec purus suscipit, in pellentesque quam blandit. </p> </article> <p class="spec"></p> <article class="cols"> <h2 class="cols-span">Lorem ipsum dolor sit</h2> <p class="lead cols-span"> Vestibulum mi felis, sollicitudin nec iaculis at, facilisis a dolor. </p> <p> Curabitur sed leo ligula. Duis sed bibendum mi. Quisque fermentum, lacus in suscipit vulputate, tellus eros tempus metus, non convallis justo augue et turpis. Sed ut tempor elit. Pellentesque congue turpis turpis, nec lobortis arcu sollicitudin non. Nunc pellentesque luctus massa ac faucibus. Nulla ac libero ut diam consectetur euismod sed eget odio. Phasellus maximus justo eget ultricies consectetur. Curabitur nec mi lectus. Nunc vel varius enim. Praesent pulvinar nisi volutpat, facilisis ligula at, volutpat lorem. Mauris nec cursus libero, eget dictum arcu. Praesent tristique lacinia erat sed vestibulum. Cras vestibulum tellus vel urna bibendum eleifend. Proin non nisi ut sapien mattis blandit ut in tellus. Maecenas congue magna nec purus suscipit, in pellentesque quam blandit. </p> </article> </section> <aside class="ads"> <p> Advertisment can run the size out to the margin of the previous container element, no more! </p> <p> Advertisment </p> <p> Advertisment </p> <p> Advertisment </p> <p> Advertisment </p> <p> Advertisment </p> </aside> <footer> <p> Copyright © 2016 All Right Reserved </p> </footer> </div> </body> </html> My CSS code is as follows: #charset "utf-8"; /*Browser Reset*/ body, p, header, aside, section, article, h1, h2, h3, nav, div, footer{ padding: 0; margin: 0; } /*Style Start*/ #font-face { font-family: battext; src: url(../Fonts/batmfa.eot), /* IE9 Compat Modes */ src: url(../Fonts/batmfa.eot?#iefix) format(embedded-opentype), /* IE6-IE8 */ url(../Fonts/batmfa.woff2) format(woff2), /* Super Modern Browsers */ url(../Fonts/batmfa.woff) format(woff), /* Pretty Modern Browsers */ url(../Fonts/batmfa.ttf) format(truetype), /* Safari, Android, iOS */ url(../Fonts/batmfa.svg#svgFontName) format(svg); /* Legacy iOS */ } .ads{ float: right; text-align: center; font-size: 90%; color: #b498989; } .ads p{ background-color: #29292C; padding-top: 0.3em; } aside{ overflow: hidden; max-width: 200px; float: left; min-height: 900px; background-color: #29292C; } aside p{ padding: 0px 20px; } article p{ text-indent: 2em; padding-left: 1.5em; } body{ font-family: "battext"; color: #FFFD5D; background-color: #252122; font: 100% Verdana; } #ctrtitle{ text-align: center; } .cols{ /*-webkit-column-count: 3; -moz-column-count: 3; column-count: 3; -webkit-column-gap: 10px; -moz-colum-gap: 10px; column-gap: 10px;*/ -webkit-column-width: 200px; -moz-column-width: 200px; column-width: 200px; } .cols-span{ -webkit-coloumn-span: all; -moz-column-span: all; column-span: all; font-size: 1.2em; margin-bottom: 0.2em; line-height: 1.2em; } .cols p{ margin-bottom:1.1em; text-align: justify; } footer{ clear: both; background-color: #29292C; text-align: center; font-size: 85%; min-height: 100px; } footer p{ padding-top: 3%; } header{ background-color: #29292C; padding-bottom: 1em; } header h1{ text-align: center; color: #252122; font-weight: 900; font-size: 2.5em; margin: 0 0 1em 0; } .lead{ font-family: Georgia; font-size: 1.3em; text-align: left; font-style: italic; } nav ul{ text-align: center; margin: 1em; list-style: none; } nav ul li{ display: inline-block; margin: 0 0.35em; nav ul li a{ background-image: url(../Images/bat-button1.jpg); background-size:contain; background-position: center; background-repeat: no-repeat; border-radius: 5px; color: #e1e2dd; text-decoration: none; padding: 0.6em 1.2em 0.6em 1.2em; outline: 0; } nav ul li a:hover{ background-image: url(../Images/bat-button2.jpg); background-size:contain; background-position: center; background-repeat: no-repeat; } nav ul li ul{ display: none; } p{ margin-bottom: 1.2em; } .rgt{ float: right; max-width: 30%; padding: 0.3em; } section{ padding: 10px; float: left; max-width: 65%; } .spec{ margin: -5px 0 10px 0; border-bottom: 1px dashed #000000; line-height: 0; } .text{ text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000; } #title{ color: #FFFD5D; } #wrapper{ max-width: 1200px; margin: 0 auto; background-color: #403E3A; } Can you guys off me any help? Thanks, -dark_nemesis
what i understand from your question is that you want to know how to use fonts, isn't it? you can always visit https://www.google.com/fonts and under every font there is a button about how to use this font.
You're just missing a line of code (I think) it is font-family: battext, sans-serif; If you insert that under the body element as well as the font-face. Then I think it will work. Hope this helps...
take the quotations off the css font-family: "battext" side note, check to make sure you have right to use it in whatever you're doing also check to make sure the file path is correct. If your structure is like this: (upper case = folders) HTML index.html CSS styles.css FONT myfont.ttf then.. these should be your code html: <link type="text/css" rel="stylesheet" href="../css/styles.css" /> take off "../" if index.html is same level as CSS/FONT folder css: #font-face { font-family: myfont; src: url(../font/myfont.ttf); } the src for css will start where in the folder it's in, so styles.css has to go back a directory, then go to font and your file
How to create horizontal lists using display:inline?
I'm trying to create a horizontally displayed list of services, however display: inline isn't working. How do I display the li's horizontally? #services { border-top: 1px solid #202020; padding-top: 40px; } #services p span { font-family: nevis-webfont; font-size: 112.5%; font-weight: normal; letter-spacing: 1px; text-transform: uppercase; } #services ul { width: 160px; } #services ul li { display: inline; } #services ul li h2 { padding-top: 20px; text-align: center; } <div id="services"> <p><span>Services</span></p> <ul> <li><h2>HEADING</h2><p>Nulla et diam risus. Praesent vestibulum augue non purus tincidunt placerat. Sed in orci leo. Duis dignissim nibh vitae lacus placerat et posuere</p></li> <li><h2>HEADING</h2><p>Nulla et diam risus. Praesent vestibulum augue non purus tincidunt placerat. Sed in orci leo. Duis dignissim nibh vitae lacus placerat et posuere</p></li> <li><h2>HEADING</h2><p>Nulla et diam risus. Praesent vestibulum augue non purus tincidunt placerat. Sed in orci leo. Duis dignissim nibh vitae lacus placerat et posuere</p></li> <li><h2>HEADING</h2><p>Nulla et diam risus. Praesent vestibulum augue non purus tincidunt placerat. Sed in orci leo. Duis dignissim nibh vitae lacus placerat et posuere</p></li> </ul> <div class="next"> <img src="img/next.png" alt="Click for more information" /> </div><!-- end next -->
They are not showing horizontally, or arranging themselves 'inline' with any noticeable difference due to the ul being too wide to allow more than one li to show in that horizontal space. the issue is here #services ul { width: 160px; } remove this width restriction to allow more than one li to fit horizontally. Furthermore, to achieve the effect I believe you are looking for, try settings a set width for the list items and and settings the display to inline-block rather than inline. This will create the horizontal blocks that I believe you are attempting to achieve. Example: http://jsfiddle.net/xPCBK/1/ The css you need to change: #services ul { width: 160px; } #services ul li { display: inline; } Change this to #services ul { } #services ul li { display: inline-block; width: 160px; }