Design a responsive button that is vertically centered

As I work on developing a responsive website using bootstrap, my current challenge lies in creating buttons that are not aligned vertically. Here is the code snippet I am working with:

<div class="play col-xs-24 visible-xs-block">
   <div class="row movie_button">
      <div class="play_button inline_blocks col-xs-4">
         <img class="button_images movie_img_button" src="../images/btn.png">
      </div>
      <div class="col-xs-20 button_link ">
         <div id="play_title">PLAY THE MOVIE</div>
      </div>
   </div>
</div>

I attempted to use display: table-cell, but unfortunately, it did not produce the desired outcome.

Answer №1

Here are some possible solutions for vertically aligning center:

Method - 1 - VIEW DEMO

To achieve vertical center alignment, set the line's height to match that of the containing box element.

<div class="col-xs-20 button_link" style="height: 50px;">
    <div id="play_title" style="line-height: 50px; text-align:center;">PLAY THE MOVIE</div>
</div>

Method - 2 - VIEW DEMO

If you simulate table display behavior, vertical alignment can be achieved. Note that setting the height property is optional and for demonstration purposes only.

<div class="col-xs-20 button_link" style="height: 50px; display: table;">
    <div id="play_title" style="display: table-cell; vertical-align: middle; text-align:center;">PLAY THE MOVIE</div>
</div>

[EDITED]

TRY - Method 2

<div class="play col-xs-24 visible-xs-block">
   <div class="row movie_button">
      <div class="play_button inline_blocks col-xs-4">
         <img class="button_images movie_img_button" src="../images/btn.png">
      </div>
      <div class="col-xs-20 button_link" style="display: table;">
         <div id="play_title" style="display: table-cell; vertical-align: middle;">PLAY THE MOVIE</div>
      </div>
   </div>
</div>

OR TRY - Method 3

<div class="play col-xs-24 visible-xs-block">
   <div class="row movie_button" style="display: table;">
      <div class="play_button inline_blocks col-xs-4">
         <img class="button_images movie_img_button" src="../images/btn.png">
      </div>
      <div class="col-xs-20 button_link" style="display: table-cell; vertical-align: middle;">
         <div id="play_title">PLAY THE MOVIE</div>
      </div>
   </div>
</div>

OR TRY - Method 4

<div class="play col-xs-24 visible-xs-block">
   <div class="row movie_button" style="display: table;">
      <div class="play_button inline_blocks col-xs-4">
         <img class="button_images movie_img_button" src="../images/btn.png">
      </div>
      <div class="col-xs-20 button_link">
         <div id="play_title" style="display: table-cell; vertical-align: middle;">PLAY THE MOVIE</div>
      </div>
   </div>
</div>

For more on vertical alignment using display: table-cell, refer to these questions:

Question 1. Div table-cell vertical align not working

Question 2. Vertical-align middle with display table-cell not working on images


Method - 3

Try using a span instead of div for div#play_title, and apply CSS styles display:inline-block; and vertical-align:middle; to the containing box element.

<div class="play col-xs-24 visible-xs-block">
   <div class="row movie_button">
      <div class="play_button inline_blocks col-xs-4">
         <img class="button_images movie_img_button" src="../images/btn.png">
      </div>
      <div class="col-xs-20 button_link" style="display:inline-block;">
         <span id="play_title" style="display:inline-block; vertical-align:middle;">PLAY THE MOVIE</span>
      </div>
   </div>
</div>

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

What is the best way to change the heading text and color in React based on the time of day when calling a function?

I want to dynamically change the text and color of my h1 heading based on the time of day. I'm encountering an error with my current code: "Cannot set property 'innerText' of null". I've tried to figure out how to incorpor ...

How can we dynamically include ng-click or ng-dblclick in AngularJS based on conditions?

Below is an example of HTML code that I have: <div ng-style="{'height' : myHeight +'px'}" ng-dblclick="myCtrl.clickme()"></div> Is there a way to dynamically add either ng-click or ng-dblclick attributes to the DOM based o ...

What is the best way to turn the visible section of a PNG image with a transparent background into a clickable link?

