Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap: How to center image in panel heading?

I have a class of 'panel-heading center', but the image in the panel isn't centering. How can I make that happen?

<%= link_to 'Back', things_path %>

<div class='row'>
  <div class='col-md-offset-2 col-md-8'>
    <div class='panel panel-default'>
    <div class='panel-heading center'>
      <%= image_tag @thing.image.url(:medium) %>
    </div>
    <div class='panel-body'>
    <p>
      <strong><%= @thing.title %></strong>
    </p>
    <p>
      <%= @thing.description %>
    </p>
    <p>
      <%= @thing.user.email %>
    </p>
    <% if @thing.user == current_user %>
      <%= link_to 'Edit', edit_thing_path(@thing) %> 
    <% end %>
    </div>
  </div>
</div>
like image 994
Dylan Richards Avatar asked Jan 21 '26 03:01

Dylan Richards


2 Answers

You can use the Bootstrap text-center class.

<div class="row">
  <div class="col-md-offset-2 col-md-8">
    <div class="panel panel-default">
      <div class="panel-heading text-center">
       ..
      </div>
      <div class="panel-body">
      ..
      </div>
     </div>
  </div>
</div>

Demo: http://bootply.com/97325

like image 67
Zim Avatar answered Jan 23 '26 17:01

Zim


Here's the answer i put in the comment :)

Try adding text-center class instead of center. An image is an inline element so will understand the text-align:center style.

like image 24
grimmus Avatar answered Jan 23 '26 16:01

grimmus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!