Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!-- Starter code: heading and empty flag container -->
<h1 id='gradient'>Happy Independence Day!</h1>
<div id='flag'></div>
              
            
!

CSS

              
                /* Starter Code: all CSS properties needed for exercise */
/* Read the comments and play with the values to see how they work! */

#gradient {
  /*  Fallback bg color:  */
  background-color: red;
  /*  Center text on page  */
  text-align: center;
  /*  Create gradient  */
  background: radial-gradient(circle, blue 0%, white 10%, red 20%);
  /*  Mask the background so only the text is seen  */
  -webkit-background-clip: text;
  /*  Set text to transparent so gradient shows through  */
  -webkit-text-fill-color: transparent;
  /*  Add blue text border (width and color)  */
  -webkit-text-stroke: 1px blue;
}

#flag {
  /*  Manually set flag dimensions  */
  height: 300px;
  width: 500px;
  /*  Add border  */
  border: 1px solid black;
  /*  Center flag on page  */
  margin: 0 auto;
  position: relative;
}

#union {
  /*  Set color and dimensions  */
  background-color: blue;
  height: 53.85%;
  width: 40%;
  /*  Position union on top of other divs  */
  z-index: 1;
/*  Place union in upper left corner of flag div  */
  position: absolute;
  top: 0;
  left: 0;
  text-align: center;
  display: flex;
  /*  Children displayed top to bottom  */
  flex-direction: column;
  justify-content: space-between;
}

.star-row {
  /*  Use flexbox  */
  /*  Children displayed left to right by default  */
  display: flex;
  justify-content: space-between;
  /*  Add small margin around rows  */
  margin: 3px;
}

.five {
  /*  Add spacing so stars are between top and bottom stars  */
  padding: 0px 9%;
}

.fa-star {
  /*  Set color and size of star icons  */
  color: white;
  font-size: 12px;
}

#stripes {
  /*  Set stripes to fill available space  */
  height: 100%;
  width: 100%;
  /*  Use Flexbox  */
  display: flex;
  /*  Children displayed top to bottom  */
  flex-direction: column;
}

.red {
  /*  Set color  */
  background-color: red;
  /*  Set stripe to fill available space  */
  width: 100%;
  height: 100%;
}

.white {
  /*  Set color  */
  background-color: white;
  /*  Set stripe to fill available space  */
  width: 100%;
  height: 100%;
}

              
            
!

JS

              
                // function to add stripes to flag
const stripes = () => {
  // find flag in html
  let flag = document.getElementById("flag");
  // create new div for stripes section
  let stripes = document.createElement("div");
  // set CSS id for stripes section
  stripes.id = "stripes";

  // enter for loop to create 13 stripes
  for (let i = 0; i < 13; i++) {
    // create individual stripe
    let stripe = document.createElement("div");
    // if the remainder of i / 2 is 0 (even number)
    if (i % 2 === 0) {
      // set class to red
      stripe.className = "red";
      // if the remainder of i / 2 is not 0 (odd number)
    } else {
      // set class to white
      stripe.className = "white";
      // close if statment
    }
    // add stripe to stripes container
    stripes.appendChild(stripe);
    // close for loop
  }
  // add stripes container to flag
  flag.appendChild(stripes);
  // close function
};

// function to add stars to flag
const stars = () => {
  // find flag in HTML
  let flag = document.getElementById("flag");
  // create new div for union (blue star section)
  let union = document.createElement("div");
  // set union's id for CSS
  union.id = "union";

  // for loop to add the 9 rows of stars
  for (let i = 0; i < 9; i++) {
    // create div for row of stars
    let row = document.createElement("div");
    // create empty variable for number of stars in row
    let num;

    // if the remainder of i / 2 is 0 (even number)
    if (i % 2 === 0) {
      // set class names
      row.className = "star-row six";
      // set number of stars to 6
      num = 6;
      // if the remainder of i / 2 is not 0 (odd number)
    } else {
      // set class names
      row.className = "star-row five";
      // set number of stars to 5
      num = 5;
      // close if statement
    }

    // enter for loop to add stars to row
    for (let j = 0; j < num; j++) {
      // add star icon's HTML (from fontAwesome) to row div
      row.innerHTML += '<i class="fas fa-star"></i>';
      // close j for loop
    }
    // add row to union
    union.appendChild(row);
    // close i for loop
  }

  // add union to flag
  flag.appendChild(union);
  // close function
};

// Call functions to add flag to the DOM
stripes();
stars();

              
            
!
999px

Console