What is the best way to align a GIF and two rows of text within a container div?

Check out my JSFiddle below:

In this fiddle, there is an image sized 32 by 32 on the left side and two lines of text on the right. I need help aligning the center of the gif and the text with the middle of the enclosing frame.

I've tried adjusting the margins in various ways, but nothing seems to work for me. Could the issue be related to using "display: inline-block;" or are there other factors causing the problem?

<div class="server-info">
   <div style="z-index: 99; width: 32px; height: 32px;
      margin-top: 9px;
      margin-bottom: 9px;
      margin-right: 3px; display: inline-block;" id="load-icon"></div>
   <div style="display: inline-block; margin-top: 5px;
      margin-bottom: 5px; height: 40px;">XXX<br>YYY </div>
</div>

CSS

.server-info {
    border-radius: 0.4em 0.4em 0.4em 0.4em;
    border-top: 0 none;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.65);
    color: white;
    display: inline-block;
    margin-left: 0.5em;
    padding: 0 1em;
    vertical-align: top;
    font-size: 1em;
    margin-top: 1.6em;
    padding-left: 1em;
    padding-right: 1em;
    text-align: left;
    text-transform: none;
    background: none repeat scroll 0 0 #000000;
}

#load-icon
{
    background-image: url("http://www.smilecarwash.com/images/ajax-loader.gif");
    background-repeat: no-repeat;
}

Update: Apologies for the incorrect fiddle link - here's the correct one.

Answer №1

Does this fit the bill for what you need? Check out http://jsfiddle.net/BcPjz/4/

If you want to vertically align in the middle, make sure to include display:table-cell and vertical middle in the text div.

Alternatively, take a look at http://jsfiddle.net/GYkBC/1/

To position the text below the image, consider adding display:block to either the image div or the text 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

How can progress bars be animated using CSS or JavaScript?

I am currently working on creating a progress bar animation, but I'm unsure whether to use CSS or JS. Can anyone provide insight on how this effect was achieved here? I am hoping to replicate it. Does anyone know if this is the code they used? I&apos ...

Unable to open links specified in 'href' with Bootstrap 5 Navbar

After finishing developing my first page, I encountered an issue while working on the second page. I am using a bootstrap 5 navigation bar. The way I have set up the navbar is that once it reaches a breaking point, I disable the view to allow the full bar ...

What is the best way to align a div to the bottom of a table cell?

I need help with positioning a div inside a table cell that has 100% height. How can I align this div to the bottom of the cell? Furthermore, there are other divs within the same cell that I would like to position in the middle and at the top. ...

Is it possible to programmatically bind a click event to each individual word in a div element?

I'm attempting to link each word within an element without altering the markup inside the element using Javascript. ...

Adjust the color of the active link on the page using Angular and CSS

I have a project that I need to modify by adding a sub menu that appears on every page but is only coded once. My goal is to highlight the link for the current page, all within one HTML snippet. Although the list renders correctly, I'm struggling to g ...

Looking for assistance with arranging and managing several containers, buttons, and modals?

My goal is to create a grid of photos that, when hovered over, display a button that can be clicked to open a modal. I initially got one photo to work with this functionality, but as I added more photos and buttons, I encountered an issue where the first b ...

Designing a flexible layout that allows for both vertical and horizontal scrolling of content

I have successfully implemented a flexbox layout with fixed header, fixed footer, fixed menu, and scrolling content based on resources from various articles and Stack Overflow answers. However, I am facing difficulty in achieving horizontal scrolling for ...

How come my gifs appear tiny even though I've adjusted their width to 32% each?

I am trying to display three gifs in a row, each taking up one-third of the width of the page. However, when I preview the page, the gifs appear tiny. I have set the divs to 32% each and the gifs should fill 100% of their respective div. Here is the code s ...

How can I show tab objects in a Chrome extension?

I'm currently working on developing a new Google Chrome extension that focuses on tab organization. Despite the abundance of similar extensions already available, I am determined to create my own unique solution. One idea I have is to create a popup w ...

Leveraging HTML attributes in CMS source code

My website is built using Prestashop, and the content pages are created using: Prestashop > Preferences > CMS > Source-Code. For each CMS page, I utilize basic HTML in the source code. THE ISSUE I am attempting to add a widget to the site&apos ...

The script fails to work correctly when displaying the data

Last night, I finally cracked the code on how to transfer data from my form on the index page to the content page, and then display the results inside the content div back on the index page. However, a new challenge has emerged. My Javascript function (re ...

Clickable link unresponsive on parallax-enhanced webpage

Currently, I am utilizing Zurb foundation's Manifesto theme for creating a parallax scrolling landing page. The anchor tag is essential for the scrolling effect on this page, causing a conflict when regular anchor links are included. Here is the HTML ...

Display method JSONized

Looking for guidance on improving code efficiency and best practices. In my current project, I am working with a JSON Array structured like this: [ { "Date": "2014-07-16", "DiscPoint": "Description 1", "DisBy": "Person 1" ...

Content hidden by spoiler buttons may overlap with other spoiler buttons

I've created some spoilers that reveal information when clicked on. When I clicked on spoiler1, the content slid underneath the other spoilers strangely. Here's an example of what happened: http://gyazo.com/4571423534e2442dc960d119c668dfa8 Why ...

Step-by-step guide on positioning an image to show at the bottom of a div

I am trying to create a div that covers 100% of the screen height, with a table at the top and white space below it for an image. However, when I add the image, it ends up directly under the table instead of at the bottom of the DIV. I have searched on G ...

jQuery unable to target Bootstrap button

I've been experiencing some trouble trying to attach a listener to a button I made with Bootstrap. <button type="button" id="buttonone" class="btn btn-default btn-lg good"> <span class="glyphicon glyphicon-minus" aria-hidden="true">< ...

Chat lines in Chrome displaying double entries - troubleshooting needed

I developed a chat plugin for my website with a simple HTML structure: <div id="div_chat"> <ul id="ul_chat"> </ul> </div> <div id="div_inputchatline"> <input type="text" id="input_chatline" name="input_chatline" val ...

div containing various images of varying sizes

I am working with a layout that requires 4 images to be displayed together within a container. One image should be larger and positioned on the left, while the other three should be uniform in size and placed next to it on the right. Despite my efforts t ...

What are some creative ways to enhance closePath() in canvas styling?

Currently, I am faced with the challenge of styling the closePath() function on my canvas. Specifically, I would like to apply different stroke styles to each line segment. For now, let's focus on changing colors for each line. In the example below, y ...

Preserve the video's aspect ratio within a fixed height and width layout by utilizing CSS styling

I am currently in the process of developing a web application with a fixed height layout that does not utilize flexbox and is also limited by width constraints. My goal is to divide the screen in half both vertically and horizontally, around 50% for each ...