Why doesn't my css grid columns work on my navigation? - html

I'm brushing up on Responsive Grid CSS on YouTube. Following along with the instructors lesson. I'm having trouble formatting my nave grid. I've included both the html and css code along with pictures of his nav results vs mine. Any help would be appreciated.
I'm trying to get the navigation bar in a 4 column grid. I'm trying to see what I'm missing here.
Instructor Results:
My Results:
/* CSS Variables */
:root {
--primary: #ddd;
--dark: #333;
--light: #fff;
--shadow: 0 1px 5px rgba(104, 104, 104, 0.8);
}
html {
box-sizing: border-box;
font-family: Arial, Helvetica, san-serif;
color: var(--dark);
}
body {
background: #ccc;
margin: 30px 50px;
line-height: 1.4;
}
.btn {
background: var(--dark);
color: var(--light);
padding: 0.6rem 1.3rem;
text-decoration: none;
border: 0;
}
img {
max-width: 100%;
}
.wrapper {
display: grid;
grid-gap: 20px;
}
/* Navigation */
.main-nav ul {
display: grid;
grid-gap: 20px;
padding: 0px;
list-style: none;
grid-template-columns: repeat(4, 1fr);
}
<div class="wrapper">
<!-- Navigation -->
<nav class="main-nav">
<ul>
<li><a href="#">Home</li>
<li><a href="#">About</li>
<li><a href="#">Services</li>
<li><a href="#">Contact</li>
</ul>
</nav>
<!-- Top Container -->
<section class="top-container">
<header class="showcase">
<h1>Damn That Looks Delicious</h1>
<p> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Aliquam sem et tortor consequat id porta.
</p>
Read More
</header>
<div class="top-box top-box-a">
<h4>Membership</h4>
<p class="price">$199/mo</p>
Buy Now
</div>
<div class="top-box top-box-b">
<h4>Pro Membership</h4>
<p class="price">$299/mo</p>
Buy Now
</div>
</section>
<!-- Boxes Section -->
<section class="boxes">
<div class="box">
<i class="fas fa-pizza-slice fa-4x"></i>
<h3>Restaurants</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="box">
<i class="fas fa-utensils fa-4x"></i>
<h3>Chefs</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="box">
<i class="fas fa-hamburger fa-4x"></i>
<h3>Catering</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
<div class="box">
<i class="fas fa-ice-cream fa-4x"></i>
<h3>Sweets</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
</div>
</section>
<section>
<img src="images/dtld.jpg" alt="">
<div>
<h2> Your Business On DTLD</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
Learn More
</div>
</section>
<!-- Portfolio Section -->
<section class="portfolio">
<img src="https:/source.unsplash.com/random/200x200" alt="">
<img src="https:/source.unsplash.com/random/201x200" alt="">
<img src="https:/source.unsplash.com/random/202x200" alt="">
<img src="https:/source.unsplash.com/random/203x200" alt="">
<img src="https:/source.unsplash.com/random/204x200" alt="">
<img src="https:/source.unsplash.com/random/205x200" alt="">
<img src="https:/source.unsplash.com/random/206x200" alt="">
<img src="https:/source.unsplash.com/random/207x200" alt="">
<img src="https:/source.unsplash.com/random/208x200" alt="">
</section>
<!-- Footer -->
<footer>
<p> Damn That Looks Delicious © 2005</p>
</footer>
</div>
<!-- Wrapper Ends -->

Once you add the closing tag to your anchor elements the layout works as you expect.
This is what you have now:
.main-nav ul {
display: grid;
grid-gap: 20px;
padding: 0px;
list-style: none;
grid-template-columns: repeat(4, 1fr);
}
<nav class="main-nav">
<ul>
<li><a href="#">Home</li>
<li><a href="#">About</li>
<li><a href="#">Services</li>
<li><a href="#">Contact</li>
</ul>
</nav>
Because the anchor elements are left open (creating invalid HTML code), the browser generates four additional grid items. Now the grid container has eight children: 4 li and 4 a.
Since your code allows for only four items per row, a second row is created to accommodate the other four items. In fact, you always had a four-column grid.
Once you close the anchor tags (creating valid HTML code), only four grid items are rendered.
.main-nav ul {
display: grid;
grid-gap: 20px;
padding: 0px;
list-style: none;
grid-template-columns: repeat(4, 1fr);
}
<nav class="main-nav">
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
</ul>
</nav>
Also, you may want to see my answer here for a brief analysis and suggestion regarding unordered lists inside nav elements.

