Balancing icons and text to align perfectly in a straight line

https://jsfiddle.net/magnix2k/z1sx03by/1/

My goal is to make sure that the icons in buttons, along with their labels and accompanying text, are perfectly aligned. Despite trying various CSS codes like 'top: 0;', 'padding: 0;', 'display: block;', 'display: inline-block;' and 'vertical-align: middle;', I'm unable to achieve the desired alignment. What am I overlooking?

HTML

<div class="service-wrapper">
  <div class="services">
    <div class="button1"><img src="http://www.evergreenwealthformula.com/new/wp-content/uploads/2017/02/Tech-Support-Icon-3.png" class="iconBtn1">TECHNICAL SUPPORT</div>
    <div class="text1"><p>For technical issues with placing or receiving videophone calls.</p></div>
  </div>
  <div class="services">
    <div class="button2"><img src="http://www.evergreenwealthformula.com/new/wp-content/uploads/2017/02/Tech-Support-Icon-3.png" class="iconBtn2">CUSTOMER SERVICES</div>
    <div class="text2"><p>For questions about applying for producing, porting, moving, updating your address, or other general questions.</p></div>
  </div>
</div>

CSS

@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro');

html, body, #container {
font-size: 18px;
margin: 0;
padding: 0;
height: 100%;
font-family: 'Source Sans Pro', sans-serif;
}

p {
line-height: 18px;
font-size: 14px;
}

div {
padding: 0;
margin: 0;
}

.service-wrapper {
width: 100%;
background-color: #000000;
}

.services {
width: 50%;
display: flex;
margin: 0 auto;
border: solid #ff0000 1px;
}

.text1 {
flex: 1 1 auto;
text-align: left;
color: #ffffff;
}

.button1 {
flex: 0 0 auto;
background-color: #ffffff;
height: 40px;
width: 200px;
margin: 10px;
padding: 5px;
border-radius: 5px;
background: #ffbb11;
text-align: center;
color: #000000;
font-weight: bold;
}

.text2 {
flex: 1 1 auto;
text-align: left;
color: #ffffff;
}

.button2 {
flex: 0 0 auto;
background-color: #ffffff;
height: 40px;
width: 200px;
margin: 10px;
padding: 5px;
border-radius: 5px;
background: #ffbb11;
text-align: center;
color: #000000;
font-weight: bold;
}

.iconBtn1{
max-height: 60%;
max-width: 60%;
}

.iconBtn2{
max-height: 60%;
max-width: 60%;
}

Answer №1

While there may be other solutions out there, this one gets the job done:

.btn1 img,
.btn2 img {
          transform: translateY(10px);
      -ms-transform: translateY(10px);
  -webkit-transform: translateY(10px);
}

If you want to see how it works with your code, check out this link: https://jsfiddle.net/a7ktb9jf/2/

Answer №2

When working with .button1 and .button2, make sure to remove the text-align: center property and instead add display: flex, justify-content: center, and align-items: center. https://jsfiddle.net/z1sx03by/4/ To avoid code duplication, consider creating a common class for both buttons and applying it universally. This will streamline your styling process and ensure consistency across all elements. Give it a try and see how it enhances your workflow! :)

Answer №3

Almost there with the display:flex css property. Just a small adjustment needed. Also, no need for separate class names if they share the same style.

@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro');

    html, body, #container {
    font-size: 18px;
    margin: 0;
padding: 0;
height: 100%;
font-family: 'Source Sans Pro', sans-serif;
    }

    p {
line-height: 18px;
font-size: 14px;
    }

    div {
    padding: 0;
    margin: 0;
    }

    .service-wrapper {
    width: 100%;
    background-color: #000000;
    }

    .services {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center; 
    margin: 0 auto;
    border: solid #ff0000 1px;
    }

    .text {
    flex: 1 1 auto;
    text-align: left;
    color: #ffffff;
    }

    .button {
    flex: 0 0 auto;
    background-color: #ffffff;
    height: 40px;
    width: 200px;
    margin: 10px;
    padding: 5px 10px;
    border-radius: 5px;
    background: #ffbb11;
    text-align: center;
    color: #000000;
  font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center; 
    }
<div class="service-wrapper">
  <div class="services">
    <div class="button"><img src="http://via.placeholder.com/20x20" class="iconBtn">
<span>TECHNICAL SUPPORT</span></div>
    <div class="text"><p>For technical issues with placing or receiving videophone calls.</p></div>
  </div>
  <div class="services">
    <div class="button"><img src="http://via.placeholder.com/20x20" class="iconBtn"><span>CUSTOMER SERVICES</span></div>
    <div class="text"><p>For questions about applying for producing, porting, moving, updating your address, or other general questions.</p></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 steps can be taken to repair the footer area within this CSS document?

As a beginner ASP.NET developer, I am encountering CSS for the first time. The CSS file I have is fairly simple, but I am facing difficulties with the footer section. The current appearance of the footer is as follows: I am looking to make the following m ...

A helpful tip for dynamically adjusting the canvas size is to utilize its height and width attributes to resize it whenever it undergoes a change

