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
enter image description here



This is the result that I got for now
enter image description here










share|improve this question
























  • 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















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
enter image description here



This is the result that I got for now
enter image description here










share|improve this question
























  • 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













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
enter image description here



This is the result that I got for now
enter image description here










share|improve this question















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
enter image description here



This is the result that I got for now
enter image description here






.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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












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>








share|improve this answer






























    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>








    share|improve this answer





















      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',
      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
      });


      }
      });














      draft saved

      draft discarded


















      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

























      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>








      share|improve this answer



























        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>








        share|improve this answer

























          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>








          share|improve this answer














          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>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 23 at 6:26

























          answered Nov 22 at 9:06









          Temani Afif

          61.2k93572




          61.2k93572
























              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>








              share|improve this answer

























                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>








                share|improve this answer























                  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>








                  share|improve this answer












                  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>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 at 8:26









                  Carol McKay

                  1,9011711




                  1,9011711






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      What visual should I use to simply compare current year value vs last year in Power BI desktop

                      How to ignore python UserWarning in pytest?

                      Alexandru Averescu