简体   繁体   中英

How to center left floated items for mobile phone view in CSS?

I have a webpage that looks fine on a desktop PC but not as good on a mobile phone as the items on the grid float to the left but I'd like them to appear centered. Is there a simple "@media only screen" code I could add or anything I could change to my below CSS so that it centers on a mobile? Also, the div class="col-xs-12 col-sm-6 col-lg-6" and here is an Image Example: Desktop vs Mobile View

You can also check out a live example at - http://www.helpme.ae/

.GRID
width:170px;
height:235px;
background:#f4f4f4;
border:1px solid #dedede;
padding:4px;
border-radius:4px;
text-align: center;
float:left;
margin:9px;
margin-bottom:20px;
position:relative

.XOX
display: block;
margin-bottom: 3px;
margin-top: 0px; 
overflow:hidden

.widget-container
{
text-align:left
}

.widget-container ul { padding:0; margin:0; list-style-type:none }
.widget-container ul li { margin-bottom:6px; }

Use this CSS:

@media (max-width: 991px) {
  .latest-posted-tasks-big {
    text-align: center;
  }
  .latest-posted-tasks-big > * {
    text-align: initial;
  }
  .latest-posted-tasks-big > .grid_task {
    display: inline-block;
    float: none;
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM