Why don't background colors work in inline-grids
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
I created two divs; one with a display:inline-grid
property and another with display:grid
property. I want to apply a background color to the child elements of both divs but the div with the display:inline-grid
property is not coloring its elements.
HTML and CSS code
#inline
display: inline-grid;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
The output is:
How can I color the divs inside the inline-grid div?
html css css3 css-grid
add a comment |Â
up vote
6
down vote
favorite
I created two divs; one with a display:inline-grid
property and another with display:grid
property. I want to apply a background color to the child elements of both divs but the div with the display:inline-grid
property is not coloring its elements.
HTML and CSS code
#inline
display: inline-grid;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
The output is:
How can I color the divs inside the inline-grid div?
html css css3 css-grid
Your output image isn't actually displaying, might want to take a look at that
â JBDouble05
Aug 30 at 0:02
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
I created two divs; one with a display:inline-grid
property and another with display:grid
property. I want to apply a background color to the child elements of both divs but the div with the display:inline-grid
property is not coloring its elements.
HTML and CSS code
#inline
display: inline-grid;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
The output is:
How can I color the divs inside the inline-grid div?
html css css3 css-grid
I created two divs; one with a display:inline-grid
property and another with display:grid
property. I want to apply a background color to the child elements of both divs but the div with the display:inline-grid
property is not coloring its elements.
HTML and CSS code
#inline
display: inline-grid;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
The output is:
How can I color the divs inside the inline-grid div?
#inline
display: inline-grid;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
#inline
display: inline-grid;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
html css css3 css-grid
html css css3 css-grid
edited Aug 11 at 7:51
ProgrammerPer
203210
203210
asked Aug 11 at 7:38
user9218974
9911
9911
Your output image isn't actually displaying, might want to take a look at that
â JBDouble05
Aug 30 at 0:02
add a comment |Â
Your output image isn't actually displaying, might want to take a look at that
â JBDouble05
Aug 30 at 0:02
Your output image isn't actually displaying, might want to take a look at that
â JBDouble05
Aug 30 at 0:02
Your output image isn't actually displaying, might want to take a look at that
â JBDouble05
Aug 30 at 0:02
add a comment |Â
6 Answers
6
active
oldest
votes
up vote
4
down vote
accepted
This happens because display: inline-grid;
is a inline
elements
Basically, an inline element does not cause a line break (start on a
new line) and does not take up the full width of a page, only the
space bounded by its opening and closing tag. It is usually used
within other HTML elements.
if you want you can colour it by using some additional styles for sample width:100%;
in your case:
#inline
display: inline-grid;
width:100%;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
add a comment |Â
up vote
8
down vote
Being an inline element, it's width is defined by its content. But there is no content here.
Just add width:
#inline
display: inline-grid;
width: 150px;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
add a comment |Â
up vote
0
down vote
Just add a "width" attribute to your division:
#inline
display: inline-grid;
width: 100%;
add a comment |Â
up vote
0
down vote
I have just added width property to the #inline css and this is now working.
#inline
display: inline-grid;
width: 100%;
add a comment |Â
up vote
0
down vote
add width to inline elements because unlike block elements their width depends upon content inside them
add a comment |Â
up vote
-1
down vote
You must know why you should use any display type and when to use it, this is the best way to have the result you need
CSS Grid Layout Module
.grid-container
display: grid;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
text-align: center;
.grid-item
background-color: rgba(255, 255, 255, 0.8);
<div class="grid-container" style="grid-template-areas:
'header header header header header header'
'menu main main main right right'
'menu footer footer footer footer footer';">
<div class="grid-item" style="grid-area: header">
<h3>Header</h3>
</div>
<div class="grid-item" style="grid-area: menu">
<h3>Menu</h3>
</div>
<div class="grid-item" style="grid-area: main">
<h3>Main</h3>
</div>
<div class="grid-item" style="grid-area: right">
<h3>Right</h3>
</div>
<div class="grid-item" style="grid-area: footer">
<h3>Footer</h3>
</div>
</div>
Grid Layout
The CSS Grid Layout Module offers a grid-based layout system, with
rows and columns, making it easier to design web pages without having
to use floats and positioning.
More info ->
add a comment |Â
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
This happens because display: inline-grid;
is a inline
elements
Basically, an inline element does not cause a line break (start on a
new line) and does not take up the full width of a page, only the
space bounded by its opening and closing tag. It is usually used
within other HTML elements.
if you want you can colour it by using some additional styles for sample width:100%;
in your case:
#inline
display: inline-grid;
width:100%;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
add a comment |Â
up vote
4
down vote
accepted
This happens because display: inline-grid;
is a inline
elements
Basically, an inline element does not cause a line break (start on a
new line) and does not take up the full width of a page, only the
space bounded by its opening and closing tag. It is usually used
within other HTML elements.
if you want you can colour it by using some additional styles for sample width:100%;
in your case:
#inline
display: inline-grid;
width:100%;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
This happens because display: inline-grid;
is a inline
elements
Basically, an inline element does not cause a line break (start on a
new line) and does not take up the full width of a page, only the
space bounded by its opening and closing tag. It is usually used
within other HTML elements.
if you want you can colour it by using some additional styles for sample width:100%;
in your case:
#inline
display: inline-grid;
width:100%;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
This happens because display: inline-grid;
is a inline
elements
Basically, an inline element does not cause a line break (start on a
new line) and does not take up the full width of a page, only the
space bounded by its opening and closing tag. It is usually used
within other HTML elements.
if you want you can colour it by using some additional styles for sample width:100%;
in your case:
#inline
display: inline-grid;
width:100%;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
#inline
display: inline-grid;
width:100%;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
#inline
display: inline-grid;
width:100%;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
answered Aug 11 at 7:48
weBBer
3,87641545
3,87641545
add a comment |Â
add a comment |Â
up vote
8
down vote
Being an inline element, it's width is defined by its content. But there is no content here.
Just add width:
#inline
display: inline-grid;
width: 150px;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
add a comment |Â
up vote
8
down vote
Being an inline element, it's width is defined by its content. But there is no content here.
Just add width:
#inline
display: inline-grid;
width: 150px;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
add a comment |Â
up vote
8
down vote
up vote
8
down vote
Being an inline element, it's width is defined by its content. But there is no content here.
Just add width:
#inline
display: inline-grid;
width: 150px;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
Being an inline element, it's width is defined by its content. But there is no content here.
Just add width:
#inline
display: inline-grid;
width: 150px;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
#inline
display: inline-grid;
width: 150px;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
#inline
display: inline-grid;
width: 150px;
#block
display: grid;
div div
height: 50px;
div div:nth-child(1n)
background-color: green;
div div:nth-child(2n)
background-color: rebeccapurple;
div div:nth-child(3n)
background-color: aquamarine;
<body>
<div id="inline">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<div id="block">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</body>
answered Aug 11 at 7:46
vals
42.9k652108
42.9k652108
add a comment |Â
add a comment |Â
up vote
0
down vote
Just add a "width" attribute to your division:
#inline
display: inline-grid;
width: 100%;
add a comment |Â
up vote
0
down vote
Just add a "width" attribute to your division:
#inline
display: inline-grid;
width: 100%;
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Just add a "width" attribute to your division:
#inline
display: inline-grid;
width: 100%;
Just add a "width" attribute to your division:
#inline
display: inline-grid;
width: 100%;
answered Aug 11 at 7:50
Sami Al Morshedi
608
608
add a comment |Â
add a comment |Â
up vote
0
down vote
I have just added width property to the #inline css and this is now working.
#inline
display: inline-grid;
width: 100%;
add a comment |Â
up vote
0
down vote
I have just added width property to the #inline css and this is now working.
#inline
display: inline-grid;
width: 100%;
add a comment |Â
up vote
0
down vote
up vote
0
down vote
I have just added width property to the #inline css and this is now working.
#inline
display: inline-grid;
width: 100%;
I have just added width property to the #inline css and this is now working.
#inline
display: inline-grid;
width: 100%;
answered Aug 11 at 7:52
BharathwajRK
293
293
add a comment |Â
add a comment |Â
up vote
0
down vote
add width to inline elements because unlike block elements their width depends upon content inside them
add a comment |Â
up vote
0
down vote
add width to inline elements because unlike block elements their width depends upon content inside them
add a comment |Â
up vote
0
down vote
up vote
0
down vote
add width to inline elements because unlike block elements their width depends upon content inside them
add width to inline elements because unlike block elements their width depends upon content inside them
answered Aug 11 at 7:59
MaBb Khawaja
94
94
add a comment |Â
add a comment |Â
up vote
-1
down vote
You must know why you should use any display type and when to use it, this is the best way to have the result you need
CSS Grid Layout Module
.grid-container
display: grid;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
text-align: center;
.grid-item
background-color: rgba(255, 255, 255, 0.8);
<div class="grid-container" style="grid-template-areas:
'header header header header header header'
'menu main main main right right'
'menu footer footer footer footer footer';">
<div class="grid-item" style="grid-area: header">
<h3>Header</h3>
</div>
<div class="grid-item" style="grid-area: menu">
<h3>Menu</h3>
</div>
<div class="grid-item" style="grid-area: main">
<h3>Main</h3>
</div>
<div class="grid-item" style="grid-area: right">
<h3>Right</h3>
</div>
<div class="grid-item" style="grid-area: footer">
<h3>Footer</h3>
</div>
</div>
Grid Layout
The CSS Grid Layout Module offers a grid-based layout system, with
rows and columns, making it easier to design web pages without having
to use floats and positioning.
More info ->
add a comment |Â
up vote
-1
down vote
You must know why you should use any display type and when to use it, this is the best way to have the result you need
CSS Grid Layout Module
.grid-container
display: grid;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
text-align: center;
.grid-item
background-color: rgba(255, 255, 255, 0.8);
<div class="grid-container" style="grid-template-areas:
'header header header header header header'
'menu main main main right right'
'menu footer footer footer footer footer';">
<div class="grid-item" style="grid-area: header">
<h3>Header</h3>
</div>
<div class="grid-item" style="grid-area: menu">
<h3>Menu</h3>
</div>
<div class="grid-item" style="grid-area: main">
<h3>Main</h3>
</div>
<div class="grid-item" style="grid-area: right">
<h3>Right</h3>
</div>
<div class="grid-item" style="grid-area: footer">
<h3>Footer</h3>
</div>
</div>
Grid Layout
The CSS Grid Layout Module offers a grid-based layout system, with
rows and columns, making it easier to design web pages without having
to use floats and positioning.
More info ->
add a comment |Â
up vote
-1
down vote
up vote
-1
down vote
You must know why you should use any display type and when to use it, this is the best way to have the result you need
CSS Grid Layout Module
.grid-container
display: grid;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
text-align: center;
.grid-item
background-color: rgba(255, 255, 255, 0.8);
<div class="grid-container" style="grid-template-areas:
'header header header header header header'
'menu main main main right right'
'menu footer footer footer footer footer';">
<div class="grid-item" style="grid-area: header">
<h3>Header</h3>
</div>
<div class="grid-item" style="grid-area: menu">
<h3>Menu</h3>
</div>
<div class="grid-item" style="grid-area: main">
<h3>Main</h3>
</div>
<div class="grid-item" style="grid-area: right">
<h3>Right</h3>
</div>
<div class="grid-item" style="grid-area: footer">
<h3>Footer</h3>
</div>
</div>
Grid Layout
The CSS Grid Layout Module offers a grid-based layout system, with
rows and columns, making it easier to design web pages without having
to use floats and positioning.
More info ->
You must know why you should use any display type and when to use it, this is the best way to have the result you need
CSS Grid Layout Module
.grid-container
display: grid;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
text-align: center;
.grid-item
background-color: rgba(255, 255, 255, 0.8);
<div class="grid-container" style="grid-template-areas:
'header header header header header header'
'menu main main main right right'
'menu footer footer footer footer footer';">
<div class="grid-item" style="grid-area: header">
<h3>Header</h3>
</div>
<div class="grid-item" style="grid-area: menu">
<h3>Menu</h3>
</div>
<div class="grid-item" style="grid-area: main">
<h3>Main</h3>
</div>
<div class="grid-item" style="grid-area: right">
<h3>Right</h3>
</div>
<div class="grid-item" style="grid-area: footer">
<h3>Footer</h3>
</div>
</div>
Grid Layout
The CSS Grid Layout Module offers a grid-based layout system, with
rows and columns, making it easier to design web pages without having
to use floats and positioning.
More info ->
.grid-container
display: grid;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
text-align: center;
.grid-item
background-color: rgba(255, 255, 255, 0.8);
<div class="grid-container" style="grid-template-areas:
'header header header header header header'
'menu main main main right right'
'menu footer footer footer footer footer';">
<div class="grid-item" style="grid-area: header">
<h3>Header</h3>
</div>
<div class="grid-item" style="grid-area: menu">
<h3>Menu</h3>
</div>
<div class="grid-item" style="grid-area: main">
<h3>Main</h3>
</div>
<div class="grid-item" style="grid-area: right">
<h3>Right</h3>
</div>
<div class="grid-item" style="grid-area: footer">
<h3>Footer</h3>
</div>
</div>
.grid-container
display: grid;
grid-gap: 10px;
background-color: #2196F3;
padding: 10px;
text-align: center;
.grid-item
background-color: rgba(255, 255, 255, 0.8);
<div class="grid-container" style="grid-template-areas:
'header header header header header header'
'menu main main main right right'
'menu footer footer footer footer footer';">
<div class="grid-item" style="grid-area: header">
<h3>Header</h3>
</div>
<div class="grid-item" style="grid-area: menu">
<h3>Menu</h3>
</div>
<div class="grid-item" style="grid-area: main">
<h3>Main</h3>
</div>
<div class="grid-item" style="grid-area: right">
<h3>Right</h3>
</div>
<div class="grid-item" style="grid-area: footer">
<h3>Footer</h3>
</div>
</div>
answered Aug 11 at 7:59
M0ns1f
2,4252820
2,4252820
add a comment |Â
add a comment |Â
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51797561%2fwhy-dont-background-colors-work-in-inline-grids%23new-answer', 'question_page');
);
Post as a guest
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
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
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
Your output image isn't actually displaying, might want to take a look at that
â JBDouble05
Aug 30 at 0:02