3

I'm trying to style the jquery UI date picker.

Everything works fine with one exception.

I need to make everything centered but I can't seem to achieve that.

Here what i have so far:

    $('#calendar').datepicker({
        inline: true,
        firstDay: 1,
        showOtherMonths: true,
        dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
    });
.ui-datepicker,
.ui-datepicker table,
.ui-datepicker tr,
.ui-datepicker td,
.ui-datepicker th {
    margin: 0;
    padding: 0;
    border: none;
    border-spacing: 0;
}


.ui-datepicker {
    display: none;
    width: 100%;
    padding: 35px;
    cursor: default;
 
    text-transform: uppercase;
    font-family: Tahoma;
    font-size: 24px;
 
    background: #fff;
 
    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    border-radius: 4px;
    border:solid 1px #e91e62;
}


.ui-datepicker-header {
    position: relative;
    padding-bottom: 10px;
    border-bottom: 1px solid #d6d6d6;
}
 
.ui-datepicker-title { text-align: center; }
 
.ui-datepicker-month {
    position: relative;
    padding-right: 15px;
    color: #e91e62;
}
 
.ui-datepicker-year {
    padding-left: 8px;
    color: #e91e62;
}



.ui-datepicker-month:before {
    display: block;
    position: absolute;
    top: 5px;
    right: 0;
    width: 5px;
    height: 5px;
    content: '';
 
    background: #a5cd4e;
    background: -moz-linear-gradient(top, #a5cd4e 0%, #6b8f1a 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#a5cd4e), color-stop(100%,#6b8f1a));
    background: -webkit-linear-gradient(top, #a5cd4e 0%,#6b8f1a 100%);
    background: -o-linear-gradient(top, #a5cd4e 0%,#6b8f1a 100%);
    background: -ms-linear-gradient(top, #a5cd4e 0%,#6b8f1a 100%);
    background: linear-gradient(top, #a5cd4e 0%,#6b8f1a 100%);
 
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
}


.ui-datepicker-prev,
.ui-datepicker-next {
    position: absolute;
    top: -2px;
    padding: 5px;
    cursor: pointer;
}
 
.ui-datepicker-prev {
    left: 0;
    padding-left: 0;
}
 
.ui-datepicker-next {
    right: 0;
    padding-right: 0;
}
 
.ui-datepicker-prev span,
.ui-datepicker-next span{
    display: block;
    width: 5px;
    height: 10px;
    text-indent: -9999px;
 
    background-image: url(../img/arrows.png);
}
 
.ui-datepicker-prev span { background-position: 0px 0px; }
 
.ui-datepicker-next span { background-position: -5px 0px; }
 
.ui-datepicker-prev-hover span { background-position: 0px -10px; }
 
.ui-datepicker-next-hover span { background-position: -5px -10px; }


.ui-datepicker-calendar th {
    padding-top: 15px;
    padding-bottom: 10px;
 
    text-align: center;
    font-weight: normal;
    color: #a8a8a8;
    width:100%;
}

.ui-datepicker-calendar td {
    padding: 0 7px;
    text-align: center;
    line-height: 26px;
}
 
.ui-datepicker-calendar .ui-state-default {
    display: block;
    width: 26px;
    outline: none;
 
    text-decoration: none;
    color: #000;
 
    border: 1px solid transparent;
}


.ui-datepicker-calendar .ui-state-active {
    color: #e91e62;
    border: 1px solid #e91e62;
}
 
.ui-datepicker-other-month .ui-state-default { color: #ccc; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<div id="calendar">
</div>

If you look at the example above, you will see a gap which is not wanted and the content of the calendar is not really centered!

Could someone please advice on this issue?

Here is a fiddle as well if needed: https://jsfiddle.net/u7cocxdy/2/

any help would be appreciated.

1 Answer 1

6

You had a width:100% in there (.ui-datepicker-calendar th), which i deleted. This got rid of the gap. I then used margin: 0 auto to center the table.

$('#calendar').datepicker({
  inline: true,
  firstDay: 1,
  showOtherMonths: true,
  dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
});
.ui-datepicker,
.ui-datepicker table,
.ui-datepicker tr,
.ui-datepicker td,
.ui-datepicker th {
  margin: 0;
  padding: 0;
  border: none;
  border-spacing: 0;
}

.ui-datepicker {
  display: none;
  width: 100%;
  padding: 35px;
  cursor: default;
  text-transform: uppercase;
  font-family: Tahoma;
  font-size: 24px;
  background: #fff;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  border-radius: 4px;
  border: solid 1px #e91e62;
}

.ui-datepicker-header {
  position: relative;
  padding-bottom: 10px;
  border-bottom: 1px solid #d6d6d6;
}

.ui-datepicker-title {
  text-align: center;
}

.ui-datepicker-month {
  position: relative;
  padding-right: 15px;
  color: #e91e62;
}

.ui-datepicker-year {
  padding-left: 8px;
  color: #e91e62;
}

.ui-datepicker-month:before {
  display: block;
  position: absolute;
  top: 5px;
  right: 0;
  width: 5px;
  height: 5px;
  content: '';
  background: #a5cd4e;
  background: -moz-linear-gradient(top, #a5cd4e 0%, #6b8f1a 100%);
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #a5cd4e), color-stop(100%, #6b8f1a));
  background: -webkit-linear-gradient(top, #a5cd4e 0%, #6b8f1a 100%);
  background: -o-linear-gradient(top, #a5cd4e 0%, #6b8f1a 100%);
  background: -ms-linear-gradient(top, #a5cd4e 0%, #6b8f1a 100%);
  background: linear-gradient(top, #a5cd4e 0%, #6b8f1a 100%);
  -webkit-border-radius: 5px;
  -moz-border-radius: 5px;
  border-radius: 5px;
}

.ui-datepicker-prev,
.ui-datepicker-next {
  position: absolute;
  top: -2px;
  padding: 5px;
  cursor: pointer;
}

.ui-datepicker-prev {
  left: 0;
  padding-left: 0;
}

.ui-datepicker-next {
  right: 0;
  padding-right: 0;
}

.ui-datepicker-prev span,
.ui-datepicker-next span {
  display: block;
  width: 5px;
  height: 10px;
  text-indent: -9999px;
  background-image: url(../img/arrows.png);
}

.ui-datepicker-prev span {
  background-position: 0px 0px;
}

.ui-datepicker-next span {
  background-position: -5px 0px;
}

.ui-datepicker-prev-hover span {
  background-position: 0px -10px;
}

.ui-datepicker-next-hover span {
  background-position: -5px -10px;
}

.ui-datepicker-calendar th {
  padding-top: 15px;
  padding-bottom: 10px;
  text-align: center;
  font-weight: normal;
  color: #a8a8a8;
}

.ui-datepicker-calendar td {
  padding: 0 7px;
  text-align: center;
  line-height: 26px;
}

.ui-datepicker-calendar .ui-state-default {
  display: block;
  width: 26px;
  outline: none;
  text-decoration: none;
  color: #000;
  border: 1px solid transparent;
}

.ui-datepicker-calendar .ui-state-active {
  color: #e91e62;
  border: 1px solid #e91e62;
}

.ui-datepicker-other-month .ui-state-default {
  color: #ccc;
}

.ui-datepicker table {
  margin: 0 auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<div id="calendar">
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.