multiple elements spanning across viewport width - CSS GRID
How to make multiple elements span across the viewport width and apply a certain background color while the center columns width is the same as other elements width that are not occupying the full width of the viewport. This has to be done using the CSS Grid system.
I asked a similar question before, but that was on how to do it on a single element. The answer is great but I cannot apply that on other elements.
What I need is a way to apply this to multiple elements and must be supported by modern browsers.
So far I came up with this solution but I don't believe it is elegant enough to be used for production as I used other <div>
elements to overlap.
.container
display: grid;
grid-template-columns: 1fr repeat(4, minmax(min-content, 150px)) 1fr;
grid-row-gap: 20px;
/*positioning*/
.span__across-1
grid-area: 1 / 2 / 1 / span 4;
.span__across-underlay-1
grid-area: 1 / 1 / 1 / span 7;
.content-1
grid-area: 2 / 2 / 2 / span 4;
.span__across-2
grid-area: 3 / 2 / 3 / span 4;
.span__across-underlay-2
grid-area: 3 / 1 / 3 / span 7;
.content-2
grid-area: 4 / 2 / 4 / span 4;
/*decoration*/
.span__across,
.span__across-underlay,
.content
background-color: grey;
height: 50px;
.span__across,
.content
border: 1px solid red;
position: relative;
<body class="container">
<div class="span__across span__across-1">this box should stay aligned with the content box</div>
<div class="span__across-underlay span__across-underlay-1"></div>
<div class="content content-1">Content box</div>
<div class="span__across span__across-2">this box should stay aligned with the content box</div>
<div class="span__across-underlay span__across-underlay-2"></div>
<div class="content content-2">Content box</div>
</body>
Or check this jsFiddle: https://jsfiddle.net/lenny86/q9s3r80t/15/
html css css3 responsive-design css-grid
add a comment |
How to make multiple elements span across the viewport width and apply a certain background color while the center columns width is the same as other elements width that are not occupying the full width of the viewport. This has to be done using the CSS Grid system.
I asked a similar question before, but that was on how to do it on a single element. The answer is great but I cannot apply that on other elements.
What I need is a way to apply this to multiple elements and must be supported by modern browsers.
So far I came up with this solution but I don't believe it is elegant enough to be used for production as I used other <div>
elements to overlap.
.container
display: grid;
grid-template-columns: 1fr repeat(4, minmax(min-content, 150px)) 1fr;
grid-row-gap: 20px;
/*positioning*/
.span__across-1
grid-area: 1 / 2 / 1 / span 4;
.span__across-underlay-1
grid-area: 1 / 1 / 1 / span 7;
.content-1
grid-area: 2 / 2 / 2 / span 4;
.span__across-2
grid-area: 3 / 2 / 3 / span 4;
.span__across-underlay-2
grid-area: 3 / 1 / 3 / span 7;
.content-2
grid-area: 4 / 2 / 4 / span 4;
/*decoration*/
.span__across,
.span__across-underlay,
.content
background-color: grey;
height: 50px;
.span__across,
.content
border: 1px solid red;
position: relative;
<body class="container">
<div class="span__across span__across-1">this box should stay aligned with the content box</div>
<div class="span__across-underlay span__across-underlay-1"></div>
<div class="content content-1">Content box</div>
<div class="span__across span__across-2">this box should stay aligned with the content box</div>
<div class="span__across-underlay span__across-underlay-2"></div>
<div class="content content-2">Content box</div>
</body>
Or check this jsFiddle: https://jsfiddle.net/lenny86/q9s3r80t/15/
html css css3 responsive-design css-grid
add a comment |
How to make multiple elements span across the viewport width and apply a certain background color while the center columns width is the same as other elements width that are not occupying the full width of the viewport. This has to be done using the CSS Grid system.
I asked a similar question before, but that was on how to do it on a single element. The answer is great but I cannot apply that on other elements.
What I need is a way to apply this to multiple elements and must be supported by modern browsers.
So far I came up with this solution but I don't believe it is elegant enough to be used for production as I used other <div>
elements to overlap.
.container
display: grid;
grid-template-columns: 1fr repeat(4, minmax(min-content, 150px)) 1fr;
grid-row-gap: 20px;
/*positioning*/
.span__across-1
grid-area: 1 / 2 / 1 / span 4;
.span__across-underlay-1
grid-area: 1 / 1 / 1 / span 7;
.content-1
grid-area: 2 / 2 / 2 / span 4;
.span__across-2
grid-area: 3 / 2 / 3 / span 4;
.span__across-underlay-2
grid-area: 3 / 1 / 3 / span 7;
.content-2
grid-area: 4 / 2 / 4 / span 4;
/*decoration*/
.span__across,
.span__across-underlay,
.content
background-color: grey;
height: 50px;
.span__across,
.content
border: 1px solid red;
position: relative;
<body class="container">
<div class="span__across span__across-1">this box should stay aligned with the content box</div>
<div class="span__across-underlay span__across-underlay-1"></div>
<div class="content content-1">Content box</div>
<div class="span__across span__across-2">this box should stay aligned with the content box</div>
<div class="span__across-underlay span__across-underlay-2"></div>
<div class="content content-2">Content box</div>
</body>
Or check this jsFiddle: https://jsfiddle.net/lenny86/q9s3r80t/15/
html css css3 responsive-design css-grid
How to make multiple elements span across the viewport width and apply a certain background color while the center columns width is the same as other elements width that are not occupying the full width of the viewport. This has to be done using the CSS Grid system.
I asked a similar question before, but that was on how to do it on a single element. The answer is great but I cannot apply that on other elements.
What I need is a way to apply this to multiple elements and must be supported by modern browsers.
So far I came up with this solution but I don't believe it is elegant enough to be used for production as I used other <div>
elements to overlap.
.container
display: grid;
grid-template-columns: 1fr repeat(4, minmax(min-content, 150px)) 1fr;
grid-row-gap: 20px;
/*positioning*/
.span__across-1
grid-area: 1 / 2 / 1 / span 4;
.span__across-underlay-1
grid-area: 1 / 1 / 1 / span 7;
.content-1
grid-area: 2 / 2 / 2 / span 4;
.span__across-2
grid-area: 3 / 2 / 3 / span 4;
.span__across-underlay-2
grid-area: 3 / 1 / 3 / span 7;
.content-2
grid-area: 4 / 2 / 4 / span 4;
/*decoration*/
.span__across,
.span__across-underlay,
.content
background-color: grey;
height: 50px;
.span__across,
.content
border: 1px solid red;
position: relative;
<body class="container">
<div class="span__across span__across-1">this box should stay aligned with the content box</div>
<div class="span__across-underlay span__across-underlay-1"></div>
<div class="content content-1">Content box</div>
<div class="span__across span__across-2">this box should stay aligned with the content box</div>
<div class="span__across-underlay span__across-underlay-2"></div>
<div class="content content-2">Content box</div>
</body>
Or check this jsFiddle: https://jsfiddle.net/lenny86/q9s3r80t/15/
.container
display: grid;
grid-template-columns: 1fr repeat(4, minmax(min-content, 150px)) 1fr;
grid-row-gap: 20px;
/*positioning*/
.span__across-1
grid-area: 1 / 2 / 1 / span 4;
.span__across-underlay-1
grid-area: 1 / 1 / 1 / span 7;
.content-1
grid-area: 2 / 2 / 2 / span 4;
.span__across-2
grid-area: 3 / 2 / 3 / span 4;
.span__across-underlay-2
grid-area: 3 / 1 / 3 / span 7;
.content-2
grid-area: 4 / 2 / 4 / span 4;
/*decoration*/
.span__across,
.span__across-underlay,
.content
background-color: grey;
height: 50px;
.span__across,
.content
border: 1px solid red;
position: relative;
<body class="container">
<div class="span__across span__across-1">this box should stay aligned with the content box</div>
<div class="span__across-underlay span__across-underlay-1"></div>
<div class="content content-1">Content box</div>
<div class="span__across span__across-2">this box should stay aligned with the content box</div>
<div class="span__across-underlay span__across-underlay-2"></div>
<div class="content content-2">Content box</div>
</body>
.container
display: grid;
grid-template-columns: 1fr repeat(4, minmax(min-content, 150px)) 1fr;
grid-row-gap: 20px;
/*positioning*/
.span__across-1
grid-area: 1 / 2 / 1 / span 4;
.span__across-underlay-1
grid-area: 1 / 1 / 1 / span 7;
.content-1
grid-area: 2 / 2 / 2 / span 4;
.span__across-2
grid-area: 3 / 2 / 3 / span 4;
.span__across-underlay-2
grid-area: 3 / 1 / 3 / span 7;
.content-2
grid-area: 4 / 2 / 4 / span 4;
/*decoration*/
.span__across,
.span__across-underlay,
.content
background-color: grey;
height: 50px;
.span__across,
.content
border: 1px solid red;
position: relative;
<body class="container">
<div class="span__across span__across-1">this box should stay aligned with the content box</div>
<div class="span__across-underlay span__across-underlay-1"></div>
<div class="content content-1">Content box</div>
<div class="span__across span__across-2">this box should stay aligned with the content box</div>
<div class="span__across-underlay span__across-underlay-2"></div>
<div class="content content-2">Content box</div>
</body>
html css css3 responsive-design css-grid
html css css3 responsive-design css-grid
asked Nov 13 '18 at 18:08
Lenny86Lenny86
657
657
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287078%2fmultiple-elements-spanning-across-viewport-width-css-grid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53287078%2fmultiple-elements-spanning-across-viewport-width-css-grid%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown