html - Bootstrap - Centering Content, Then Left Aligning (in relation to center) -


i have 2 divs must centered using bootstrap class text-center (for mobile reasons). after applying class, image , text center perfectly. however, i'd text centered , left-aligned precisely in line left side of image.

i've tried couple of things: first centering div , creating div around text, , left-aligning text text-left. however, text not stay centered , moves way left of column. i'd go left image. if set margin pixels text left-aligned image, not stay responsive , jumps on page when resized.

here example of content centered, , example of happens when center , left-align text: https://jsfiddle.net/wgr165tl/3/

i'd find out how text centered left-aligned far left of image. necessary keep text-center class. input appreciated.

<html> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mtjoasx8j1au+a5wdvnpi2lkffwweaa8hdddjzlplegxhjvme1fgjwpgmkzs7" crossorigin="anonymous">  <!-- optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-flw2n01lmqjakbkx3l/m9eahuwpsfenvv63j5ezn3uzzapt0u7eysxmjqv+0en5r" crossorigin="anonymous">  <!-- latest compiled , minified javascript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0msbjdehialfmubbqp6a4qrprq5ovfw37prr3j5elqxss1yvqotnepnhvp9aj7xs" crossorigin="anonymous"></script> </head> <body> <h1>example 1 (original)</h1> (want text align left edge of box) <div class="row text-center">   <div class="col-sm-1">   </div>    <div class="col-sm-3">     <div><img src="http://ep.yimg.com/ca/i/brandsonsale-store_2271_940646575"></div>     test test   </div>   <div class="col-sm-3">     <div><img src="http://ep.yimg.com/ca/i/brandsonsale-store_2271_940646575"></div>     test test   </div> </div>  <h1>example 2</h1> (tried centering , left-aligning text, goes far left. ideally line left edge of box) <div class="row text-center">   <div class="col-sm-1">   </div>  <div class="col-sm-3">     <div><img src="http://ep.yimg.com/ca/i/brandsonsale-store_2271_940646575"></div>     <div class="text-left">test test</div>   </div>   <div class="col-sm-3">     <div><img src="http://ep.yimg.com/ca/i/brandsonsale-store_2271_940646575"></div>     <div class="text-left">test test</div>   </div> </div> </body> </html> 

another solution set css-properties "test test" div: add css div:

text-align: left;  margin: auto;  width: 250px; 

a working example :)

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mtjoasx8j1au+a5wdvnpi2lkffwweaa8hdddjzlplegxhjvme1fgjwpgmkzs7" crossorigin="anonymous">    <!-- optional theme -->  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-flw2n01lmqjakbkx3l/m9eahuwpsfenvv63j5ezn3uzzapt0u7eysxmjqv+0en5r" crossorigin="anonymous">    <!-- latest compiled , minified javascript -->  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0msbjdehialfmubbqp6a4qrprq5ovfw37prr3j5elqxss1yvqotnepnhvp9aj7xs" crossorigin="anonymous"></script>    <h1>example 2</h1>  works??!!! yeay  <div class="row text-center">    <div class="col-sm-1">    </div>    <div class="col-sm-3">      <div><img src="http://ep.yimg.com/ca/i/brandsonsale-store_2271_940646575">     </div>      <div style="text-align: left; margin: auto; width: 250px;" >test test</div>   </div>    <div class="col-sm-3">        <div><img src="http://ep.yimg.com/ca/i/brandsonsale-store_2271_940646575"></div>        <div style="text-align: left; margin: auto; width: 250px;">test test</div>      </div>    </div>

hope helped :)


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -