I want to create equal height items inside a column. It's easy when i only have the title and price. The i can just flex grow the title, and i go my equal height.
The issue is when i also have a description.
Title
Price
Desc
There are two example, because i've tried both.
One example with all content inside one item, and the another example where the content is splittet into two item.
I've a equal height jQuery script, but want to use Flex if possible.
There's colors on all elements to see if the have equal heights.
I've my code on codepen, but i'll paste it in here also.
* {
box-sizing: border-box;
}
.container {
background: tomato;
padding: 20px;
max-width: 600px;
margin: auto;
}
.container:not(:first-of-type) {
margin-top: 40px;
}
.container ul {
margin: unset;
padding: 0;
list-style-type: none;
display: flex;
flex-flow: row wrap;
justify-content: space-between;
}
.container ul li {
display: flex;
flex-direction: column;
width: 32%;
background: #fff;
padding: .3em;
}
.container ul li h2 {
margin: 0;
}
.container.one ul li a {
background: lightgreen;
}
.container.one ul li a h2, .container.one ul li a p {
background: pink;
}
.container.one ul li a span {
background: lightblue;
}
.container.one .loop--item * {
display: flex;
flex-direction: column;
}
.container.one .loop--item--product-link {
height: 100%;
}
.container.one .loop--item--product-link h2 {
flex: 1;
}
.container.two .title-price {
background: green;
}
.container.two .desc {
background: blue;
}
.container.two ul li a {
background: lightgreen;
}
.container.two ul li a h2, .container.two ul li a p {
background: pink;
}
.container.two ul li a span {
background: lightblue;
}
.container.two .loop--item--product-link {
display: flex;
flex-direction: column;
flex-grow: 1;
}
.container.two .loop--item--product-link div.title-price {
padding: 10px;
display: flex;
flex-direction: column;
flex: 1;
}
.container.two .loop--item--product-link div.title-price h2 {
flex: 1;
}
.container.two .loop--item--product-link div.desc {
padding: 10px;
}
<h1 style="text-align:center;">Equal height: Title, Price, Description</h1>
<!-- Container ONE -->
<div class="container one">
<h1>Content in same box</h1>
<ul class="loop">
<li class="loop--item">
<a href="#" class="loop--item--product-link">
<h2>Overskrift</h2>
<span>17.000 kr. - 24.000 kr.</span>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nemo repellat inventore aspernatur ad quia fugiat facere rerum sapiente odit maiores!</p>
</a>
</li>
<li class="loop--item">
<a href="#" class="loop--item--product-link">
<h2>Her er en overskrift som er lidt længere</h2>
<span>17.000 kr. - 24.000 kr.</span>
<p>elit. Nemo repellat inventore aspernatur ad quia fugiat facere rerum sapiente odit maiores!</p>
</a>
</li>
<li class="loop--item">
<a href="#" class="loop--item--product-link">
<h2>Her er en overskrift </h2>
<span>17.000 kr. - 24.000 kr.</span>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nemo repellat inventore aspernatur ad quia fugiat facere rerum sapiente odit maiores!</p>
</a>
</li>
</ul>
</div>
<!-- Container TWO -->
<div class="container two">
<h1>Content in two boxes</h1>
<ul class="loop">
<li class="loop--item">
<a href="#" class="loop--item--product-link">
<div class="title-price">
<h2>Overskrift</h2>
<span>17.000 kr. - 24.000 kr.</span>
</div>
<div class="desc">
<p>Lorem ipsum dolor, sit amet consectetit maiores!</p>
</div>
</a>
</li>
<li class="loop--item">
<a href="#" class="loop--item--product-link">
<div class="title-price">
<h2>Her er en overskrift</h2>
<span>17.000 kr. - 24.000 kr.</span>
</div>
<div class="desc">
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nemo repellat inventore aspernatur ad quia fugiat facere rerum sapiente odit maiores!</p>
</div>
</a>
</li>
<li class="loop--item">
<a href="#" class="loop--item--product-link">
<div class="title-price">
<h2>Her er en overskrift</h2>
<span>17.000 kr. - 24.000 kr.</span>
</div>
<div class="desc">
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nemo repellat inventore aspernatur ad</p>
</div>
</a>
</li>
</ul>
</div>
As Paulie_D says, there is no way in the CSS to do it unless the elements share a parent.
In modern browsers, however, you can flatten your DOM tree, and make some elements disappear using display: contents.
One posible solution using this approach (getting rid of li and a)
* {
box-sizing: border-box;
}
.container {
background: tomato;
padding: 20px;
max-width: 600px;
margin: auto;
}
.container:not(:first-of-type) {
margin-top: 40px;
}
.container ul {
margin: unset;
padding: 0;
list-style-type: none;
display: grid;
grid-template-rows: repeat(3, auto);
grid-template-columns: repeat(3, auto);
grid-gap: 10px;
}
.container ul li,
.container ul li a {
display: contents;
}
.container ul li h2 {
margin: 0;
}
.container.one ul li a h2 {
grid-row: 1;
background: pink;
}
.container.one ul li a p {
grid-row: 3;
background: pink;
}
.container.one ul li a span {
grid-row: 2;
background: lightblue;
}
<h1 style="text-align:center;">Equal height: Title, Price, Description</h1>
<!-- Container ONE -->
<div class="container one">
<h1>Content in same box</h1>
<ul class="loop">
<li class="loop--item">
<a href="#" class="loop--item--product-link">
<h2>Overskrift</h2>
<span>17.000 kr. - 24.000 kr.</span>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nemo repellat inventore aspernatur ad quia fugiat facere rerum sapiente odit maiores!</p>
</a>
</li>
<li class="loop--item">
<a href="#" class="loop--item--product-link">
<h2>Her er en overskrift som er lidt længere</h2>
<span>17.000 kr. - 24.000 kr.</span>
<p>elit. Nemo repellat inventore aspernatur ad quia fugiat facere rerum sapiente odit maiores!</p>
</a>
</li>
<li class="loop--item">
<a href="#" class="loop--item--product-link">
<h2>Her er en overskrift </h2>
<span>17.000 kr. - 24.000 kr.</span>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Nemo repellat inventore aspernatur ad quia fugiat facere rerum sapiente odit maiores!</p>
</a>
</li>
</ul>
</div>
Related
Desired outcome: I have three columns. I need them to be all the same width, as well as text and buttons to be on the same level in all three of them.
Problem: Depending on the number of words, columns become wider and buttons start to jump when text is resizing, and all three texts are resizing on a different points. I need to prevent that. How can I achieve this?
HTML:
<section class="sub-offer">
<div class="offer-container">
<div class="offer-up">
<h2>Lorem, ipsum.</h2>
<img src="https://via.placeholder.com/150x150.png/09f/fff" alt="" />
</div>
<div class="offer-down">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minus a
rerum sapiente odit porro obcaecati fugit, maxime modi veritatis
quis!
</p>
</div>
<div class="more-btn">
Lorem, ipsum.
</div>
</div>
<div class="offer-container">
<div class="offer-up">
<h2>Lorem, ipsum.</h2>
<img src="https://via.placeholder.com/150x150.png/09f/fff" alt="" />
</div>
<div class="offer-down">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Excepturi
perspiciatis voluptas qui iste, voluptatem atque ab rerum illum quia
incidunt odio?
</p>
</div>
<div class="more-btn">
Lorem, ipsum.
</div>
</div>
<div class="offer-container">
<div class="offer-up">
<h2>Lorem, ipsum.</h2>
<img src="https://via.placeholder.com/150x150.png/09f/fff" alt="" />
</div>
<div class="offer-down">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Beatae
vitae aut fugit dicta repellendus dolorem, quam, accusamus hic nemo
ullam quod porro atque error?
</p>
</div>
<div class="more-btn">
Lorem, ipsum.
</div>
</div>
</section>
CSS:
.sub-offer {
text-align: center;
display: flex;
position: relative;
.offer-container {
background: linear-gradient(to bottom right, #2e2e3b, #0f1519);
}
h2 {
font-family: 'Playfair Display', serif;
font-size: 15px;
position: absolute;
margin-left: auto;
margin-right: auto;
margin-top: 4.3em;
width: 33%;
text-align: center;
}
p {
font-size: 12px;
margin-top: 2em;
padding: 0 0.5em 0 0.5em;
font-family: 'Montserrat', sans-serif;
}
a {
display: inline-block;
font-family: 'Montserrat', sans-serif;
font-size: 12px;
background: white;
margin: 3em 0 2.5em 0;
padding: 0.5em;
text-decoration: none;
color: black;
&:hover {
background: #e5e5e5;
}
}
}
How they look now:
You can add a media query to change the flex-direction when the screen resizes.
Add the following indie .sub-offer class.
#media(max-width: 600px){
flex-direction: column;
}
Add the following inside h2 element.
#media(max-width: 600px){
width: 100%;
}
I solved my issue. To give all three columns the same width I've used what #tacoshy recommended in the comments: section.sub-offer { display: flex; } .offer-container { width: calc(100% / 3); }
To align all three buttons though leaving all them responsive I've wrapped my button into a div and used the following css:
.more-btn {
display: flex;
align-self: center;
margin-top: auto;
}
I'm not really a good dev, but I can give it a try. What I do when I want to make things line up perfectly is use grid, so I tried adding it to .offer-container like this .offer-container {display: grid; grid-template-rows: 1fr 1fr 1fr;}. A working example is below. Though, since I'm new to helping people on StackOverflow or really StackOverflow in general, I'm sure I didn't do something right. for example, providing a solution to a different problem or fixing issues that you didn't as for. If you need a list of what I changed, you can see that here: added } for sub-offer removed extra closing bracket on a{} separated &:hover to a:hover{} made <p> text white. I hope this is the solution you were looking for if your problem hasn't already been fixed.
.sub-offer {
text-align: center;
display: flex;
position: relative;
width:100px
}
.offer-container {
background: linear-gradient(to bottom right, #2e2e3b, #0f1519);
display: grid;
grid-template-rows: 1fr 1fr 1fr;
}
h2 {
font-family: 'Playfair Display', serif;
font-size: 15px;
position: absolute;
margin-left: auto;
margin-right: auto;
margin-top: 4.3em;
width: 33%;
text-align: center;
}
p {
font-size: 12px;
margin-top: 2em;
padding: 0 0.5em 0 0.5em;
font-family: 'Montserrat', sans-serif;
color: white;
}
a {
display: inline-block;
font-family: 'Montserrat', sans-serif;
font-size: 12px;
background: white;
margin: 3em 0 2.5em 0;
padding: 0.5em;
text-decoration: none;
color: black;
}
a:hover {
background: #e5e5e5;
}
<section class="sub-offer">
<div class="offer-container">
<div class="offer-up">
<h2>Lorem, ipsum.</h2>
<img src="https://via.placeholder.com/150x150.png/09f/fff" alt="" />
</div>
<div class="offer-down">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minus a
rerum sapiente odit porro obcaecati fugit, maxime modi veritatis
quis!
</p>
</div>
<div class="more-btn">
Lorem, ipsum.
</div>
</div>
<div class="offer-container">
<div class="offer-up">
<h2>Lorem, ipsum.</h2>
<img src="https://via.placeholder.com/150x150.png/09f/fff" alt="" />
</div>
<div class="offer-down">
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Excepturi
perspiciatis voluptas qui iste, voluptatem atque ab rerum illum quia
incidunt odio?
</p>
</div>
<div class="more-btn">
Lorem, ipsum.
</div>
</div>
<div class="offer-container">
<div class="offer-up">
<h2>Lorem, ipsum.</h2>
<img src="https://via.placeholder.com/150x150.png/09f/fff" alt="" />
</div>
<div class="offer-down">
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Beatae
vitae aut fugit dicta repellendus dolorem, quam, accusamus hic nemo
ullam quod porro atque error?
</p>
</div>
<div class="more-btn">
Lorem, ipsum.
</div>
</div>
</section>
I have the majority of my code wrapped in a container with the following style:
.container {
position: relative;
width: 100%;
height: 100vh;
overflow: auto;
padding-left: 0;
padding-right: 0;
scroll-behavior: smooth;
scroll-snap-type: y mandatory;
}
This is to enable me to scroll smoothly from one section of the page that takes up a height of 100vh to another. (That is why I have overflow: auto in my styling). However, when I add the "overflow: auto", the web page stops being the full width of my window (as shown in the image).
screenshot of problem
When I remove the "overflow: auto" and replace it with "overflow: none", then the width is fixed but my scrolling feature now longer works.
HTML Code here:
<body class="container-fluid">
<!-- Main Page -->
<div class="container">
<div class="section">
<div class="main row vertical-center">
<div class="main-image col-md-6">
<img src="rec/img/placeholder-image.png" alt="client_image">
</div>
<div class="main-text align-items-center col-md-6">
<h2 class="p-3">
Name Lastname
</h2>
<span class="align-bottom bottom-text-main">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptatem corporis nostrum illo? Vero necessitatibus accusamus ullam commodi, consequatur corrupti. Recusandae eligendi eaque possimus minima numquam dignissimos cumque adipisci tempora temporibus.
</span>
</div>
<span id="contact">
<!-- <ul class="contact-icons" style="list-style-type:none;">
<li></li></li>
<li></li>
<li></li>
</ul> -->
<i></i>
<i></i>
<i></i>
</span>
</div>
</div>
<!-- Information -->
<div class="section info">
<div class="information p-4 pb-0" id="information">
<h1 >More about me.</h1>
<br>
<div class="background ml-3">
<h5 class = "pb-1">Background</h5>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Corrupti facilis, est distinctio esse temporibus sint animi sunt veniam asperiores commodi quo numquam excepturi nemo ab, harum, nam possimus quas veritatis!</p>
</div>
<div class="skills ml-3">
<h5 class="pb-1">Skills</h5>
<ul>
<li>Skill</li>
<li>Skill</li>
<li>Skill</li>
<li>Skill</li>
<li>Skill</li>
</ul>
</div>
</div>
</div>
<!-- Experience -->
<div class="section">
<div class="experience p-3" id="experience">
<h1 class="pt-3">Work experience</h1>
<br>
<div class="xp">
<div class="workxp p-3 ml-3">
<h4 class = "pb-2">Lorem, ipsum.</h4>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Laborum, aliquid. Quidem, quae dolorem! Amet ea obcaecati nam quia aliquid, facilis dolorem ab velit optio. Accusamus quidem commodi rerum itaque incidunt?
</div>
<div class="workxp p-3 ml-3">
<h4 class = "pb-2">Lorem, ipsum.</h4>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Ducimus aperiam veritatis eos illo quo necessitatibus omnis illum iure impedit debitis, consectetur voluptatum quisquam, quae temporibus veniam. In minima quos perferendis.
</div>
<div class="workxp p-3 ml-3">
<h4 class = "pb-2">Lorem, ipsum.</h4>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo officiis alias architecto non iure, quia labore rem. Totam nulla qui exercitationem beatae, ab aperiam! Asperiores soluta nisi repudiandae odit doloribus.
</div>
</div>
</div>
</div>
<!-- Additional Inforation -->
<div class="section">
<div class="additional-info p-3" id="additional-info">
<h1>Additional Information</h1>
<!-- <h1 class="second-line-info">Information</h1> -->
<div class="additional-info-text text-left">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, pariatur!</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Praesentium, pariatur at. Fuga error impedit officiis!</p>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Dolor facilis tempora odit vel cum adipisci, aut ducimus illum ab tenetur quae temporibus non. Velit rerum ipsa quis, sint blanditiis doloremque repellendus aliquid eius amet exercitationem!</p>
<p>Lorem ipsum dolor sit amet.</p>
<p>Lorem, ipsum dolor.</p>
</div>
</div>
</div>
<!-- Footer -->
<div class="section" id="footer">
<footer class="page-footer font-small blue pt-4">
<div class="container-fluid text-center text-md-left">
<div class="row">
<div class="col-md-6 mt-md-0 mt-3">
<h5 class="text-uppercase">Name Lastname</h5>
<p>Cliche Inspiritional Quote Here</p>
</div>
<!-- Grid column -->
<hr class="clearfix w-100 d-md-none pb-3">
<!-- Grid column -->
<div class="col-md-6 mb-md-0 mb-9">
<!-- Links -->
<h5 class="text-uppercase">Contact Links</h5>
<ul class="list-unstyled">
<li>
<i> Facebook</i>
</li>
<li>
<i> Instagram</i>
</li>
<li>
<i> Email</i>
</li>
</ul>
</div>
<!-- Grid column -->
</div>
<!-- Grid row -->
</div>
<!-- Footer Links -->
</footer>
</div>
</div>
Here is the CSS file:
body {
color: var(--grey);
width: 100%;
padding: 0;
margin: 0;
min-width: fit-content;
}
.container {
position: relative;
width: 100vh;
height: 100vh;
overflow: visible;
padding-left: 0;
padding-right: 0;
scroll-behavior: smooth;
scroll-snap-type: y mandatory;
}
.container .section {
position: relative;
height: 100%;
width: 100%;
scroll-snap-align: start;
/* background-blend-mode: multiply; */
}
/* .container.section:nth-child(1) {
background: ;
background-size: cover;
background-attachment: fixed;
} */
.main {
background-color: var(--white);
padding-left: 0%;
padding-right: 0%;
margin-top: 0rem;
margin-bottom: 0rem;
height: 100vh;
}
.main-image {
padding-top: 0%;
margin-left: 0%;
padding-right: 0;
margin-bottom: 2rem;
height: 50%;
}
.main-image img {
height: 100%;
width: 100%;
margin-left: 0%;
margin-right: 0%;
}
.main-text {
padding-bottom: 2rem;
height: 50%;
/* margin-left: 5%;
margin-right: 5%; */
}
.main-text p {
vertical-align: middle;
}
.information {
background-color: var(--soft);
height: 100vh;
padding-top: 0;
}
.experience {
background-color: var(--white);
height: 100%;
}
.information h1 {
padding-top: 1rem;
}
.background {
padding-top: 3rem;
}
.skills ul {
list-style-type: none;
}
.skills {
padding-top: 3rem;
}
.additional-info {
background-color: var(--soft);
height: 100vh;
padding-top: 1rem;
}
.additional-info h1 {
color: var(--grey);
}
.second-line-info {
margin-left: 5rem;
}
.additional-info-text {
text-align: center;
padding-left: 2rem;
padding-right: 2rem;
}
.additional-info-text p {
margin-top: 1.5rem;
margin-bottom: 1.5rem;
}
#footer {
height: 10vh;
}
.list-unstyled i {
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
}
#media only screen and (min-width: 600px) {
html {
width: 100%;
}
body {
width: 100%;
padding: 0;
}
.main {
padding-top: 0%;
width: 100%;
}
.vertical-center {
display: flex;
align-items: center;
}
.main-image {
height: 100%;
margin-top: 15%;
}
.main-image img {
border-radius: 50%;
height: 50%;
width: 75%;
}
.main-text {
height: 100%;
margin-top: 20%;
}
.main-text h2 {
margin-bottom: 3rem;
}
#contact {
position: absolute;
bottom: 2%;
right: 2%;
}
.contact-icons {
padding: 0;
font-size: 2em;
display: table-cell;
}
.fa {
padding-left: 1rem;
padding-right: 1rem;
text-align: center;
text-decoration: none;
border-radius: 50%;
}
.contact a {
display: inline-block;
width: 1.2em;
transition: all .2s ease-in-out;
}
a:hover {
text-decoration: none;
}
.additional-info {
text-align: left;
justify-content: left;
}
.additional-info-text p {
margin-top: 2rem;
}
/* BEVAN ONDER */
/* General */
body, html
{
width: 100%;
padding: 0;
margin:0;
}
.container{
width: 100%;
}
.container.section{
width: 100%;
}
/* Information page(s) */
.background{
padding-top: 2rem;
}
.skills{
padding-top: 2rem;
}
.background p{
width: 50%;
}
}
Is there a possible fix for this?
Use this css value
overflow:scroll
or
overflow:visible
Keeping them auto will let browser decide the overflow.
I personally never use auto value.
try this
overflow:scroll;
width:100vw
if didn't work please edit post and add html
I am following a series of Traversy Media videos for creating a portfolio website. I have a foundational knowledge of HTML/CSS. We have to create a grid and no matter what I do, I cannot get the grid to show up in my browser (Chrome). The grid will be for the About info on the about page. Also the footer isn't showing up for some reason. Any help would be greatly appreciated.
Here is the about.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://kit.fontawesome.com/31d2c226f4.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="css/main.css">
<title>About Me</title>
</head>
<body>
<div class="overlay"></div>
<header>
<div class="menu-btn">
<div class="btn-line"></div>
<div class="btn-line"></div>
<div class="btn-line"></div>
</div>
<nav class="menu">
<div class="menu-branding">
<div class="portrait"></div>
</div>
<ul class="menu-nav">
<li class="nav-item">
<a href="/" class="nav-link">
Home
</a>
</li>
<li class="nav-item current">
<a href="about.html" class="nav-link">
About Moi
</a>
</li>
<li class="nav-item">
<a href="work.html" class="nav-link">
My Work
</a>
</li>
<li class="nav-item">
<a href="Contact.html" class="nav-link">
How to Reach Me
</a>
</li>
</ul>
</nav>
</header>
<main id="about">
<h1 class="lg-heading">
About
<span class="text-secondary">Me</span>
</h1>
<h2 class="sm-heading">
Let me tell you a few things...
</h2>
<div class="about-info">
<!-- <img src="img/portrait.jpeg" alt="Alex Gool" class="bio-image"> -->
<div class="bio">
<h3 class="text-secondary">BIO</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem dolore at, quasi natus veritatis, amet cum voluptates, iste fugit atque autem laboriosam. Provident officia modi inventore fugit recusandae vitae nisi.</p>
</div>
<div class="job job-1">
<h3>123 Webshop</h3>
<h6>Full Stack Developer</h6>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nisi ipsum aperiam inventore. Inventore illo accusamus debitis facilis, quisquam velit aliquam?</p>
</div>
<div class="job job-2">
<h3>Designers ABC</h3>
<h6>Front End Developer</h6>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nisi ipsum aperiam inventore. Inventore illo accusamus debitis facilis, quisquam velit aliquam?</p>
</div>
<div class="job job-3">
<h3>Webworks</h3>
<h6>Graphic Designer</h6>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nisi ipsum aperiam inventore. Inventore illo accusamus debitis facilis, quisquam velit aliquam?</p>
</div>
</div>
</main>
<footer id="main-footer">
Copyright © 2021
</footer>
<script src="js/main.js"></script>
</body>
</html>
And here is the main SCSS file
// Move variable and functions to _config.scss file. This helps tidy up the main.scss file and makes the code more readable. Use #import then the file name (NOT WITH THE .scss EXTENSION).
#import "config";
#import "menu";
// Ensures inside padding will not affect height/width of box, it will just be in the box itself.
* {
box-sizing: border-box;
}
body {
#include background;
background: $primary-color;
color: set-text-color($primary-color);
height: 100%;
margin: 0;
font-family: "Segoe UI", "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.5;
}
// Headings
h1,
h2,
h3 {
margin: 0;
font-weight: 400;
&.lg-heading {
font-size: 6rem;
}
&.sm-heading {
margin-bottom: 2rem;
padding: 0.2rem 1rem;
// Background to heading information will be lighter.
// Wrap in RGBA function, 0.5 is the opacity.
background: rgba(lighten($primary-color, 2), 0.5);
}
}
a {
color: #fff;
text-decoration: none;
}
// Header (icon) is fixed so it stays at top right when user scrolls through the webpage.
header {
position: fixed;
z-index: 2;
width: 100%;
}
.text-secondary {
color: $secondary-color;
}
// Nesting the .icons class so that only the icons in the main tag will be affected. This is specific to SASS.
main {
padding: 4rem;
// height: 100%;
min-height: calc(100vh - 60px);
.icons {
margin-top: 1rem;
color: set-text-color($primary-color);
// Inside the div class "icons", each icon is wrapped in a link.
a {
padding: 0.4rem;
// Putting the & in things is specific to SASS, this is not a feature of normal CSS.
&:hover {
color: $secondary-color;
#include easeOut();
}
}
}
&#home {
// This makes it so that there will never be scroll bars.
overflow: hidden;
h1 {
// This brings my name down closer to the middle of the page.
margin-top: 20vh;
}
}
}
.about-info {
display: grid !important;
grid-template-columns: 1fr 1fr 1fr !important;
grid-template-rows: auto !important;
grid-template-areas:
"bioimage bio bio"
" job1 job2 job3" !important;
.bio-image {
grid-area: bioimage;
margin: auto;
border-radius: 50%;
border: $secondary-color 3px solid;
}
.bio {
grid-area: bio;
font-size: 1.5rem;
}
.job-1 {
grid-area: job1;
}
.job-2 {
grid-area: job2;
}
.job-3 {
grid-area: job3;
}
.job {
background: lighten($primary-color: 5);
padding: 0.5rem;
border-bottom: $secondary-color 5px solid;
}
}
#main-footer {
text-align: center;
padding: 1rem;
background: darken($primary-color: 10);
color: set-text-color($primary-color);
height: 60px;
}
#import "mobile";
I took this snippet from the code you linked and rewrote it without SCSS so it can compile below. It seems to me like display: grid is working just fine. If you open the chrome dev tools and inspect, you will see a "grid" label on the .about-info element.
.about-info {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
grid-template-areas: "bioimage bio bio" " job1 job2 job3" !important;
}
.about-info .job-1 {
grid-area: job1;
}
.about-info .job-2 {
grid-area: job2;
}
.about-info .job-3 {
grid-area: job3;
}
.about-info .bio {
grid-area: bio;
font-size: 1.5rem;
}
.about-info .bio-image {
grid-area: bioimage;
margin: auto;
border-radius: 50%;
border: $secondary-color 3px solid;
}
.about-info .job {
background: lighten($primary-color: 5);
padding: 0.5rem;
border-bottom: $secondary-color 5px solid;
}
<div class="about-info">
<div class="bio">
<h3 class="text-secondary">BIO</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Exercitationem dolore at, quasi natus veritatis, amet cum voluptates, iste fugit atque autem laboriosam. Provident officia modi inventore fugit recusandae vitae nisi.</p>
</div>
<div class="job job-1">
<h3>123 Webshop</h3>
<h6>Full Stack Developer</h6>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nisi ipsum aperiam inventore. Inventore illo accusamus debitis facilis, quisquam velit aliquam?</p>
</div>
<div class="job job-2">
<h3>Designers ABC</h3>
<h6>Front End Developer</h6>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nisi ipsum aperiam inventore. Inventore illo accusamus debitis facilis, quisquam velit aliquam?</p>
</div>
<div class="job job-3">
<h3>Webworks</h3>
<h6>Graphic Designer</h6>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nisi ipsum aperiam inventore. Inventore illo accusamus debitis facilis, quisquam velit aliquam?</p>
</div>
</div>
.pop-up {
z-index: 10;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
height: 90vh;
width: 50vw;
max-width: 80%;
background-color: #132c23;
border: 5px solid #fffbce;
border-radius: 20px;
}
.wrap-pop-up-div {
height: 100%;
width: 100%;
position: relative;
}
.pop-carousel {
position: absolute;
top: 12.5%;
left: 30%;
}
.close-modal {
position: absolute;
right: 5%;
top: 2%;
outline: none;
background: none;
cursor: pointer;
border: none;
font-size: 3rem;
color: #fffbce;
}
.close-modal:hover {
color: #510000;
transition-duration: 300ms;
}
.pop-carousel .container-carousel {
overflow: hidden;
width: 600px;
height: auto;
}
.pop-carousel .slides {
display: flex;
align-items: center;
align-content: center;
}
.pop-carousel img {
width: 600px;
height: 400px;
flex-shrink: 0;
}
.list-pop-up {
position: relative;
left: 2%;
top: 15%;
}
.pop-up ul {
padding: 0px;
list-style: none;
font-family: rochester;
font-size: 1.8rem;
}
.pop-up ul a {
color: #fffbce;
text-decoration: none;
}
.pop-up ul a:hover {
color: #4c8d49;
text-decoration: underline;
transition-duration: 350ms;
}
.pop-up ul a.active {
color: #4c8d49;
text-decoration: underline;
}
.pop-up ul li {
padding: 10px 0;
}
.wrap-pop-up-div > .para-div,
.wrap-pop-up-div > a {
position: absolute;
top: 70%;
}
.wrap-pop-up-div > .para-div {
left: 30%;
width: 600px;
text-align: justify;
font-size: 1.2rem;
color: #fffbce;
}
.wrap-pop-up-div > a {
left: 7.5%;
top: 80%;
text-decoration: none;
color: #fffbce;
font-size: 1.3rem;
border: 2px solid #fffbce;
padding: 5px 7.5px;
border-radius: 5px;
}
.wrap-pop-up-div > a:hover {
border-color: #510000;
background-color: #510000;
transition-duration: 200ms;
-webkit-transition-duration: 200ms;
}
.overlay {
background-color: rgba(0, 0, 0, 0.5);
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 5;
}
#media (max-width: 950px) {
.pop-up {
height: 100%;
width: 100%;
position: fixed;
top: 0;
left: 0;
}
}
<div class="pop-up" >
<div class="wrap-pop-up-div show-toggle">
<button class="close-modal">×</button>
<div class="list-pop-up">
<ul>
<li>
<a class="active" href="#">
Badeparadies
</a>
</li>
<li>
<a href="#">
Trieberger Wasserfälle
</a>
</li>
</ul>
</div>
<div class="pop-carousel">
<div class="container-carousel">
<i class="fas fa-arrow-left prevBtn"></i>
<i class="fas fa-arrow-right nextBtn"></i>
<div class="slides">
<img
src="../source/img/gen-info/Rooms/bspForRooms.jpg"
alt="roomForThree"
/>
<img
src="../source/img/gen-info/Rooms/bspForRooms.jpg"
alt="roomForThree"
/>
</div>
</div>
</div>
<div class="para-div">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Unde aliquid consectetur sit optio eius consequuntur porro similique ducimus magni id, sint, aut fugiat aliquam ab magnam facere ipsum cupiditate autem incidunt tenetur possimus excepturi accusantium nostrum. At fugiat ex natus ea ut id voluptates, vero, similique perferendis expedita tenetur esse.</p>
</div>
<a class="box-shadower" href="#">Buchen</a>
</div>
<div class="wrap-pop-up-div show-toggle">
<button class="close-modal">×</button>
<div class="list-pop-up">
<ul>
<li>
<a href="#">
Badeparadies
</a>
</li>
<li>
<a class="active" href="#">
Trieberger Wasserfälle
</a>
</li>
</ul>
</div>
<div class="pop-carousel">
<div class="container-carousel">
<i class="fas fa-arrow-left prevBtn"></i>
<i class="fas fa-arrow-right nextBtn"></i>
<div class="slides">
<img
src="../source/img/gen-info/Rooms/bspForRooms.jpg"
alt="roomForThree"
/>
<img
src="../source/img/gen-info/Rooms/bspForRooms.jpg"
alt="roomForThree"
/>
</div>
</div>
</div>
<div class="para-div">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Unde aliquid consectetur sit optio eius consequuntur porro similique ducimus magni id, sint, aut fugiat aliquam ab magnam facere ipsum cupiditate autem incidunt tenetur possimus excepturi accusantium nostrum. At fugiat ex natus ea ut id voluptates, vero, similique perferendis expedita tenetur esse.</p>
</div>
<a class="box-shadower" href="#">Buchen</a>
</div>
</div>
</div>
<div class="overlay show-toggle"></div>
I have some modals, which should pop up in full screen at 950px (max-width). Thus I implemented a media query but it does not work. Does anyone know an alternative way? I also tried to on my pop-up class a 100vw but this had no effect at all. Perhaps someone has an idea why? The code I post here is basically the way how I did it for my background of the modal (the greyish overlay), so it worked for me in this document already, seems odd that it isn't working now.
CSS:
#media (max-width: 950px) {
.pop-up {
height: 100%;
width: 100%;
position: fixed;
top: 0;
left: 0;
}
}
HTML:
<div class="pop-up" >
<div class="wrap-pop-up-div show-toggle">
<button class="close-modal">×</button>
<div class="list-pop-up">
<ul>
<li>
<a class="active" href="#">
Badeparadies
</a>
</li>
<li>
<a href="#">
Trieberger Wasserfälle
</a>
</li>
</ul>
</div>
<div class="pop-carousel">
<div class="container-carousel">
<i class="fas fa-arrow-left prevBtn"></i>
<i class="fas fa-arrow-right nextBtn"></i>
<div class="slides">
<img
src="../source/img/gen-info/Rooms/bspForRooms.jpg"
alt="roomForThree"
/>
<img
src="../source/img/gen-info/Rooms/bspForRooms.jpg"
alt="roomForThree"
/>
</div>
</div>
</div>
<div class="para-div">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Unde aliquid consectetur sit optio eius consequuntur porro similique ducimus magni id, sint, aut fugiat aliquam ab magnam facere ipsum cupiditate autem incidunt tenetur possimus excepturi accusantium nostrum. At fugiat ex natus ea ut id voluptates, vero, similique perferendis expedita tenetur esse.</p>
</div>
<a class="box-shadower" href="#">Buchen</a>
</div>
<div class="wrap-pop-up-div show-toggle">
<button class="close-modal">×</button>
<div class="list-pop-up">
<ul>
<li>
<a href="#">
Badeparadies
</a>
</li>
<li>
<a class="active" href="#">
Trieberger Wasserfälle
</a>
</li>
</ul>
</div>
<div class="pop-carousel">
<div class="container-carousel">
<i class="fas fa-arrow-left prevBtn"></i>
<i class="fas fa-arrow-right nextBtn"></i>
<div class="slides">
<img
src="../source/img/gen-info/Rooms/bspForRooms.jpg"
alt="roomForThree"
/>
<img
src="../source/img/gen-info/Rooms/bspForRooms.jpg"
alt="roomForThree"
/>
</div>
</div>
</div>
<div class="para-div">
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Unde aliquid consectetur sit optio eius consequuntur porro similique ducimus magni id, sint, aut fugiat aliquam ab magnam facere ipsum cupiditate autem incidunt tenetur possimus excepturi accusantium nostrum. At fugiat ex natus ea ut id voluptates, vero, similique perferendis expedita tenetur esse.</p>
</div>
<a class="box-shadower" href="#">Buchen</a>
</div>
</div>
</div>
<div class="overlay show-toggle"></div>
You have
max-width: 80%;
transform: translate(-50%, -50%);
in your style for pop-up. Change your css to
#media (max-width: 950px) {
.pop-up {
height: 100%;
width: 100%;
position: fixed;
top: 0;
left: 0;
max-width: 100%;
transform: translate(0, 0);
}
}
.pop-up {
transform: translate(-50%, -50%);
max-width: 80%;
border: 5px solid #fffbce;
border-radius: 20px;
}
messes up your popup if your media query is active. Add
#media (max-width: 950px) {
.pop-up {
transform: none;
max-width: 100%;
border: none;
border-radius: 0;
}
}
as well and it should be good.
My image which is in the head touches on the next block (seaction features). (image-phone)
https://imgur.com/a/CeOakka
I tried change types of position,z-index. If i cut the image its not cool and easy to fix ;)
And how can i variable my image: div-class or just img tag? In my code i just variable img with class without div blocks. Is it clean?
<div class="container">
<nav id="main-nav">
<ul class="menu">
<li>Tour</li>
<li>Features</li>
<li>Pricing</li>
<li>
<h2 class="logo">NEWPROVIDENCE</h2>
</li>
<li>Help</li>
<li>Contact</li>
<i class="fab fa-apple fa-1x"></i>Get app
</ul>
</nav>
<div class="showcase">
<h1>What happen tomorrow?</h1>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Voluptas, ex maxime! Natus earum praesentium officiis adipisci qui nisi ut, laboriosam labore optio. Non quidem assumenda dolore consectetur, corrupti quae delectus.</p>
<i class="fas fa-play"></i>Watch Video
</div>
<img src="https://imgur.com/a/Ees14KN" class="phone-img" alt="">
</div>
</header>
<section id="main-features">
<div class="container">
<div class="features">
<div class="feature">
<i class="fas fa-clock fa-2x"></i>
<h2 class="m-heading">Real time all the time</h2>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Porro sunt soluta praesentium earum iusto hic?</p>
</div>
<div class="feature">
<i class="fas fa-clock fa-2x"></i>
<h2 class="m-heading">Real time all the time</h2>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Porro sunt soluta praesentium earum iusto hic?</p>
</div>
</div>
<hr>
</div>
</section>
header {
background: url('../img/bg-header.png') no-repeat center center / cover;
height: 100vh;
}
#main-nav {
display: flex;
justify-content: space-between;
padding: 2rem;
}
#main-nav ul {
display: grid;
grid-template-columns: repeat(3, auto) 1fr repeat(3, auto);
width: 100%;
list-style: none;
align-items: center;
text-align: center;
}
#main-nav ul li a {
padding: 0.75rem;
font-size: 16px;
margin: 0 0.25rem;
color: #26272d;
}
#main-nav ul li a:hover {
color: #bebebf;
}
.phone-img {
display: block;
margin: 0 auto;
}
You could try to put the phone image inside of a div as a background image instead of embedding it into the html on the page.
If you remove the image from the html and add a div class="phone-image"(for example) instead, you can control the height and width of the div and add this to the css:
div .phone-image {
background: url(../path-to-your-images-folder/images/yourphoto.jpg);
background-size: cover;
height: 100px; /* for example */
width: 40%; /* for example 40% of the container width */
}
You would also have to position it correctly on top of the other image by using a higher z-index and position: absolute; and then play around with top, bottom, left and right values (https://medium.freecodecamp.org/how-to-understand-css-position-absolute-once-and-for-all-b71ca10cd3fd)