CSS Grid needs to be 100% width and height on all sides - html

I have a question, I have this page right here:
And I have all boxes set up as a grid. But I want all black borders touching each other. So that all space is fully filled up with the grid only. The whole page needs to be the grid. See the code below:
DEMO:
* {
margin: 0 auto;
}
body {
width: 100%;
height: 100%;
min-width: 100%;
overflow: hidden;
}
.grid-container {
display: grid;
grid-template-columns: 0.8fr 2fr 0.8fr;
grid-template-rows: 1fr 1fr 1fr 1fr;
gap: 0px 0px;
grid-template-areas:
"logo nav time"
"computer-menu terminal computer-anim"
"missions terminal notebook"
"missions terminal notebook";
}
.missions {
grid-area: missions;
border: 3px solid black;
}
.terminal {
grid-area: terminal;
border: 3px solid black;
}
.notebook {
grid-area: notebook;
border: 3px solid black;
}
.computer-menu {
grid-area: computer-menu;
border: 3px solid black;
}
.logo {
grid-area: logo;
border: 3px solid black;
}
.nav {
grid-area: nav;
border: 3px solid black;
}
.time {
grid-area: time;
border: 3px solid black;
}
.computer-anim {
grid-area: computer-anim;
border: 3px solid black;
}
<div class="grid-container">
<div class="missions"><h1>MISSIONS</h1></div>
<div class="terminal"><h1>TERMINAL</h1></div>
<div class="notebook"><h1>NOTEBOOK</h1></div>
<div class="computer-menu"><h1>COMPUTER-MENU</h1></div>
<div class="logo"><h1>LOGO</h1></div>
<div class="nav"><h1>NAV</h1></div>
<div class="time"><h1>TIME</h1></div>
<div class="computer-anim"><h1>COMPUTER-ANIM</h1></div>
</div>

The problem is this rule in your code:
* {
margin: 0 auto;
}
The auto margins are centering the grid items within the columns.
Remove that rule, or modify the selector, and you're done.
/* * {
margin: 0 auto;
} */
body {
width: 100%;
height: 100%;
min-width: 100%;
overflow: hidden;
}
.grid-container {
display: grid;
grid-template-columns: 0.8fr 2fr 0.8fr;
grid-template-rows: 1fr 1fr 1fr 1fr;
gap: 0px 0px;
grid-template-areas:
"logo nav time"
"computer-menu terminal computer-anim"
"missions terminal notebook"
"missions terminal notebook";
}
.missions {
grid-area: missions;
border: 3px solid black;
}
.terminal {
grid-area: terminal;
border: 3px solid black;
}
.notebook {
grid-area: notebook;
border: 3px solid black;
}
.computer-menu {
grid-area: computer-menu;
border: 3px solid black;
}
.logo {
grid-area: logo;
border: 3px solid black;
}
.nav {
grid-area: nav;
border: 3px solid black;
}
.time {
grid-area: time;
border: 3px solid black;
}
.computer-anim {
grid-area: computer-anim;
border: 3px solid black;
}
<div class="grid-container">
<div class="missions">
<h1>MISSIONS</h1>
</div>
<div class="terminal">
<h1>TERMINAL</h1>
</div>
<div class="notebook">
<h1>NOTEBOOK</h1>
</div>
<div class="computer-menu">
<h1>COMPUTER-MENU</h1>
</div>
<div class="logo">
<h1>LOGO</h1>
</div>
<div class="nav">
<h1>NAV</h1>
</div>
<div class="time">
<h1>TIME</h1>
</div>
<div class="computer-anim">
<h1>COMPUTER-ANIM</h1>
</div>
</div>

