CSS Square background - image





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















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 '18 at 12:20


















0















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 '18 at 12:20














0












0








0


0






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 '18 at 7:53









fiza khan

1,006521




1,006521










asked Nov 22 '18 at 7:28









24sharon24sharon

50321036




50321036













  • 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 '18 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 '18 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 '18 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 '18 at 12:20












2 Answers
2






active

oldest

votes


















2














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

































    2














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


      }
      });














      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









      2














      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






























        2














        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




























          2












          2








          2







          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 '18 at 6:26

























          answered Nov 22 '18 at 9:06









          Temani AfifTemani Afif

          82.1k104794




          82.1k104794

























              2














              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




























                2














                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


























                  2












                  2








                  2







                  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 '18 at 8:26









                  Carol McKayCarol 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.




                      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

                      How to change which sound is reproduced for terminal bell?

                      Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                      Can I use Tabulator js library in my java Spring + Thymeleaf project?