Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Centering an <img> tag within a 100% Div

Featured Replies

Hi

 

Ok so simply put I have a 100% width Div with <img..> inside. The image width is 698px, though that shouldn't make any difference. This is what I've got.

 

<div class="col-md-12" >

<a class="logo" href="#"><img src="images/old_elm.png" alt="Special Occasion Cars. Chauffeur driven cars london." style="display: block; margin:0 auto;"></a>

</div>

 

What I need is that the <img...> sits in the center horizontally. Of course the code just defaults the image to the left.

 

I know I'm going mad, I've done this before, I just can't get it to do what I what it to do. arrggg.

 

Anyone reminder me hows this done done please? :)

Put text-align: center on whatever element is wrapping the image.

An image, by default acts exactly the same as an inline-block element, which responds to the text-align property on it's parent.

  • Author

<div class="col-md-12" style="text-align:center;">
<a class="logo" href="#"><img src="images/old_elm.png" alt="Special Occasion Cars. Chauffeur driven cars london."></a>
</div>

 

No change I'm afraid.

It's hard to see just looking at your HTML there.

 

what are the display properties of the anchor that is wrapping the image? if that has display block and width:100% then your text-align center should go on that

 

Could you put up a live version or put it on Codepen so we can give to a better answer?

Edited by rbrtsmith

  • Author

yes bootstrap.

 

Worked it out the div was inside another div that was floating to the left. Much appreciated.

Edited by Acknowledged74

  • 2 weeks later...

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.