There is missing of closing anchor </a> tag in your code so once you add closing anchor tag in it. Your code will run perfectly.
screenshot of missing anchor tag

Related

How do I make the container of this resume I created using html and css response in a way that if I make the browser smaller, it will follow?

So, I created this resume using HTML and CSS and I wanted to it responsive in a way that if I change the browser size, the contents including the container will adjust. I'm new to this so I'm not sure.
This is how it looks when I change the size of my browser. As you can see, the contents and container become messy
#import url('https://fonts.googleapis.com/css2?family=Catamaran:wght#400;500;600;700;800;900&display=swap');
body
{
background: #f0966b;
font-family: 'Catamaran', sans-serif;
margin: 30px 250px;
}
.name
{
font-size: 35px;
font-weight: 800;
}
.container
{
display: grid;
padding: 30px;
grid-column-gap: 1em;
grid-row-gap: 1em;
background-color: #f8f8f8;
max-width: 100%;
min-height: 100px;
}
.header
{min-height: 100px;
display: grid;
grid-template-columns: 70% 30%;
}
.subheader
{
font-size: 19px;
font-weight: 700;
}
.left-right
{
display: grid;
grid-template-columns: 50% 50%;
margin-top: 25px;
}
.footer
{
display: grid;
grid-template-columns: repeat(3, 1fr);
margin-top: 1px;
grid-column-gap: 2em;
}
span
{
font-weight: 600;
}
<!DOCTYPE html>
<html>
<head>
<title>Sample</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="./sample.css">
<link href="https://fonts.googleapis.com/css2?family=Catamaran:wght#400;500;600;700;800;900&display=swap" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="header">
<p class="name">
Hello. <br>
I'm <span style="color: #e9692c; ">
Name Surname.
</span>
</p>
<img src="https://i.pinimg.com/1200x/ec/de/63/ecde631ccc34c9b8086dbf7956f88eae.jpg" width="200" height="auto">
</div>
<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.
</div>
<div class="left-right">
<div>
<div class="subheader">
Skills
<div>━</div>
</div>
<div>
● Graphic Design<br>
● Web Design<br>
● Web Development<br>
● Adobe Illustrator<br>
● Adobe Photoshop<br></div>
</div>
<div>
<div class="subheader">
<div class="exp">
Experience
<div>━</div>
</div></div>
<div>
<strong>2xxx-PRESENT</strong> <br>
<span style="color: #e9692c;">POSITION</span><br>
<span>COMPANY INC.</span>
<div>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</div>
</div>
</div>
<div><br>
<div class="subheader">
Education
<div>━</div>
</div>
<div>2xxx-2xxx | M.A <br>
<span style="color: #e9692c;">FRONT-END <br></span>
University</div><br>
<div>2xxx-2xxx | B.S <br>
<span style="color: #e9692c;">INFORMATION TECHNOLOGY <br></span>
University</div>
</div>
<div>
<div class="subheader"><br>
Works
<div>━</div>
</div>
<div>
Sprite Animation using HTML & CSS<br>
Blog Site
</div>
</div>
<div><br>
<div class="subheader">
Hobbies & Interests
<div>━</div>
</div>
<div>
Web Design <br>
Digital Illustration <br>
Animation <br>
Video Editing <br>
Programming <br>
</div>
</div>
</div>
<div><hr></div>
<div class="footer">
<div>email</div>
<div>contact no.</div>
<div>linkedin</div>
</div>
</body>
</html>
</body>
</html>
The issue is body margin size. Make that margin as %
body{margin: 30px 250px;}
body{margin: 30px 2%;} //Use This

