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

              
                <div class="date-pickler" id="dp1">
  <div class="date-str">
    <input id="yyyy" type="number" title="year" />
    <input id="mm" type="number" title="month" />
    <input id="dd" type="number" title="date" />
  </div>
  <ul class="year">
    year selection
  </ul>
  <ul class="month">
    month selection
  </ul>
  <div class="date">
    date selection
  </div>
  <button>Clear</button><button>Done</button>
</div>
              
            
!

CSS

              
                html,
body {
  font-family: sans-serif;
  background: azure;
}

.date-pickler {
  background: white;
  border: 1px solid grey;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  padding: 5px;
  border-radius: 2px;
  max-width: 200px;
  ul {
    margin:  8px 0;
  }
  .date-str {
    display: flex;
    input {
      width: 30%;
      flex-grow: 1;
    }
  }
  .year,
  .month,
  .date {
    list-style: none;
    padding: 0;
    display: flex;
    flex-wrap: wrap;

    li {
      cursor: pointer;
      border: 1px solid grey;
      margin-left: -1px;
      margin-top:-1px;
      text-align: center;
      line-height :150%;
      &:hover {
        background: yellow;
      }
    }
  }
  .year li {
    width: 30%;
    flex-grow: 1;
  }
  .month li {
    width: 30%;
    flex-grow: 1;
  }
  .date li {
    width: 14%;
    flex-grow: 1;
  }
}

              
            
!

JS

              
                var picklers = document.querySelectorAll(".date-pickler[id]");
console.log("found " + picklers.length + " Date Picklers");

for (var p of picklers) {
  var dp = new Dp(p);
  console.log(dp.yearPage);
}

function Dp(elem) {
  this.yearPage = elem.querySelector(".year");
  this.monthPage = elem.querySelector(".month");
  this.datePage = elem.querySelector(".date");

  this.yearField = elem.querySelector("#yyyy");
  this.monthField = elem.querySelector("#mm");
  this.dateField = elem.querySelector("#dd");

  this.toPage = function(page) {
    this.yearPage.style.display = "none";
    this.monthPage.style.display = "none";
    this.datePage.style.display = "none";

    if (page === "year") {
      this.yearPage.style.display = "flex";
    } else if (page === "month") {
      this.monthPage.style.display = "flex";
    } else if (page === "date") {
      this.datePage.style.display = "flex";
    }
  };
  
  this.toPage("year");
  
  var me = this;
  this.yearField.addEventListener("click", function(){
    me.toPage("year");
  });
  this.monthField.addEventListener("click", function(){
    me.toPage("month");
  });
   this.dateField.addEventListener("click", function(){
    me.toPage("date");
  });
  
  this.yearPage.innerHTML = "";
  for(var y=2004;y<=2018;y++){
    var div = document.createElement("li");
    div.innerHTML = y;
    // closure
    var a = function(yr,div){
      div.addEventListener("click",function(){
        me.yearField.value = yr;
        me.toPage("month");
      });
    };
    a(y,div);
    this.yearPage.appendChild(div);
  }
  
  var months = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".split(/,/);
  this.monthPage.innerHTML = "";
  for(var y=0;y<months.length;y++){
    var div = document.createElement("li");
    div.innerHTML = months[y];
    // closure
    var a = function(mon,m,div){
      div.addEventListener("click",function(){
        me.monthField.value = m+1;
        me.toPage("date");
      });
    };
    a(months[y],y,div);
    this.monthPage.appendChild(div);
  }
  
  //.. dates
   this.datePage.innerHTML = "";
  for(var y=0;y<30;y++){
    var div = document.createElement("li");
    div.innerHTML = y;
    // closure
    var a = function(mon,m,div){
      div.addEventListener("click",function(){
        me.dateField.value = m+1;
        // tODO close
      });
    };
    a(months[y],y,div);
    this.datePage.appendChild(div);
  }
}

              
            
!
999px

Console