Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

less - Twitter's Bootstrap 3.x semantic mobile grid

After reading the new (unfinished) Bootstrap 3 docs I am wondering how to create semantic mobile grid.

In short. How to convert this:

<div class="row">
  <div class="col col-lg-6 col-sm-6">6</div>
  <div class="col col-lg-6 col-sm-6">6</div>
</div>

To this and preserve the small mobile grid:

<div class="wrapper">
  <div class="left">6</div>
  <div class="right">6</div>
</div>

Less

.wrapper {  .make-row(); }
.left    { .make-column(6); // this creates only large grid }
.right   { .make-column(6); }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

PART 1: Rant

I hate bootstrappers using html div classes as a presentation layer to their HTML!!! I applaud you looking to program your site correctly.

It reminds me of the 90s and early 2000s when we were all building websites with tables... are we going backwards people?

<div class="col-6 col-lg-6 col-sm-6">6</div>
<div class="col-6 col-lg-6 col-sm-6">6</div>

vs

<table><tr><td>6</td><td>6</td></tr></table>

I'm waiting for the day that Google imposes penalties on non-semantic markup.

PART 2: Solution

Anyhow, pulling this back to the question...

For bootstrap 3, as far as I am aware, you cannot use .make-column(6) etc... as per Bass Jobsen's answer because you need to specify the size of the window / screen. lg / md / sm / xs

Here is how I would do it...

main.less

@import 'bootstrap.less';

.wrapper {
    .container;
    .make-row();
    .clearfix();
}

.content-main { // Change these for each window size
  .make-lg-column(6);
  .make-md-column(6);
  .make-sm-column(6);
  .make-xs-column(6);
}
.content-sidebar { // change these for each window size
  .make-lg-column(6);
  .make-md-column(6);
  .make-sm-column(6);
  .make-xs-column(6);
}

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta charset="UTF-8">
    <style rel="stylesheet/less" src="less/main.less" />
    <script src="js/less-1.4.1.min.js" type="text/javascript"></script>

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>

    <script src="assets/js/html5shiv.js"></script>
    <script src="assets/js/respond.min.js"></script>
    <![endif]-->   
</head>
<body>
    <div class="wrapper">
        <div class="content-main">
            <div class="page-title">
                <!-- Page Title Stuff -->
            </div>
            <div class="page-content">
                <!-- Page Content Stuff -->
            </div>
        </div>
        <div class="content-sidebar"><!-- Page Footer Stuff --></div>
    </div>  
</body>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...