-1

I have use bootstrap in my application. i want to div center i try to use in div col-sm-offset but not div center .

I use Class In div Col-sm-7 col-sm-offset-2

My Code Here Below

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<style>
.clsborder{
  border:1px solid black;

}

</style>
<body>


  
<div class="container">
  <div class="row">
<div class="col-sm-7 col-sm-offset-2 clsborder">  <h3>Column 1</h3>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
      <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>

    
    
</div>
   </div>
</div>

</body>
</html>

Note: i want to Div Center Using offset in boostrap

Js Fiddle Demo here

Sumit patel
  • 3,807
  • 9
  • 34
  • 61

2 Answers2

1

The offset and the column must add up to 12 columns.

Use the formula:

12 - col-sm-# / 2

replace hashtag to A number.

If the number has decimals you can not offset it.

8 columns is alright with an offset of 2

If it doesn't work try centering using css

Mechetle
  • 58
  • 1
  • 8
  • thank for answer .. but your answer not worked .. i mast be use col-sm-7 then div center using offset – Sumit patel Sep 07 '16 at 11:11
  • @Sumitpatel Then it's just not possible with plain bootstrap. There is not col-sm-offset-2.5 in bootstrap. Maybe just add your own class with corresponding margins and / or paddings? – Lorenz Merdian Sep 07 '16 at 11:30
-1

I found my Answer guides ... Use in @media query and build custom Offset

@media (min-width: 768px)
{
.custom-offset {
    margin-left:21% !important;
}
}

Updated Code below

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<style>
.clsborder{
  border:1px solid black;

}
@media (min-width: 768px)
{
.custom-offset {
    margin-left:21% !important;
}
}


</style>
<body>


  
<div class="container">
  <div class="row">
<div class="col-sm-7 col-sm-offset-2 clsborder">  <h3>Column 1</h3>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
      <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>

    
    
</div>
   </div>
</div>

</body>
</html>

Js Fiddle Demo Here

Sumit patel
  • 3,807
  • 9
  • 34
  • 61