Image should not use full-width in element

At the moment I am trying to program the wireframe I have made, but experience some problems with specially the left side of the element:
The problem is that the 200x200px image is going full width in the left column. Therefore I cannot center the image.
I can see it can be changed with overwriting the following CSS, and set the width to none;.
.cms-area img {
width: 100%;
}
But as I see it will break the reponsive on the images?
Can anybody help me in goal here?
See the [Testpage here][2].
The site is still using Bootstrap 3, and I do not have access to change the main CSS. Therefore I need to overwrite CSS if I need that.
Best regards
<style>
#front .row {
padding-bottom: 0px;
}
.row [class*="col-"] {
padding-right: 7.5px;
padding-left: 7.5px;
}
.padding-white-bg {
padding: 15px;
background-color: #fff;
margin-bottom:30px;
border: 1px solid #ebecf0;
}
.padding-twocolumn-bg {
margin-bottom:30px;
}
.padding-grey-bg {
padding: 7.5px;
}
.padding-white-border {
border: 1px solid #ebecf0;
}
.top-pad-d {
padding-top: 15px;
}
.sbp-2-column {
background-color:#fff;
padding-top:15px;
padding-bottom:15px;
border:1px solid #ebecf0;
}
/********************************/
/* Product styling */
/********************************/
/* Make spot image go full width */
.cms-area .result-cols ul.items li.add-item {
width: 100% !important;
}
.cms-area .result-cols ul.items li.add-item .item {
padding: 0px;
}
/* Remove add to basket button */
.cms-area .result-cols ul.items li.add-item a.button-add {
display:none;
}
/* Set height on product description */
.cms-area .result-cols ul.items li.add-item .desc {
height: 0px;
overflow: visible;
}
/* Remove fade on product headline */
.cms-area .result-cols ul.items li.add-item .desc:after {
background: none;
}
.cms-area .result-cols .more-wrap {
padding-bottom: 0px;
}
/* Remove Sub-heading */
.desc2{
display:none;
}
/* Remove product text */
.ext-description {
display:none;
}
/* Remove padding multiple products on row */
.cms-area .result-cols {
padding:0px;
}
/********************************/
/* Custom Buttons */
/********************************/
.btn.btn-lg {padding: 10px 40px;}
.btn.btn-hero,
.btn.btn-hero:hover,
.btn.btn-hero:focus {
color: #f5f5f5;
background-color: #1abc9c;
border-color: #1abc9c;
outline: none;
margin: 20px auto;
}
/********************************/
/* Media Queries */
/********************************/
#media screen and (min-width: 980px){
.hero { width: 980px; }
}
#media screen and (max-width: 640px){
.hero h1 { font-size: 4em; }
}
#media screen and (max-width: 896px){
.top-pad-m {
padding-top: 15px;
}
}
#media only screen and (max-width: 1280px) {
.fade-carousel .slides .slide-1,
.fade-carousel .slides .slide-2,
.fade-carousel .slides .slide-3 {
height: 60vh;
}
}
/********************************/
/* Overall Styling */
/********************************/
#sbp-hr {
margin-top:10px !important;
margin-bottom:10px !important;
}
.sbp-align {
text-align: left;
padding-left:10px;
}
.test {
padding:20px 20px 20px 20px;
}
/* TEST on 2 column */
.classWithPad { margin:8px; padding:10px; background-color: #fff; border:1px solid #ebecf0;}
.cms-area img {
max-width: 100%;
}
</style>
<div class="wrapper">
<!-- Section 7 -->
<div class="section padding-twocolumn-bg">
<div class="row">
<div class="text-center col-md-6">
<div class="classWithPad">
<p style="padding:75px;">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<a><img src="https://placehold.it/200x200" class="img-responsive test"></a>
</div>
</div>
<div class="text-center col-md-6">
<div class="classWithPad">
<div class="row">
<div class="col-sm-12">
<h3 class="sbp-align">Headline</h3>
<hr>
</div>
<div class="col-sm-6">
<img src="https://placehold.it/250x150" style="padding:10px;">
<h4 class="sbp-align">Subline</h4>
<p class="sbp-align">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<hr id="sbp-hr">
Read more
</div>
<div class="col-sm-6">
<img src="https://placehold.it/250x150" style="padding:10px;">
<h4 class="sbp-align">Subline</h4>
<p class="sbp-align">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<hr id="sbp-hr">
Read more
</div>
</div>
</div>
</div>
</div>
</div>
</div>
If you make width=200px to the left column the uploaded image will always be at center and there are lots of padding you are using for centering the images, you can use various classes of bootstrap for that!
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<div class="container-fluid">
<!-- Section 7 -->
<div class="section padding-two column-bg">
<div class="row align-items-center">
<div class="text-center col-md-6 col-12">
<div class="classWithPad">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<a><img src="https://placehold.it/200x200" width="200px"></a>
</div>
</div>
<div class="text-center col-md-6">
<div class="classWithPad">
<div class="row p-3">
<div class="col-sm-12">
<h3 class="sbp-align">Headline</h3>
<hr>
</div>
<div class="col-sm-6">
<img src="https://placehold.it/250x150" width="100%" class="pb-2">
<h4 class="sbp-align pb-2">Subline</h4>
<p class="sbp-align">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<hr id="sbp-hr">
Read more
</div>
<div class="col-sm-6">
<img src="https://placehold.it/250x150" width="100%" class="pb-2">
<h4 class="sbp-align">Subline</h4>
<p class="sbp-align">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<hr id="sbp-hr">
Read more
</div>
</div>
</div>
</div>
</div>
</div>
</div>

How to pull object to the left side out of the div(class "card")

this is what i have
and this is what i have to do
i know how to create "hover" but don't understand how to add this numbers which are pulled to the left OUT of the card!
this is my html
<li>
<div uk-parallax="opacity: 0,1; y: 100,0; viewport: 0.3"
class="uk-card uk-card-hover uk-card-small uk-card-body">
<h3 class="uk-card-title">HOW THE PRICE CALCULATED</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.</p>
</div>
</li>
<li>
<div uk-parallax="opacity: 0,1; y: 100,0; viewport: 0.5"
class="uk-card uk-card-hover uk-card-small uk-card-body">
<h3 class="uk-card-title">HOW THE PRICE CALCULATED</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.</p>
</div>
</li>
By the way i am using css framework named UIkit 3, maybe it can help somehow...
Thank you!
You'll have to do some custom CSS, but it can be accomplished with CSS counters + before pseudo element, like so:
ol {
list-style: none;
counter-reset: mycounter;
padding-left: 50px;
}
li {
counter-increment: mycounter;
position: relative;
}
li:hover {
background-color: #efefef;
}
li::before {
content: counter(mycounter);
position: absolute;
left: -30px;
font-size: 72px;
}
li:hover::before {
color: rgb(0,100,255);
font-size: 96px;
left: -40px;
top: -5px;
}
Here it is on codepen (with a little more styling to get it closer to your mockup):
https://codepen.io/jcatt/pen/jeOQaO?editors=1100
And here's a guide to doing this kind of thing:
https://css-tricks.com/custom-list-number-styling/

Unaligned images with text underneath? CSS / HTML

unaligned images and text
I have attempted to input suggestions from previous questions but it just seems I have been able to successfully find the correct way to align these images with their text underneath.
<section id="boxes">
<div class="container">
<div class="box">
<img src="./images/dayporter2.jpeg">
<h3>DAYPORT</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
</p>
</div>
<div class="box">
<img src="./images/floorcare1.jpeg">
<div class="box">
<h3>FLOOR CARE</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</p>
</div>
<div class="box">
<img src="./images/janitor2.jpeg">
</div>
</section>
/* boxes */
#boxes{
margin-top: 20px;
}
#boxes .box{
float: left;
text-align: center;
width: 30%;
padding: 10px;
}
#boxes .box img{
width: 90px;
}`
You seem to have an unnecessary div tag.
remove the div tag after your 'floorcare1.jpeg' img, here:
<img src="./images/floorcare1.jpeg">
<div class="box"> //remove this
<div class="box">
<img src="./images/floorcare1.jpeg">
<div class="box"> <!-- The probleme is here -->
<h3>FLOOR CARE</h3>
Because the .box element which is direct below the image is float left, it will force the image to be float left, because their sibling .box take 30% of the parent and there are remaining 70% width of their .box parent element. You must remove the .box element and every thing will work like you expecting.
Another problem you must close all you open markup
<section>
<div class="container">
<div class="box">
<!-- First box -->
</div>
<div class="box">
<!-- Second box -->
</div>
<div class="box">
<!-- Third box -->
</div>
</div>
</section>

3 divs horizontally, set last's height to auto

I have 3 divs, each with width:100%, placed under each other.
Here's how it looks:
My code is:
<div class="welcome">
<h1>Welcome</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</small>
</div>
<div class="welcome2">
<h1>About</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.<small>
</div>
<div class="welcome3">
<h1>Why choose us?</h1>
<div class="row">
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
<div class="col-md-4 why">
<i class="fa fa-reply-all fa-3x why-icon"></i>
<strong>Fast support</strong>
<p>Our moderators will help you with your problem.</p>
</div>
</div>
</div>
CSS
.welcome
{
text-align: center;
width: 100%;
background-color: #3BA666;
background-image: linear-gradient(60deg, #4DAC71 50%, #3BA666 50%);
padding: 50px;
}
.welcome2
{
text-align: center;
width: 100%;
background-color: #FF61E7;
background-image: linear-gradient(60deg, #FF61E7 50%, #FF61D0 50%);
padding: 50px;
}
.welcome3
{
text-align: center;
width: 100%;
background-color: #32C8DE;
background-image: linear-gradient(60deg, #32D0DE 50%, #32C8DE 50%);
padding: 50px;
}
.why
{
/** text-align: left; **/
padding: 15px;
}
.why-icon
{
color: #0E495C;
display: block;
}
I want it to be like that - first two are normal height, and the last one always fill the empty white space. Is this possible?
Here is the Fiddle: https://jsfiddle.net/21dydo07/1/
Yes, with CSS3.
Give the design's parents (body, html, ...) a height of 100%. Then set some height to .welcome and .welcome2, e.g. 200px each. After that, set .welcome3 to take the rest, like this:
html, body {height: 100%}
.welcome, .welcome2 {height: 200px}
.welcome3 {height: calc(100% - 400px)}
Another solution would be to set specific height for every element (that would also be CSS2 comapatible), but that wouldn't allow you to always fill 100% of the screen height and have the third div with a variable height.
If you need the first solution, but you also need CSS2 compliance (e.g. for IE8), then you might need a javascript fallback, that will set the height to .welcome3 accordingly at pageload, something like this (needs jQuery):
$(document).ready(function() {
$(".welcome3").css("height",$(window).height()-400);
});
If the sentences in the first two blocks can be wrapped to single-line, use this:
You could use calc().
Make sure that the wrapper for these three has a height style.
For .welcome and .welcome2, set padding and line-height either in px or in em. For example, if the calculated height comes out to be 300px use height: calc(100% - 300px) for .welcome3. Note: The spaces around the operator - are important.
You can do this with Flexbox, set min-height: 100vh; on wrap div and flex: 1; on welcome3 so it will always take free space of viewport
html, body {
margin: 0;
padding: 0;
}
.wrap {
display: flex;
min-height: 100vh;
flex-direction: column;
text-align: center;
}
.welcome {
background: #3CA666;
padding: 20px;
}
.welcome2 {
background: #FF61D0;
padding: 20px;
}
.welcome3 {
background: #32C9DE;
flex: 1;
padding: 20px;
}
<div class="wrap">
<div class="welcome">
<h1>Welcome</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</small>
</div>
<div class="welcome2">
<h1>About</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.</small>small>
</div>
<div class="welcome3">
<h1>Welcome 3</h1>
<small>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua</small>
</div>
</div>