I wanted to link a .png image with a transparent background on my website. After trying the following HTML: <a href="index.html"> <img border="0" src="smiley.png" alt="smiley" width="150" height="150"> </a> and CSS: a { text-d ...

"Optimizing websites for Retina displays through pixel ratios and media queries

Is there a way to make my max-width media queries effective for retina displays? I encountered an issue when testing my website on a macbook air with a pixel ratio of 2, causing my media queries to trigger at incorrect screen widths. For reference, here i ...

Website experiencing a 500 internal server error

I am struggling with implementing a maintenance page on my website using PHP and MySQL. I want to display a maintenance page instead of any other page when certain functions are being added. However, after uploading the code, I encountered a 500 error. The ...

Steps for making input stand out and display full content

One of the challenges I am facing is that some of my input fields are too small to display the entire text, and unfortunately, I cannot change their size. Is there a way to display the full content of the input when hovering without disrupting the layout? ...

Issues with CodeIgniter paths causing disruption to CSS background-image declaration

I've been working on a website with backend for two separate customers, each with their own unique URLs. I encountered an issue with Javascript links (ajax calls using url:) but managed to resolve it by using a global variable: var SiteURL='< ...

How can the backgroundImage css in react admin <Login /> be replaced using Material-UI?

I have been refering to the following resources: Learn about customizing login page background in React-Admin: Explore themes customization in Material-UI: https://material-ui.com/customization/components/ Instead of using a preset background, I want to ...

Tips for formatting dt and dd elements side by side on one line

How can I use CSS to style the following content in two columns: <dl> <dt>Mercury</dt> <dd>Mercury (0.4 AU from the Sun) is the closest planet to the Sun and the smallest planet.</dd> <dt>Venus</dt> ...

Ways to showcase the chosen choices from earlier stages in the intelligent guide

Currently, I am developing a user interface for my latest project and have incorporated the Smart Wizard from . In particular, I am utilizing the smartwizard-modal.html found in the examples section of smartwizard. This specific smart wizard modal consis ...

The design problem arises from using jQuery to dynamically prepare the table body at runtime

The table row and data are not appearing in the correct format. Here is a link to the problem on Fiddle: http://jsfiddle.net/otc056L9/ Below is the HTML code: <table border="1" style="width: 100%" class="eventtable"> <thead style="color: b ...

Iframe Interactivity

My goal is to create an interactive iframe that will match the current parent URL (). For example, if I have an iframe pointing to http://www.google.com and click a link within the iframe, it should update the parent URL to , and then load the clicked con ...

Utilize the Tab feature effectively in Impress.Js

Currently, I have disabled the Tab key in Impress.js so that it only moves to the next slide. However, when I try to focus on links and delete this code to let it behave normally, Impress.js crashes. Has anyone found a workaround for this issue? Appreciat ...

Struggling to make divs reach the bottom of the page? Check out my jsFiddle for a solution!

I'm facing difficulty in extending the left and right divs to the bottom of the page, with no additional space above or below. You can view my progress here: http://jsfiddle.net/qggFz/26/ Appreciate any help, Dale ...

The display of table headers varies in IE7

I am experiencing an issue with a table that has headers, each containing a span element with a background image serving as a separator between the column headers. While the display looks correct on most browsers, on IE7 the separator image (which is with ...

Troubleshooting Display Issue with Nested Div Selection in jQuery Tooltips

I have a long list of data consisting of 30-50 rows, each row needing its own distinct tooltip. Creating unique IDs for each row would require unnecessary JavaScript code. My goal is to utilize jQuery to retrieve the tooltip from the nested <DIV> wit ...

The Laravel return view function seems to be malfunctioning as it is displaying an error page instead

I am facing an issue where I am trying to display an existing view but instead of the show page, I keep getting a "404 not found" error. As a beginner in Laravel, I am still trying to grasp its concepts. Any insights into why I am encountering the error 40 ...

Utilize checkboxes to sort through MySQLi data

Currently, I have a page that is populated with various types of posts such as news and blog entries. My goal is to implement checkboxes so that users can select which type of post they want to view. For example, I would like the option to check 'new ...

Is there a way to retrieve and update the data of all the child elements within a table row dynamically?

I have a table with the following header information. <table id="example" class="display" cellspacing="0" width="100%"> <thead> <tr> <th> Date ...

The calculator is not simply adding two numbers; instead, it is combining them together to display something like "2+2=22"

<title>Calculator</title> <script type="text/javascript"> function Calculate(){ var myWorker = document.getElementById('myOperation'); var numberOne= document.getElementById('firstNumber').value; ...