CSS Square background - image
up vote
0
down vote
favorite
I tried to make some square background using CSS only, but i got just line background without the option of horizontal lines.
This is my example code:
CSS
.container{
background-color:red;
width: 400px; height:200px; margin:0 auto;
background-image: linear-gradient(90deg, rgba(255, 255, 255, .5) 95px , transparent 50%),
linear-gradient(rgba(255, 255, 255, 0) 5px, transparent 100%);
background-size: 100px 100%;
}
<div class="container">
</div>
And this is the result that I am looking for
This is the result that I got for now
html css background-image linear-gradients repeating-linear-gradient
add a comment |
up vote
0
down vote
favorite
I tried to make some square background using CSS only, but i got just line background without the option of horizontal lines.
This is my example code:
CSS
.container{
background-color:red;
width: 400px; height:200px; margin:0 auto;
background-image: linear-gradient(90deg, rgba(255, 255, 255, .5) 95px , transparent 50%),
linear-gradient(rgba(255, 255, 255, 0) 5px, transparent 100%);
background-size: 100px 100%;
}
<div class="container">
</div>
And this is the result that I am looking for
This is the result that I got for now
html css background-image linear-gradients repeating-linear-gradient
Solutions below. The answer to what goes wrong in your code is in the second linear-gradient, both colours are fully transparent, so it does not have any visible result!
– Mr Lister
Nov 22 at 12:20
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I tried to make some square background using CSS only, but i got just line background without the option of horizontal lines.
This is my example code:
CSS
.container{
background-color:red;
width: 400px; height:200px; margin:0 auto;
background-image: linear-gradient(90deg, rgba(255, 255, 255, .5) 95px , transparent 50%),
linear-gradient(rgba(255, 255, 255, 0) 5px, transparent 100%);
background-size: 100px 100%;
}
<div class="container">
</div>
And this is the result that I am looking for
This is the result that I got for now
html css background-image linear-gradients repeating-linear-gradient
I tried to make some square background using CSS only, but i got just line background without the option of horizontal lines.
This is my example code:
CSS
.container{
background-color:red;
width: 400px; height:200px; margin:0 auto;
background-image: linear-gradient(90deg, rgba(255, 255, 255, .5) 95px , transparent 50%),
linear-gradient(rgba(255, 255, 255, 0) 5px, transparent 100%);
background-size: 100px 100%;
}
<div class="container">
</div>
And this is the result that I am looking for
This is the result that I got for now
.container{
background-color:red;
width: 400px; height:200px; margin:0 auto;
background-image: linear-gradient(90deg, rgba(255, 255, 255, .5) 95px , transparent 50%),
linear-gradient(rgba(255, 255, 255, 0) 5px, transparent 100%);
background-size: 100px 100%;
}
<div class="container">
</div>
.container{
background-color:red;
width: 400px; height:200px; margin:0 auto;
background-image: linear-gradient(90deg, rgba(255, 255, 255, .5) 95px , transparent 50%),
linear-gradient(rgba(255, 255, 255, 0) 5px, transparent 100%);
background-size: 100px 100%;
}
<div class="container">
</div>
html css background-image linear-gradients repeating-linear-gradient
html css background-image linear-gradients repeating-linear-gradient
edited Nov 22 at 7:53
fiza khan
653417
653417
asked Nov 22 at 7:28
24sharon
4872935
4872935
Solutions below. The answer to what goes wrong in your code is in the second linear-gradient, both colours are fully transparent, so it does not have any visible result!
– Mr Lister
Nov 22 at 12:20
add a comment |
Solutions below. The answer to what goes wrong in your code is in the second linear-gradient, both colours are fully transparent, so it does not have any visible result!
– Mr Lister
Nov 22 at 12:20
Solutions below. The answer to what goes wrong in your code is in the second linear-gradient, both colours are fully transparent, so it does not have any visible result!
– Mr Lister
Nov 22 at 12:20
Solutions below. The answer to what goes wrong in your code is in the second linear-gradient, both colours are fully transparent, so it does not have any visible result!
– Mr Lister
Nov 22 at 12:20
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
All you need is two gradients, one to define the horizontal lines and the other the vertical ones:
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
repeating-linear-gradient(to right,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px),
repeating-linear-gradient(to bottom,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px)
red;
}
<div class="container">
</div>
The above example will create an homogeneous grid. You can also consider multiple gradient in order to control each line alone:
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
/*vertical ones*/
linear-gradient(blue,blue) center/2px 100%,
linear-gradient(blue,blue) 25% 0/2px 100%,
linear-gradient(blue,blue) 85% 0/2px 100%,
/*horizontal ones*/
linear-gradient(blue,blue) 0 25%/100% 2px,
linear-gradient(blue,blue) 0 75%/100% 2px,
red;
background-repeat:no-repeat;
}
<div class="container">
</div>
add a comment |
up vote
2
down vote
The answer is in "repeating-linear-gradient()"
https://developer.mozilla.org/en-US/docs/Web/CSS/repeating-linear-gradient
.container{
background-color:red;
width: 400px; height:200px; margin:0 auto;
background-image:
repeating-linear-gradient(rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.25turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.75turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px);
}
<div class="container">
</div>
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
All you need is two gradients, one to define the horizontal lines and the other the vertical ones:
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
repeating-linear-gradient(to right,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px),
repeating-linear-gradient(to bottom,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px)
red;
}
<div class="container">
</div>
The above example will create an homogeneous grid. You can also consider multiple gradient in order to control each line alone:
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
/*vertical ones*/
linear-gradient(blue,blue) center/2px 100%,
linear-gradient(blue,blue) 25% 0/2px 100%,
linear-gradient(blue,blue) 85% 0/2px 100%,
/*horizontal ones*/
linear-gradient(blue,blue) 0 25%/100% 2px,
linear-gradient(blue,blue) 0 75%/100% 2px,
red;
background-repeat:no-repeat;
}
<div class="container">
</div>
add a comment |
up vote
2
down vote
accepted
All you need is two gradients, one to define the horizontal lines and the other the vertical ones:
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
repeating-linear-gradient(to right,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px),
repeating-linear-gradient(to bottom,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px)
red;
}
<div class="container">
</div>
The above example will create an homogeneous grid. You can also consider multiple gradient in order to control each line alone:
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
/*vertical ones*/
linear-gradient(blue,blue) center/2px 100%,
linear-gradient(blue,blue) 25% 0/2px 100%,
linear-gradient(blue,blue) 85% 0/2px 100%,
/*horizontal ones*/
linear-gradient(blue,blue) 0 25%/100% 2px,
linear-gradient(blue,blue) 0 75%/100% 2px,
red;
background-repeat:no-repeat;
}
<div class="container">
</div>
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
All you need is two gradients, one to define the horizontal lines and the other the vertical ones:
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
repeating-linear-gradient(to right,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px),
repeating-linear-gradient(to bottom,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px)
red;
}
<div class="container">
</div>
The above example will create an homogeneous grid. You can also consider multiple gradient in order to control each line alone:
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
/*vertical ones*/
linear-gradient(blue,blue) center/2px 100%,
linear-gradient(blue,blue) 25% 0/2px 100%,
linear-gradient(blue,blue) 85% 0/2px 100%,
/*horizontal ones*/
linear-gradient(blue,blue) 0 25%/100% 2px,
linear-gradient(blue,blue) 0 75%/100% 2px,
red;
background-repeat:no-repeat;
}
<div class="container">
</div>
All you need is two gradients, one to define the horizontal lines and the other the vertical ones:
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
repeating-linear-gradient(to right,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px),
repeating-linear-gradient(to bottom,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px)
red;
}
<div class="container">
</div>
The above example will create an homogeneous grid. You can also consider multiple gradient in order to control each line alone:
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
/*vertical ones*/
linear-gradient(blue,blue) center/2px 100%,
linear-gradient(blue,blue) 25% 0/2px 100%,
linear-gradient(blue,blue) 85% 0/2px 100%,
/*horizontal ones*/
linear-gradient(blue,blue) 0 25%/100% 2px,
linear-gradient(blue,blue) 0 75%/100% 2px,
red;
background-repeat:no-repeat;
}
<div class="container">
</div>
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
repeating-linear-gradient(to right,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px),
repeating-linear-gradient(to bottom,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px)
red;
}
<div class="container">
</div>
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
repeating-linear-gradient(to right,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px),
repeating-linear-gradient(to bottom,
transparent 0,transparent calc(50px - 2px),
blue calc(50px - 2px),blue 50px)
red;
}
<div class="container">
</div>
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
/*vertical ones*/
linear-gradient(blue,blue) center/2px 100%,
linear-gradient(blue,blue) 25% 0/2px 100%,
linear-gradient(blue,blue) 85% 0/2px 100%,
/*horizontal ones*/
linear-gradient(blue,blue) 0 25%/100% 2px,
linear-gradient(blue,blue) 0 75%/100% 2px,
red;
background-repeat:no-repeat;
}
<div class="container">
</div>
.container {
background-color: red;
width: 400px;
height: 200px;
margin: 0 auto;
background:
/*vertical ones*/
linear-gradient(blue,blue) center/2px 100%,
linear-gradient(blue,blue) 25% 0/2px 100%,
linear-gradient(blue,blue) 85% 0/2px 100%,
/*horizontal ones*/
linear-gradient(blue,blue) 0 25%/100% 2px,
linear-gradient(blue,blue) 0 75%/100% 2px,
red;
background-repeat:no-repeat;
}
<div class="container">
</div>
edited Nov 23 at 6:26
answered Nov 22 at 9:06
Temani Afif
61.2k93572
61.2k93572
add a comment |
add a comment |
up vote
2
down vote
The answer is in "repeating-linear-gradient()"
https://developer.mozilla.org/en-US/docs/Web/CSS/repeating-linear-gradient
.container{
background-color:red;
width: 400px; height:200px; margin:0 auto;
background-image:
repeating-linear-gradient(rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.25turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.75turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px);
}
<div class="container">
</div>
add a comment |
up vote
2
down vote
The answer is in "repeating-linear-gradient()"
https://developer.mozilla.org/en-US/docs/Web/CSS/repeating-linear-gradient
.container{
background-color:red;
width: 400px; height:200px; margin:0 auto;
background-image:
repeating-linear-gradient(rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.25turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.75turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px);
}
<div class="container">
</div>
add a comment |
up vote
2
down vote
up vote
2
down vote
The answer is in "repeating-linear-gradient()"
https://developer.mozilla.org/en-US/docs/Web/CSS/repeating-linear-gradient
.container{
background-color:red;
width: 400px; height:200px; margin:0 auto;
background-image:
repeating-linear-gradient(rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.25turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.75turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px);
}
<div class="container">
</div>
The answer is in "repeating-linear-gradient()"
https://developer.mozilla.org/en-US/docs/Web/CSS/repeating-linear-gradient
.container{
background-color:red;
width: 400px; height:200px; margin:0 auto;
background-image:
repeating-linear-gradient(rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.25turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.75turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px);
}
<div class="container">
</div>
.container{
background-color:red;
width: 400px; height:200px; margin:0 auto;
background-image:
repeating-linear-gradient(rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.25turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.75turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px);
}
<div class="container">
</div>
.container{
background-color:red;
width: 400px; height:200px; margin:0 auto;
background-image:
repeating-linear-gradient(rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.25turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px),
repeating-linear-gradient(0.75turn, rgba(255, 255, 255, .5), rgba(255, 255, 255, .25) 95px, red 100px);
}
<div class="container">
</div>
answered Nov 22 at 8:26
Carol McKay
1,9011711
1,9011711
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53425836%2fcss-square-background-image%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
Solutions below. The answer to what goes wrong in your code is in the second linear-gradient, both colours are fully transparent, so it does not have any visible result!
– Mr Lister
Nov 22 at 12:20