Did you try to set CSS:
/* ADDED */
.grid-container > div {
width:calc(100% - 6px);
}
DEMO
* {
margin: 0 auto;
}
body {
width: 100%;
height: 100%;
min-width: 100%;
overflow: hidden;
}
.grid-container {
display: grid;
grid-template-columns: 0.8fr 2fr 0.8fr;
grid-template-rows: 1fr 1fr 1fr 1fr;
gap: 0px 0px;
grid-template-areas:
"logo nav time"
"computer-menu terminal computer-anim"
"missions terminal notebook"
"missions terminal notebook";
}
.missions {
grid-area: missions;
border: 3px solid black;
}
.terminal {
grid-area: terminal;
border: 3px solid black;
}
.notebook {
grid-area: notebook;
border: 3px solid black;
}
.computer-menu {
grid-area: computer-menu;
border: 3px solid black;
}
.logo {
grid-area: logo;
border: 3px solid black;
}
.nav {
grid-area: nav;
border: 3px solid black;
}
.time {
grid-area: time;
border: 3px solid black;
}
.computer-anim {
grid-area: computer-anim;
border: 3px solid black;
}
/* ADDED */
.grid-container > div {
width:calc(100% - 6px);
}
<div class="grid-container">
<div class="missions"><h1>MISSIONS</h1></div>
<div class="terminal"><h1>TERMINAL</h1></div>
<div class="notebook"><h1>NOTEBOOK</h1></div>
<div class="computer-menu"><h1>COMPUTER-MENU</h1></div>
<div class="logo"><h1>LOGO</h1></div>
<div class="nav"><h1>NAV</h1></div>
<div class="time"><h1>TIME</h1></div>
<div class="computer-anim"><h1>COMPUTER-ANIM</h1></div>
</div>

Related

Grid Layout Overlapping Row with full height

I have started using Grid CSS and i am stuck in building a Layout using Grid system.
I am looking to build a layout where the column would overlap a row and take full height. I have attached a screenshot of the layout and what i have tried so far.
body {
margin: 40px;
}
.sidebar {
grid-area: sidebar;
}
.content {
grid-area: content;
}
.header {
grid-area: header;
}
.wrapper {
display: grid;
grid-gap: 10px;
grid-template-columns: 120px 120px 120px;
grid-template-areas:
"header header header"
"sidebar content content";
background-color: #fff;
color: #444;
}
.box {
background-color: #444;
color: #fff;
border-radius: 5px;
padding: 20px;
font-size: 150%;
}
.header {
background-color: #999;
}
.overlay {
background-color: red;
z-index: 10;
grid-column: content-start / content-end;
grid-row: header-start / content-end;
}
<div class="wrapper">
<div class="box header">Header</div>
<div class="box sidebar">Sidebar</div>
<div class="overlay">Content</div>
</div>
Depending on how you want to overlap the following code works, but need to be adapted:
There's a lot of other way to do this...
body {
margin: 40px;
}
.sidebar {
grid-area: sidebar;
}
.content {
grid-area: content;
}
.header {
grid-area: header;
}
.wrapper {
display: grid;
grid-gap: 10px;
grid-template-columns: 120px 120px 120px;
grid-template-rows: 30px 30px auto auto;
grid-template-areas:
"header header header"
"sidebar content content";
background-color: #fff;
color: #444;
}
.box {
background-color: #444;
color: #fff;
border-radius: 5px;
padding: 20px;
font-size: 150%;
}
.header {
background-color: #999;
grid-row: 1 / 3;
}
.sidebar {
background-color: red;
z-index: 10;
grid-row: 2 / 4;
height: 300px;
}
.overlay {
background-color: red;
z-index: 10;
grid-column: content-start / content-end;
grid-row: 3 / 4;
}
<div class="wrapper">
<div class="box header">Header</div>
<div class="box sidebar">Sidebar</div>
<div class="overlay">Content</div>
</div>

How to make a fixed size content

