Reputation: 564
I have this code:
<div class="col-sm-4">
<h4>{{$TagName->TagName}}</h4>
<img style="
width: 200px;
height: 200px;
";
class="img-responsive"; src="images/{{$TagName->TagName}}.jpg">
</div>
So my idea is to make(like this):
***text***
*imageeee*
Instead of:
text******
imageeee**
The * means the space that occupies, I dunno how to represent better the solution that I am seeking. I used the text-align:center to div, and 2 display:block to the html elements but it doesn't work either.(I'm using also bootstrap if it counts)
Some ideas how to solve this?
Upvotes: 0
Views: 69
Reputation:
The html
<div class="col-sm-4 text-center">
<h4>this is text</h4>
<img style="
width: 200px;
height: 200px;
";
class="img-responsive imageCentered"; src="https://upload.wikimedia.org/wikipedia/commons/1/1b/Square_200x200.png">
</div>
the css
.imageCentered{
margin:0 auto;
}
here is jsfiddle
Upvotes: 2
Reputation: 1686
here are two approaches to centering a column in Bootstrap 3:
Approach 1 (offsets):
The first approach uses Bootstrap's own offset classes so it requires no change in markup and no extra CSS. The key is to set an offset equal to half of the remaining size of the row. So for example, a column of size 2 would be centered by adding an offset of 5, that's (12-2)/2
.
In markup this would look like:
<div class="row">
<div class="col-md-2 col-md-offset-5"></div>
</div>
Now, there's an obvious drawback for this method, it only works for even column sizes, so only .col-X-2
, .col-X-4
, col-X-6
, col-X-8
and col-X-10
are supported.
Approach 2 (the old margin:auto)
You can center any column size by using the proven margin: 0 auto;
technique, you just need to take care of the floating that is added by Bootstrap's grid system. I recommend defining a custom CSS class like the following:
.col-centered{
float: none;
margin: 0 auto;
}
Now you can add it to any column size at any screen size and it will work seamlessly with Bootstrap's responsive layout:
<div class="row">
<div class="col-lg-1 col-centered"></div>
</div>
Note: With both techniques you could skip the .row element and have the column centered inside a .container but you would notice a minimal difference in the actual column size because of the padding in the container class.
Since v3.0.1 Bootstrap has a built-in class named center-block that uses margin: 0 auto but is missing float:none. You can add that to your CSS to make it work with the grid system.
Upvotes: 2