Column doesn't want to center within row in Rails

In the application's view, there is a fluid container and in the home view, there is another container with 4 rows. The first row has one column that is not aligning vertically to the middle of the row. I have attempted to use Bootstrap's align-middle class and also added 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 center an item on the screen horizontally, you can utilize the methods below:

text-align: center will horizontally align the text in the center.

margin: auto assists in centering elements perfectly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dynamic scrolling text for overflowing text display

Here's a scenario I'm facing: Let's say I have three div tags, each 100 pixels wide: <--- DIV WIDTH ---> Text in div 1 Text in div two, it overflows Text in div three <--- DIV WIDTH ---> Currently, I've set the following C ...

Apply bold formatting to the HTML text only, leaving the EJS variable untouched beside it

https://i.sstatic.net/X36eG.png Is there a way to format the text for "Guest signed up" and "Guests attended" in bold while keeping the values normal? Here is my current code: <li class="list-group-item">Guests signed up: <%= guestSignu ...

Unexpected and lengthy Styling rules generated from Gulp Sass compilation

Whenever my gulp sass task runs, it successfully creates the combined file. However, there are a few peculiar rules that stand out. These rules are incredibly long, about 1.5 million characters, and result in a 1.1mb file each time. This is clearly not acc ...

Calculating the calc()-expression in Fluid Typography Linear Transition

After exploring the technique demonstrated by Mike Riethmuller, which involves utilizing calc() to create a fluid font-size transition between a minimum and maximum value, I found the outcome obtained from calc() in the browser somewhat perplexing (and not ...

Tips for incorporating API-provided CSS values into AngularJS expressions for stylish card customization

I am in the process of creating unique Pokemon cards that pull data from an API. My question is, how can I apply specific CSS styling to each card directly from the API, similar to how I have utilized AngularJS to render the information? So far, I have su ...

Margin not being applied to last element in parent - any ideas why?

Why does the margin of the last element, whether it is a <p> or <h1>, not have any impact? It should be pushing the background of the parent container downwards. .container { background: grey; } h1 { margin-bottom: 3em } p { margin- ...

A secondary operation is triggered in the simulated keyboard when the enter or space key is pressed, even when it is not warranted

In my HTML, I have created a simulated keyboard with buttons that correspond to characters. When you click on these buttons, the character is added to a text element on the screen. Additionally, you can use your physical keyboard to input characters in the ...

Dynamic styling with jQuery input focus animation

Whenever I interact with the input field, I want my border colors to animate in and fade out smoothly. But I'm facing some challenges. Here is how I've set it up: HTML <input type="text" id="search-input" placeholder=&quo ...

Tips on positioning two images in separate locations within a table cell?

I have a cell containing two images. I want one to be centered in the middle of the cell and the other in the top right corner, overlaying the centered image. My goal is to achieve this layout https://jsfiddle.net/5bL56a34/ without specifying the left m ...

Creating a Form Input Field Based on a Selection List

I'm in the process of developing a small app to boost my productivity at work. Currently, I have some html/js code that includes a ul with a search filter. When I select an option, it opens a new tab with relevant text. Ideally, I want the outcome to ...

Anomalous reference in an external style sheet

Okay, so I'm admittedly quite new to programming, but I thought I had CSS referencing all figured out...turns out, not quite. I've tried including stylesheets both internally and externally, moving them around in different folders, you name it. B ...

Tips for preventing errors in formatting?

I created a field using rectangles as divs. However, when I add content to the rectangle divs, the formatting gets messed up. Can anyone help me fix this issue? Here's the link <div class='line' id='line1'> <div class=& ...

Enhance your website design with Bootstrap's unique styling for jumbotron elements

I am currently working on developing a mobile website for calendar events and I need some help. Here is the basic version of the site that I have created so far: The issue I am facing is that the purple backgrounded areas only cover the text, rather than ...

Symbol placed atop text within a navigation bar

I am in the process of creating a custom menu for my website. I want to include an icon with text underneath, but when I add the text it shifts to the right and messes up the alignment. Menu with Icon Only Menu with Text (causes alignment issues) @impo ...

The reveal/conceal feature will not reveal all elements at the outset

I've been working on implementing a show/hide elements filter. However, I'm facing an issue where all elements that are supposed to display initially are hidden instead. Additionally, the 'active' class is not being properly removed or ...

Is it possible to dynamically add attributes to XHTML tags using Javascript? For instance, adding a title attribute to an anchor tag like <a title="text">

Is it possible to modify XHTML source code through JavaScript? Can attributes be added to any XHTML tag dynamically, such as adding a title attribute to an anchor tag (<a title="text">)? ...

What is the best way to close the gap between the bottom border and text elements?

Currently in the process of developing my website and encountering an issue. Check out the webpage here. I aim to apply 3px underlines solely to the links, like so: The line height for the text stands at 56pt, causing the border-bottom to be significantl ...

Tips for preventing vw fonts from constantly increasing in size

In my current project, I am working on a responsive website with an html max-width of 1000px. I have set all the fonts using vw units, but I'm facing an issue when the browser is expanded beyond 1000px. Is there a solution to prevent the fonts from in ...

Error: Cannot import CSS because the window object is not defined

Encountered an error while trying to import CSS in a React JS application: This application functions as a dashboard, with Node.js on the server side and React JS on the client side. webpack.base.js module.exports = { // Configuring Babel for all fi ...

Is there a way to utilize useEffect for detecting changes in screen width?

One challenge I am facing while using React is dealing with a canvas that varies in size and shape based on the screen dimensions. To draw something on this canvas, I find myself having to set specific dimensions for each different screen size. const [scre ...