Goal:
Make the content to have fixed width 700px in desktop only and the left-content and right-content width should adapt to desktop's width.
Problem:
I don't know how to solve it in a good way.
Info:
*The layout needs to take account to responsive design.
*Desktop width size start att min-width 901px
*Stil newbie in css layout
Jsbin:
https://jsbin.com/wegebemoqe/edit?html,css,output
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8" />
</head>
<body>
<div id="container">
<div id="top-content" class="palette-1">
top
</div>
<div id="content" class="palette-2">
content
</div>
<div id="footer" class="palette-4">
footer
</div>
<div id="left-content" class="palette-5">
</div>
<div id="right-content" class="palette-5">
</div>
</div>
</body>
</html>
body {
color: white;
text-align: center;
box-sizing: content-box;
margin: 20px;
}
.palette-1 {
background-color: #83B2FF;
}
.palette-2 {
background-color: #8BF18B;
}
.palette-4 {
background-color: #FF8650;
}
.palette-5 {
background-color: #FF555E;
}
#container {
margin: 2.5rem;
padding: 0.625rem;
background-color: #FFE981;
height: 37.5rem;
width: calc(100vw - 10rem);
display: grid;
grid-template-areas:
"header header header header"
"left-content content content right-content"
"footer footer footer footer";
row-gap: 1rem;
}
#media screen and (min-width: 901px) {
#content {
width: 700px;
}
}
#media screen and (max-width: 900px) {
#container {
grid-template-areas:
"header header"
"content content"
"footer footer"
}
#left-content, #right-content {
display: none;
}
}
.item {
padding: 1.5rem;
}
#top-content {
grid-area: header;
}
#content {
grid-area: content;
}
#footer {
grid-area: footer;
}
Why you don't set for #content that size when you need or example 700px, and when you don't need just set width: auto.
https://jsbin.com/tubodokusa/edit?html,output
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8" />
</head>
<body>
<div id="container">
<div id="top-content" class="palette-1">
<div id="testtest">
<img src="https://i2.wp.com/vanillicon.com/9d348569b83638e8dea4e9ef05a828b4_200.png" width="100px" height="45px" />
</div>
<div id="asdfasdf">
<span onclick="myFunction2()">Menu</span>
<img onclick="myFunction()" src="https://i2.wp.com/vanillicon.com/9d348569b83638e8dea4e9ef05a828b4_200.png" width="100px" height="45px" />
</div>
<ul id="iconmenu" class="nav-menu">
<li class="title">Coffee</li>
<li class="title">Tea</li>
<li class="title">Milk</li>
</ul>
</div>
<div id="content" class="palette-2">
content
</div>
<div id="footer" class="palette-4">
footer
</div>
</div>
</body>
</html>
body {
color: white;
text-align: center;
box-sizing: content-box;
margin: 0;
}
.palette-1 {
background-color: #83B2FF;
}
.palette-2 {
background-color: #8BF18B;
}
.palette-4 {
background-color: #FF8650;
}
.palette-5 {
background-color: #FF555E;
}
#container {
}
#content {
grid-area: content;
}
#footer {
grid-area: footer;
}
#media only screen and (min-width: 1030px) {
#container {
background-color: #FFE981;
width: 100%;
display: grid;
grid-template-areas:
"left-header header right-header"
"left-content content right-content"
"left-footer footer right-footer";
row-gap: 1rem;
display: grid;
/*
grid-template-columns: 1fr fit-content(500px) 1fr;
grid-template-columns: 1fr auto 1fr; */
grid-gap: 5px;
box-sizing: border-box;
height: 200px;
background-color: #8cffa0;
padding: 10px;
grid-template-columns: 1fr 1000px 1fr;
grid-template-rows: auto auto auto;
}
#top-content {
grid-area: header;
display: flex;
align-items: center;
justify-content: center;
border-top: 3px solid #425c62;
}
#asdfasdf {
display: none;
}
ul.nav-menu {
margin: 0;
}
ul.nav-menu > li {
display: inline-block;
padding: 0 10px 0 10px;
margin: 0;
line-height: 70px;
border-top: 1px solid #83B2FF;
}
ul.nav-menu > li:hover {
background-color: #2779BF;
border-top: 1px solid #425c62;
}
#content {
}
}
#media only screen and (max-width: 1029px) {
#container {
grid-template-areas:
"header"
"content"
"footer"
}
#top-content {
grid-area: header;
align-items: center;
}
#left-content, #right-content {
display: none;
}
.mystyle {
display: none;
transition: all 1s ease-in;
padding: 0 0 0 0;
line-height: 0;
}
#testtest {
background-color: blue;
}
#asdfasdf {
/**/
grid-area: header;
display: flex;
align-items: center;
justify-content: space-between;
background-color: grey;
}
ul.nav-menu {
margin: 0;
}
ul.nav-menu > li {
display: inline-block;
padding: 0 10px 0 10px;
margin: 0;
line-height: 70px;
border-top: 1px solid #83B2FF;
}
ul.nav-menu > li:hover {
background-color: #2779BF;
border-top: 1px solid #425c62;
}
#content {
}
}
function myFunction() {
var element = document.getElementById("iconmenu");
element.classList.add("mystyle");
}
function myFunction2() {
var element = document.getElementById("iconmenu");
element.classList.remove("mystyle");
}

