Bootstrap-3 - img responsive not working

I created a small site for fun, getting to know the bootstrap.

The problem is that the logo image does not respond, regardless of what I'm trying to do.

The code seems pretty simple. I'm sure there are simply not enough details:

<div id="masthead"> <div class="container"> <div class="row"> <div class="col-md-7 header-logo"> <div class="header-logo" style="color: white;"> <img src="/img/gros_buck_175.png" class="img-responsive" align="left" style="padding-right: 1.5em;padding-top: 0px; max-width: 184px;"> <br> TEL: 450 955-3422 <br> 182 CHEMIN D'ADAMSVILLE <br> J2L 2Y6, BROMONT<br> laboucheriedugrosbuck@gmail.com <br clear="all"> </div> </div> <div class="col-md-5"> <div class="well well-lg"> <div class="row"> <div class="col-sm-12"> <img src="/img/sceau_140.png" class="img-responsive" align="left" style="padding-right: 1.2em;"> <h3 style="margin-top:0px; margin-bottom: 1em;">PROMO</h3> FAITES VOTRE PLAN DE VIANDE:<br> ACHETEZ POUR PLUS DE 100$ DE PRODUITS À L'UNITÉ ET RECEVEZ 10% EN SAUCISSES. </div> </div> </div> </div> </div> </div><!--/container--> </div><!--/masthead--> 

(Here is a fiddle reproducing the problem) - https://jsfiddle.net/JoshC/2XgDW/2/

+8
css twitter-bootstrap
source share
2 answers

First remove the max-width: 184px attribute max-width: 184px from the image tag

 <img src="/img/gros_buck_175.png" class="img-responsive" align="left" style="padding-right: 1.5em;padding-top: 0px;"> 

Although it would be better to avoid using inline style:

 <img src="/img/gros_buck_175.png" class="img-responsive" id="myLogo" align="left"> 
 #myLogo { padding-right: 1.5em; padding-top: 0px; } 

If there is a possibility that one of the elements of the ancestral style may interfere, you can reset to do it like this:

 #myLogo { all: initial!important; width: 100%!important; height: auto!important; } 

If you are still experiencing a problem, the next step is to use JavaScript

 Object.assign(document.getElementById('myLogo').style, { all: 'initial', width: '100%', height: 'auto' }); 

This code must be included after the element in the document, otherwise it will not be able to find the specified element, since it does not yet exist.


Now that you have added the example to your question, you can make the image look natural by replacing the following CSS:

 img { display:table-cell; width:100%; height:auto; } 

Using this CSS:

 img { display:inline-block; } 

( Demo )


I believe your use of display: table interfering with your design. Below are two ways to achieve the same layout without hacks.

CSS3 Method

All relevant modern browsers support this method, so if you do not care about backward compatibility with older browsers, you can use this method.

( Demo )

 <div class="inline-wrap"> <img src="http://placehold.it/150x150" /> <div class="text-wrap">Lorem Ipsum is simply dummy text Lorem Ipsum is simply dummy text Lorem Ipsum is simply dummy text</div> </div> 
 *,*:before,*:after { box-sizing: border-box; } .inline-wrap { white-space: nowrap; font-size: 0; height: 150px; } .inline-wrap img { width: 150px; } .inline-wrap .text-wrap { white-space: initial; font-size: initial; display: inline-block; height: 100%; width: 65%; /* Fallback */ width: calc(100% - 150px); } 

Table method

For backward compatibility, you can use this method.

( Demo )

 <table> <tr> <td class="img-wrap"> <img src="http://placehold.it/150x150" /> </td> <td class="text-wrap">Lorem Ipsum is simply dummy text Lorem Ipsum is simply dummy text Lorem Ipsum is simply dummy text</td> </tr> </table> 
 *, *:before, *:after { box-sizing: border-box; } table, tr, td { border: 0; padding: 0; margin: 0; border-collapse: collapse; } table { width:100%; } table .img-wrap { font-size: 0; } table .text-wrap { width: 100%; height: 100%; } 
+9
source share

Try changing the max-width to width: 100% , which should say that it occupies 100% of the width of the containers, but as the width of the containers changes, so does the size of the images, while 100% coverage is always supported.
This SHOULD work if it doesn't let me know, and I'll crack it a bit. I'm just on my phone, so I don’t want a sandbox with a touch keyboard anywhere. If this does not work, I will rip it to my computer tomorrow: D!

Ps. Is there a reason why you declare a .header-logo class in one div, and then again in the next div give it the same class. I understand that this was a different div block, but this is essentially the header logo inside the header logo.

0
source share

All Articles