Ways to center text next to a canvas element

Is there a way to ensure that my text elements are centered within the div and positioned next to my canvas element? Currently, the texts are placed beside the canvas but not in the middle. How can I achieve this desired effect?

In addition, please note that the canvas includes a chart plugin which has not been included in the code snippets provided below.

#user-count {
  height: 100px;
  width: 100px;
}

.card {
  background-color: #f4f4f4;
  border: none;
  padding:10px;
  display: inline-block;
}

.card-body {
  font-weight: 600;
  text-transform: uppercase;
  display: inline-block;
}
<div class="row">
<div class="col-md-6">
<div class="card">
  <canvas id="user-count"></canvas>
 <div class="card-body">
 <span>current blood donors</span>
 <span>as of 2017</span>
 </div>
</div>
</div>

Answer №1

Using Flexbox for a stylish layout :)

#user-count {
  height: 100px;
  width: 100px;
  background-color: red;
}

.card {
  background-color: #f4f4f4;
  border: none;
  padding: 10px;
  display: inline-block;
  display: flex;
  justify-content: center;
  align-items: center;
}

.card-body {
  font-weight: 600;
  text-transform: uppercase;
  display: inline-block;
}
<div class="row">
  <div class="col-md-6>
    <div class="card">
      <canvas id="user-count"></canvas>
      <div class="card-body">
        <span>current blood donors</span>
        <span>as of 2017</span>
      </div>
    </div>
  </div>

Answer №2

To enhance your styling, just insert this css snippet:

#user-count {
vertical-align: middle;
}

Answer №3

.panel {
    background-color: #f4f4f4;
    border: none;
    padding: 10px;
    display: flex;
    align-items: center;
}

Try utilizing display:flex instead of inline-block. Flex is comparable to inline-block, but not identical. Make sure to include align-items:center to vertically center all elements.

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

Adjustments in margins for printed HTML may vary from page to page in Internet Explorer versions 8 to 11

One challenge I'm facing is with a user-generated report page that is typically printed. There seems to be an unusual bug occurring specifically in Internet Explorer. The layout of the page consists of tables within various divs, all aligned perfectly ...

Securing PayPal's purchase forms for safe online transactions

Trying to assist someone with a donation issue, but discovered that the source code allows for editing of values in the Paypal button. When selecting 5 points worth $5, it's possible to manipulate the values in the source code of the Paypal form. How ...

Phonegap (cordova 1.6.0) integration with Facebook login is experiencing issues on Android

When using Cordova 1.6.0, I am encountering issues with alerts. The Cordova Facebook Connect plugin is failing on login! The Cordova Facebook Connect plugin is also failing on auth.status! Please assist me with resolving these problems. I have been fol ...

Turn off the second dropdown menu if the first one has not been chosen

I need to implement a feature where the second dropdown is disabled if the first dropdown is not selected. Is there a way to achieve this using JavaScript? The requirement is that if the user does not select an option from the first dropdown, the second dr ...

"Expanding Your Design: Manipulating Text Size and Padding with CSS

I am facing an issue with my buttons that are meant to look uniform. One button contains the word "Register" and the other contains "Details". Due to this, the button with the longer word appears bigger, which is not desired! My goal is to make both butt ...

When floating a heading 4 (h4) and two divs to the left, and a single div to the right,

When floating a h4 and 2 divs to the left, and another div to the right, how can I place a block inside the remaining space that perfectly fills it? The background color of this space should not spread outside. [h4][div][div][remaining space][div] Thank ...

Continue scrolling through both columns until you have reached the final element

I am looking to develop a feed page that mirrors the format of LinkedIn. I envision two columns placed side by side, with the first column containing numerous elements and the second column having fewer elements. As the user scrolls, both columns will scro ...

What methods are available for employing conditions in HTML attributes?

I need to implement a functionality in Angular where an image is loaded in a new window when the user clicks a button. The popup window will contain HTML content. Here's the Angular code snippet: <button class="btn btn-primary" type=&quo ...

Connect to content on the current page

I am facing an issue where the linked heading of a section on the same page is getting lost under the fixed navigation bar when scrolling down. This problem seems to only occur on desktop view as it works fine on mobile preview. Here is the code I am curre ...

Variations in CSS Stylesheets for Various Parts of the Body

Currently, I am in the process of creating a single page website. One issue that I have encountered is needing a Bootstrap "modal" class popup to appear when a button is clicked. However, the template I am utilizing was designed using Bootstrap Version 1, ...

Troubleshooting: When Angular Fade In Out Animation Won't Work

Looking to create a simple animation with the angular animation package The goal is to smoothly transition from opacity 0 to opacity 1 for a fade effect. I've had success with other properties like height and display, but struggling with opacity. H ...

Excessive spacing in the <td> elements - TABLE

I am encountering some problems with my table layout. The spacing between the field names and text boxes appears to be too large. Could there be mistakes I'm making that are causing this issue? How can I minimize the gaps? Please refer to the image b ...

What methods can be used to center a Google map on a specific location?

I am facing an issue with three map canvases on different divs. Despite setting the center to the same position in all three of them using JavaScript, the second and third maps do not seem to reflect that center. Does anyone have any insights on what cou ...

Aligning XML content in a `pre` tag using PHP code

Is there a way to format the XML syntax within a pre tag on a website so that it is properly aligned? While there are solutions available to highlight the syntax, such as the ones mentioned here, they do not address aligning the code block with preceding ...

What is the best approach for designing a UI in Angular to showcase a matrix of m by n dimensions, and how should the JSON format

click here for a sneak peek of the image Imagine a matrix with dimensions m by n, containing names on both the left and top sides. Remember, each column and row must be labeled accordingly. ...

Modify the contents of a textbox by editing the text as you type

Text within the text box follows this format: login -u username -p password When entering this text, I want to substitute 'password' with a series of '*'s equal in length. For example: 'login -u <a href="/cdn-cgi/l/email-prot ...

Having trouble choosing elements with angular.element within ng-repeat loop

In my HTML code, I am using an ngRepeat element: <ol id="animationFrame"> <li ng-repeat="animationImage in animationImages" ng-repeat-listener> <img ng-src="{{animationImage.src}}" id="{{animationImage.id}}"> </li> </ol& ...

What is the best way to transfer Django variables to HTML?

Looking to send data from the rs232 port and showcase it in a graph using javascript? Check out this resource: Seeking guidance on importing the views.py variable into my html file. views.py import io from django.http import HttpResponse from django.shor ...

h1 does not center align properly when there is insufficient text below

It seems that my h1 only aligns to the center of the screen when there is enough text underneath it. Otherwise, it doesn't align correctly or at all. How can I resolve this alignment issue? .content { margin-top: 60px; text-align: center; } bo ...

Crafting web design with CSS and HTML programming

I am currently working on implementing a sublevel drop-down menu. While I have successfully created the first level of the menu, the second level always displays prominently when hovering over the first drop-down menu. My goal is to only show the second le ...