Blazor component flex lines go outside of the component layout

I created blazor calendar component which consists of two parts Header and weekview components. The component flex lines go beyond the component itself and I could not figure out Why? I have attached a screenshot of the issue.
Header (Calendar Component) code
<div class="maincontainer">
<div class="viewtitle">Augest 2022</div>
<div class="lbuttons">
<button class="button"><</button>
<button class="button">></button>
<button class="button">Today</button>
</div>
<div class="mbuttons">
<label class="datelabel">Monady, Augest 21, 2022</label>
<input class="dateinput" type="datetime-local" id="schedule-time"
name="schedule-time" value="2022-06-12T19:30"
min="2022-06-07T00:00" max="2022-06-14T00:00">
<input class="button" type="button" id="btnsubmit" value="Submit">
</div>
<div class="rbuttons">
<button class="button" #onclick="#(() => DayView_Click())" #onclick:stopPropagation="true">Day</button>
<button class="button" #onclick="#(() => WeekView_Click())" #onclick:stopPropagation="true">Week</button>
<button class="button" #onclick="#(() => MonthView_Click())" #onclick:stopPropagation="true">Month</button>
</div>
</div>
#switch (CurrentView)
{
case CalendarViewOption.MonthView:
<MonthViewComponent></MonthViewComponent>
break;
case CalendarViewOption.DayView:
<DayViewComponent></DayViewComponent>
break;
case CalendarViewOption.WeekView:
<WeekViewComponent></WeekViewComponent>
break;
}
CSS
body {
margin: 0;
padding: 0;
}
.maincontainer {
background: #E7EAF6;
display: grid;
grid-template-columns: minmax(100px, 1fr) auto minmax(100px, 1fr);
grid-template-rows: auto
}
.viewtitle {
grid-column: 1/4;
grid-row: 1;
justify-self: center;
padding: 5px 5px 5px 5px;
color: darkblue;
font-weight: bold;
font-size: 16px;
}
.lbuttons {
grid-column: 1/2;
grid-row: 2;
justify-self: start;
}
.mbuttons {
grid-column: 2/3;
grid-row: 2;
justify-self: center;
}
.rbuttons {
grid-column: 3/4;
grid-row: 2;
justify-self: end;
}
.button {
background-color: black;
color: white;
border: 2px solid #555555;
padding: 3px;
margin: 0;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
border-radius: 5px;
cursor: pointer;
}
.button:hover {
background-color: white;
color: black;
}
.datelabel {
color: black;
font-weight: bold;
}
.dateinput {
padding: 3px 3px;
margin: 2px 0;
border: 1px solid rgb(130, 128, 128);
border-radius: 4px;
box-sizing: border-box;
cursor: pointer;
}
WeekView
<div class="calendar-container">
<div class="header">
<ul class="weekdays">
<li>Sun</li>
<li>Mon</li>
<li>Tue</li>
<li>Wed</li>
<li>Thu</li>
<li>Fri</li>
<li>Sat</li>
</ul>
<ul class="daynumbers">
<li>20</li>
<li>21</li>
<li>22</li>
<li>23</li>
<li>24</li>
<li>25</li>
<li>26</li>
</ul>
</div>
<div class="timeslots-container">
<ul class="timeslots">
<li>8<sup>am</sup></li>
<li>9<sup>am</sup></li>
<li>10<sup>am</sup></li>
<li>11<sup>am</sup></li>
<li>12<sup>pm</sup></li>
<li>4<sup>pm</sup></li>
<li>5<sup>pm</sup></li>
<li>6<sup>pm</sup></li>
<li>7<sup>pm</sup></li>
<li>8<sup>pm</sup></li>
<li>9<sup>pm</sup></li>
<li>10<sup>pm</sup></li>
</ul>
</div>
<div class="event-container">
<div class="slot slot-1">
<div class="event-staus"></div>
<span>Event A</span>
</div>
<div class="slot slot-2" style="height: 60px; grid-row: 1; grid-column: 1;">
<div class="event-staus"></div>
<span>Event A</span>
</div>
</div>
CSS
body {
margin: 0;
padding: 0;
}
li {
list-style: none;
}
ul {
padding: 0;
margin: 0;
}
.calendar-container {
display: grid;
grid-template-columns: 50px auto;
grid-template-rows: auto;
gap: 1px 1px;
grid-template-areas:
". header"
"timeslots-container main";
background: #325288;
}
.weekdays,
.daynumbers {
display: grid;
grid-template-columns: repeat(7, 1fr);
}
.daynumbers {
min-height: 1em;
}
.weekdays {
background: #19456B;
color: white
}
.header {
background-color: gainsboro;
grid-area: header;
}
.timeslots-container {
background-color: lightgray;
grid-area: timeslots-container;
align-items: center;
}
.timeslots {
display: flex;
flex-direction: column;
align-items: center;
}
.timeslots li {
min-height: 60px;
}
.timeslots li::after {
content: "";
position: absolute;
left: 10px;
width: 100%;
height: 1px;
background: lightgray;
z-index: 1;
}
.event-container {
display: grid;
grid-template-columns: repeat(7, auto);
grid-template-rows: repeat(48, auto);
grid-area: main;
position: relative;
}
.slot {
position: absolute;
background: darkcyan;
border-radius: 5px;
z-index: 5;
color: white;
font-size: 12px;
}
.slot-1 {
height: 30px;
grid-row: 106;
grid-column: 3;
}
Screenshot
Your issue is with:
.timeslots li::after {
content: "";
position: absolute;
left: 10px;
width: 100%;
height: 1px;
background: lightgray;
z-index: 1;
}
setting it to left: 10px is a mistake and why its causing your code to look like this, because technically it is taking left: 10px on the entire page. You need to set it so that it does not overlap the li element by setting it to relative so it stays inside.
So I have done a few changes to your css.
First I added this css:
.calendar-container {
overflow: hidden;
}
Then I set the li elements to relative:
.timeslots li {
position: relative;
}
then I adjusted your li::after css:
.timeslots li::after {
left: 0px;
width: 3000px;
}
this should solve your problem since the ::after now stays inside the li and not the entire page, and the overflow: hidden hides any overflow that causes side-scroll.