I am encountering an issue with the canvas element in my code. The canvas is supposed to update whenever its containing div is resized. window.addEventListener('resize',function() { let mapwidth = $('.canvas').attr("width") l ...

Ways to extract a specific line of text from HTML code

Can someone help me extract a specific line from an HTML code using Python? For instance, in this website: The snippet of code is as follows: var episodes = [[8,54514],[7,54485],[6,54456],[5,54430],[4,54400],[3,54367],[2,54327],[1,54271]]; I am lookin ...

Personalizing Material-UI's select component: A step-by-step guide

Desired Outcome: https://i.stack.imgur.com/khNHn.png https://i.stack.imgur.com/dQzVz.png Progress So Far: https://i.stack.imgur.com/CUixn.png Struggling to Position SVG Icon Next to Text: https://i.stack.imgur.com/4GFtA.png Issue with Black Line Whe ...

Retrieve properly formatted text from the editor.document using the VSCode API

I have been working on creating a personalized VSCode extension that can export the current selected file contents as a PDF. Although PrintCode exists, it does not fit my specific needs. The snippet of code I am currently using is: const editor = vscode.w ...

Manipulating HTML content with Javascript Array

Is there a way to retain Javascript context from an array? Any suggestions for improving this code? SAMPLE: <html> <script type="text/javascript"> var rand = Math.floor(Math.random() * 6) + 1; var i = Math.floor(Math.random() * 6) + 1; var ...

Exploring the animation potential of HTML5 canvas and Javascript through utilizing putImageData with animated gifs

I am interested in modifying the image data of each frame in an animated gif while it is playing in a web browser, using HTML5 canvas and Javascript. For instance, I would like to convert every frame to grayscale dynamically as the gif plays. Is this achie ...

Spinning around the Y-axis only causes a one-sided flip

Is there a method to ascertain the direction of rotation for the CSS property transform: rotateY? I have been attempting to spin this h1 element from one side to the other, but regardless of using a positive or negative sign, it always rotates in the same ...

Tips for preventing bootstrap from resizing the top card image too large while maintaining consistency across various image files

Hello, I'm facing an issue with bootstrap image sizing. When I insert images with smaller dimensions into a card, they are being blown up to fit the card which results in them becoming blurry. Here is the HTML code that's causing the problem: { ...

Implementing Bootstrap 4 Beta's server-side validation post error resolution

I'm currently working with Bootstrap 4.0.0.beta and am facing an issue with server-side validation. When adding the .is-invalid class to inputs that were invalid upon submission, even after the user corrects the error, the class remains, potentially c ...

Updating the correct list item in an unordered list on a Bootstrap modal pop-up submission

I am dealing with an unordered list of messages where each message within a list item is clickable. <ul id="home-message-list" class="messages"> <li> <a href="#"> <span class="linkClick" name="message">< ...

The active class consistently adds new menu options without removing the previous ones

I am facing an issue with my menu where the active class does not get added to the new menu item when clicked, despite being removed from the previous item. Below is the code snippet: <div class="row text-center" id="side-menu"> <nav> ...

Inconsistent Functionality of Bootstrap Popover

I am experiencing an issue with the bootstrap Popover feature. It seems to work inconsistently - sometimes it works and other times it doesn't. I am using it to create a popover that displays a user's information when a visitor hovers over the us ...

Utilize JQuery to implement fading effects for clicked elements in a webpage

I've been using a rollover JavaScript plugin to create smooth transitional effects when users hover over clickable page elements. Everything was going well until I decided to switch to making ajax calls instead of page loads for dynamic content. The p ...

Arrange a div element among the descendants of a neighboring div

I am working with a div that is generated by a library. This div contains 2 child divs with varying heights, which can change based on the API response and the width of the browser window. My goal is to display another div (my-div) between top-bar and bot ...

What are the steps to create a responsive form using CSS?

I have a screenshot below that needs to be recreated using HTML/CSS. This design should be consistent in both desktop and mobile views. https://i.stack.imgur.com/cnfHt.png Currently, I have managed to replicate this in a JSFiddle which looks good on desk ...

Is there a way to make a picture fill the entire background?

Is there a way to make pictures expand across an entire page with different resolutions? I'm trying to achieve this effect but unsure how. Take a look at my current example: . ...

Sort posts alphabetically by their first letter using jQuery

Currently, I am dealing with a collection of products sourced from WooCommerce and displayed as custom posts through the Elementor page builder at this link: My attempt to incorporate an alphabetical filter using a plugin has not been successful, most lik ...

Troubleshooting: Navbar dropdown menu in AngularJS gets hidden within UI layout

After spending some time trying to understand why the NavBar drop-down is getting overlapped inside the ui-layout, I realize that I must be overlooking some basic steps. This issue seems so simple, yet it is eluding me. To see the details of the problem, ...

The loading time for the Docker index HTML file page is unacceptably slow

Sample Dockerfile: FROM ubuntu:22.04 RUN apt-get update RUN apt-get install -y nginx COPY -r dist/ /var/www/html/ CMD service nginx start && tail -F /var/log/nginx/error.log After that, run the following commands: docker build -t website . docker ...