Column won't align to middle of row in Rails

75
June 15, 2018, at 6:30 PM

So I have a fluid container in the application's view, and another container in the home view with 4 rows. The first row has only one column that won't vertically align to middle of row. I've tried adding an align-middle Boostrap class, as well as adding a custom class({height:50vh}).

<div class="container-fluid preview-height no-padding">  
      <% @posts.each do |p| %>     
        <div class="container-fluid d-block">  
 
 
          <div class="row disp-margin text-white preview-height bg-cover bg-img"             style="background-image: url('<%= p.image.length > 0 ? p.image :               default_background_url %>');">  
 
              <div class="col-lg-12 text-center vcenter"> 
                      <p class="h1"><a><%= p.title %></a></p><%# Post's title...%> 
                      <a class="bordera m-padding"><%= p.style %></a> 
                      <a class="bordera m-padding"><%= p.genre %></a> 
                      <a class="bordera m-padding"><%= p.platform %></a>    
                      <h3><%= p.likes.length %> likes</h3>  
                      <%= p.body %>  
              </div> 
 
          </div> 
 
 
          <div class="row b-padding bg-white text-center">  
              <h3 class="col-lg-12 text-center">by <%= p.user.name %> 
          </div> 
 
 
          <div class="row no-padding bg-white h1">   
              <h3 class="col-lg-12 text-center">  
                <%= link_to "Like", post_likes_path(p), method: :post %>  
              </h3>  
              <h4 class="col-lg-12 text-center"> 
                <%=link_to("Back to the top","#", class:'text-dark')%>  
              </h4> 
          </div>  
 
 
        </div> 
      <% end %>  
</div> 

Answer 1

To align something to the center of the screen (horizontally) you can use the following:

text-align: center Will align text to be centered horizontally.

margin: auto will align elements to be centered

READ ALSO
Cannot figure out website css

Cannot figure out website css

jobcull, I cannot figure out how to stretch the grey color at the bottom to fill the whole screen and also get rid of the white space near the bottom of the blockEverything that I've tried breaks everything else

77
Code reverts back to original theme after a while

Code reverts back to original theme after a while

Apologies for such an amateur question, I can't find the answer anywhere else after searching

92
Table thead background color not showing up when printing

Table thead background color not showing up when printing

I am making a table that has sticky header and left columnIt has thead, tbody and tfoot

90
Targeting JavaScript bound links with CSS selectors similarly with A/HREF elements

Targeting JavaScript bound links with CSS selectors similarly with A/HREF elements

I sometimes use <a href="javascript:" onclick="someFunction()">link</a> to target JS bound link with a:link CSS selectors, since targeting doesn't work on an element without the href attributeHowever, this can be dangerous in front-end frameworks,...

96