Not getting the layout I want in the nav code with CSS Grid i want it to take upp the hole width [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 months ago.
Improve this question
I use grids to customise my html layout and it does not work as I want. I want my nav to take all available width.
Here is my code:
header {
text-align: center;
grid-area: header;
border: solid;
}
#nav1 {
text-decoration: none;
border: solid;
background-color: green;
grid-area: MH;
width: 1fr;
text-align: center;
}
#nav2 {
text-decoration: none;
border: solid;
background-color: red;
grid-area: MC;
width: 1frs;
text-align: center;
}
#nav3 {
text-decoration: none;
border: solid;
background-color: yellow;
grid-area: start;
width: 1fr;
text-align: center;
}
footer {
grid-area: footer;
border: solid;
background-color: orange;
margin-top: 0px;
height: 100px;
}
main {
text-decoration: none;
border: solid;
background-color: gray;
grid-area: main;
height: 500px;
color: #ff00eb;
border-color: black;
}
aside {
width: 0.5fr;
border: solid;
background-color: purple;
grid-area: aside;
}
#big-container,
nav {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
grid-template-areas: 'header header header' 'MH MC start' 'main main aside' 'footer footer footer ';
grid-gap: 0px;
padding: 0px;
<!-- detta är min header-->
<header>
<h1></h1>
</header>
<div id="big-container">
<nav>
mitt hus
min calender
main
</nav>
<main>
main
</main>
<aside>
aside
</aside>
<footer>
footer
</footer>
</div>
I would assign to the nav bar the display flex attribute. Like that:
header {
text-align: center;
grid-area: header;
border: solid;
}
footer {
grid-area: footer;
border: solid;
background-color: orange;
margin-top: 0px;
height: 100px;
}
main {
text-decoration: none;
border: solid;
background-color: gray;
grid-area: main;
height: 500px;
color: #ff00eb;
border-color: black;
}
aside {
width: 0.5fr;
border: solid;
background-color: purple;
grid-area: aside;
}
#big-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto;
grid-template-areas: 'header header header' 'MH MC start' 'main main aside' 'footer footer footer ';
grid-gap: 0px;
padding: 0px;
}
nav {
width: 100%;
background: lightblue;
display: flex;
justify-content: center;
}
nav > a {
display: block;
text-decoration: none;
border: solid;
text-align: center;
width:100%;
}
nav > a:nth-child(1) {
background-color: green;
}
nav > a:nth-child(2) {
background-color: green;
}
nav > a:nth-child(3) {
background-color: green;
}
<!-- detta är min header-->
<header>
<h1></h1>
</header>
<nav>
mitt hus
min calender
main
</nav>
<div id="big-container">
<main>
main
</main>
<aside>
aside
</aside>
<footer>
footer
</footer>
</div>
Here is a simplified version (in terms of code) of what you wanna achieve:
body {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-areas: "header header header" "nav nav nav" "main main aside" "footer footer footer ";
}
header {
text-align: center;
grid-area: header;
border: solid;
}
nav {
grid-area: nav;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
#nav1 {
text-decoration: none;
border: solid;
background-color: green;
text-align: center;
}
#nav2 {
text-decoration: none;
border: solid;
background-color: red;
text-align: center;
}
#nav3 {
text-decoration: none;
border: solid;
background-color: yellow;
text-align: center;
}
main {
text-decoration: none;
border: solid;
background-color: gray;
grid-area: main;
height: 500px;
color: #ff00eb;
border-color: black;
}
aside {
width: 0.5fr;
border: solid;
background-color: purple;
grid-area: aside;
}
footer {
grid-area: footer;
border: solid;
background-color: orange;
margin-top: 0px;
height: 100px;
}
<header>
header
</header>
<nav>
mitt hus
min calender
main
</nav>
<main>
main
</main>
<aside>
aside
</aside>
<footer>
footer
</footer>

