如何居中网格.js

How to center gridster.js?

本文关键字:js 网格 何居中      更新时间:2023-09-26

我一直在玩Gridster.js,但是对于我的生活,我似乎无法使网格居中,它总是保持合理,我已经尝试了又尝试,但也许我错过了一些东西。

我已经制作了一个具有我网格基础的jsfiddle,我希望有人可以解决它并帮助我将其居中,请:)

.gridster {
    background: #004756;
       margin: 0 auto;
    opacity: .8;
    -webkit-transition: opacity .6s;
    -moz-transition: opacity .6s;
    -o-transition: opacity .6s;
    -ms-transition: opacity .6s;
    transition: opacity .6s;
    text-align: center;
}
.gridster > * {
    margin: 0 auto;
    -webkit-transition: height .4s;
    -moz-transition: height .4s;
    -o-transition: height .4s;
    -ms-transition: height .4s;
    transition: height .4s;
}
.gridster .gs_w{
    z-index: 2;
    position: absolute;
        background: #FFF;
    cursor: pointer;
    -webkit-box-shadow: 0 0 5px rgba(0,0,0,0.3);
    box-shadow: 0 0 5px rgba(0,0,0,0.3);
}
.ready .gs_w:not(.preview-holder) {
    -webkit-transition: opacity .3s, left .3s, top .3s;
    -moz-transition: opacity .3s, left .3s, top .3s;
    -o-transition: opacity .3s, left .3s, top .3s;
    transition: opacity .3s, left .3s, top .3s;
}
.ready .gs_w:not(.preview-holder) {
    -webkit-transition: opacity .3s, left .3s, top .3s, width .3s, height .3s;
    -moz-transition: opacity .3s, left .3s, top .3s, width .3s, height .3s;
    -o-transition: opacity .3s, left .3s, top .3s, width .3s, height .3s;
    transition: opacity .3s, left .3s, top .3s, width .3s, height .3s;
}
.gridster .preview-holder {
    z-index: 1;
    position: absolute;
    background-color: #fff;
    border-color: #fff;
    opacity: 0.3;
}
.gridster .player-revert {
    z-index: 10!important;
    -webkit-transition: left .3s, top .3s!important;
    -moz-transition: left .3s, top .3s!important;
    -o-transition: left .3s, top .3s!important;
    transition:  left .3s, top .3s!important;
}
.gridster .dragging {
    z-index: 10!important;
    -webkit-transition: all 0s !important;
    -moz-transition: all 0s !important;
    -o-transition: all 0s !important;
    transition: all 0s !important;
}
.gridWrapper {
   width: 100%;
    overflow-x: scroll;
    overflow-y: hidden;
}
.gridAlignerWrapper {
    display: table;
    width: 100%;
    height: 100%;
}
.gridAligner {
    width: 100%;
    display: table-cell;
        }
body {
    background-color: #EEEEEE;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    font-size: x-small;
    color: #666666;
    text-align: center;
      vertical-align: middle;
}
ul, ol {
    list-style: none;
    margin:0 auto;
      text-align: center;
      vertical-align: middle;

}
h1 {
  margin-bottom: 12px;
  text-align: center;
  font-size: 30px;
  font-weight: 400; 
}
h3 {
  font-size: 25px;
  font-weight: 600;
  color: white; 
}
/* Uncomment this if you set helper : "clone" in draggable options */
/*.gridster .player {
  opacity:0;
}*/

https://jsfiddle.net/036qutd9/4/

谢谢

谢谢Paulie_D,我设法解决了它并让它居中:)

.gridster {
    width: 730px;
    background: #004756;
    margin-left:auto;
    margin-right:auto;
    opacity: .8;
    -webkit-transition: opacity .6s;
    -moz-transition: opacity .6s;
    -o-transition: opacity .6s;
    -ms-transition: opacity .6s;
    transition: opacity .6s;
    text-align: center;
}
.gridster > * {
    margin: 0 auto;
    -webkit-transition: height .4s;
    -moz-transition: height .4s;
    -o-transition: height .4s;
    -ms-transition: height .4s;
    transition: height .4s;
}