Border after each row in CSS Grid

I'm trying to make a border-bottom after each row using CSS grid with the content aligned to center. I can't get my head around it.
I want .line to fill the width of the entire .wrapper container.
How can I achieve that?
Here is the code:
* {
box-sizing: border-box;
}
.outer {
width: 80%;
margin: 0 auto;
}
.wrapper {
border: 2px solid #f76707;
border-radius: 5px;
background-color: #fff4e6;
display: grid;
grid-template-columns: repeat(3, auto) max-content;
justify-content: center;
}
.wrapper>div:not(.line) {
border: 2px solid #ffa94d;
border-radius: 5px;
background-color: #ffd8a8;
padding: 1em;
color: #d9480f;
}
.line {
grid-column-start: 1;
grid-column-end: 6;
height: 2px;
border-bottom: 1px solid black;
width: 100%;
}
<div class="outer">
<div class="wrapper">
<div>1111111</div>
<div>222</div>
<div>3333333333</div>
<div class="line"></div>
<div>4444</div>
<div>555555555</div>
<div>99999999999</div>
</div>
</div>
Instead of justify-content to center content you could add additional columns before and after your content, both with 1fr.
Then position the first div and the div after .line to the start at the second column.
Fiddle
* {
box-sizing: border-box;
}
.outer {
width: 80%;
margin: 0 auto;
}
.wrapper {
border: 2px solid #f76707;
border-radius: 5px;
background-color: #fff4e6;
display: grid;
grid-template-columns: 1fr repeat(3, auto) 1fr;
}
.wrapper>div:not(.line) {
border: 2px solid #ffa94d;
border-radius: 5px;
background-color: #ffd8a8;
padding: 1em;
color: #d9480f;
}
.wrapper > div:first-of-type,
.line + div {
grid-column: 2;
}
.line {
grid-column: 1 / -1;
height: 1px;
background: black;
}
<div class="outer">
<div class="wrapper">
<div>1111111</div>
<div>222</div>
<div>3333333333</div>
<div class="line"></div>
<div>4444</div>
<div>555555555</div>
<div>99999999999</div>
</div>
</div>
Here's a responsive solution that works with a variable number of items and without adding silly hard coded divs. Basically every item has a line below, the complicated part is determining the last row items which must not have a line. The example uses flex-box (and LESS) but that's not relevant here, it would also work with grid.
.grid {
display: flex;
}
.grid-item{
position: relative;
.one-col{
flex-basis: 100%/1;
&:nth-last-child(1){
&:after{ border-bottom: 0; }
}
}
.two-cols{
flex-basis: 100%/2;
&:nth-last-child(1),
&:nth-last-child(2):nth-child(odd){
&:after{ border-bottom: 0; }
}
}
.three-cols{
flex-basis: 100%/3;
&:nth-last-child(1),
&:nth-last-child(2):nth-child(3n+1),
&:nth-last-child(2):nth-child(3n+2),
&:nth-last-child(3):nth-child(3n+1){
&:after{ border-bottom: 0; }
}
}
.four-cols{
flex-basis: 100%/4;
&:nth-last-child(1),
&:nth-last-child(2):nth-child(4n+1),
&:nth-last-child(2):nth-child(4n+2),
&:nth-last-child(2):nth-child(4n+3),
&:nth-last-child(3):nth-child(4n+1),
&:nth-last-child(3):nth-child(4n+2),
&:nth-last-child(4):nth-child(4n+1){
&:after{ border-bottom: 0; }
}
}
#media screen and (max-width: #screen__sm) {
.grid-item .one-col;
}
#media screen and (min-width: #screen__sm) and (max-width: (#screen__md - 1)) {
.grid-item .two-cols;
}
#media screen and (min-width: #screen__md) and (max-width: (#screen__lg - 1)) {
.grid-item .three-cols;
}
#media screen and (min-width: #screen__lg) {
.grid-item .four-cols;
}
&:after{
content: "";
display: block;
position: absolute;
left: 0;
right: 0;
bottom: 0;
border-bottom: solid 1px black;
}
I had some success by using nth-of-type and switching the line to a different type (<span>).
I also added a first and sixth column for the line to span,
while the other items only occupy column 2-5.
* {
box-sizing: border-box;
}
.outer {
width: 80%;
margin: 0 auto;
}
.wrapper {
border: 2px solid #f76707;
border-radius: 5px;
background-color: #fff4e6;
display: grid;
grid-template-columns: 1fr repeat(3, auto) 1fr;
justify-content: center;
}
.wrapper>div {
border: 2px solid #ffa94d;
border-radius: 5px;
background-color: #ffd8a8;
padding: 1em;
color: #d9480f;
}
.wrapper>div:nth-of-type(3n+1) {
grid-column: 2;
}
.line {
grid-column: 1/6;
height: 2px;
border-bottom: 1px solid black;
}
<div class="outer">
<div class="wrapper">
<div>1111111</div>
<div>222</div>
<div>3333333333</div>
<span class="line"></span>
<div>4444</div>
<div>555555555</div>
<div>6666666</div>
<span class="line"></span>
<div>77777</div>
<div>888888888</div>
<div>99</div>
</div>
</div>