Traditional alignment challenges arise when trying to position two elements in a row using HTML and CSS

Greetings to the community of stack overflow! I am facing a mundane issue with two elements (refer to code snippet below) that requires my attention. Any help or advice would be greatly appreciated.

I am aiming for the final output to resemble this:

Within the grey circular background, I have positioned social media links (.social__icon > img) relatively. Unfortunately, I am unable to load SVG files from the assets here. You can refer to the screenshot showcasing my attempts:

Regrettably, due to insufficient reputation, embedding screenshots is not an option for me at the moment. I hope there is another way for you to view it.

If not, envision it looking something like this:

Social Media Link Image margin-left:12px Social Media Text-Name also Relative Link Image with Hover and Animation Effects

They both should function as one in a row

For example,

I'm Facebook SVG icon in the grey ellipse 12px left Facebook

This is the desired outcome with:

.social__icon {
  display: inline-flex; /* Changed */
  align-items: center; /* Added */

View image description here

Active mode: View image description here

ol,
ul,
li,
menu {
  list-style: none;
}

a {
  text-decoration: none;
}

.social__list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.social__icon {
  display: inline-block;
  text-align: center;
  width: 26px;
  height: 26px;
  border-radius: 100%;
  background: rgba(196, 196, 196, 0.5);
  -webkit-transition: all 0.25s linear;
  -moz-transition: all 0.25s linear;
  -ms-transition: all 0.25s linear;
  -o-transition: all 0.25s linear;
  transition: all 0.25s linear;
}

.social__icon img {
  vertical-align: middle;
}

.social__icon span {}

.social__icon:active {
  background: #4B9200;
  color: #4B9200;
}

.social__icon:hover {
  animation: shake 500ms ease-in-out forwards;
}

@keyframes shake {
  0% {
    transform: rotate(2deg);
  }
  50% {
    transform: rotate(-3deg);
  }
  70% {
    transform: rotate(3deg);
  }
  100% {
    transform: rotate(0deg);
  }
}
<div class="social">
  <ul class="social__list">
    <li>
      <a class="social__icon" href="https://en-gb.facebook.com" target="_blank" rel="noopener">
        <img src="../../assets/icons/social/fb.svg" alt="">
        <span>Facebook</span>
      </a>

    </li>
    <li>
      <a class="social__icon" href="https://twitter.com" target="_blank" rel="noopener">
        <img src="../../assets/icons/social/twtr.svg" alt="">
        <span>Twitter</span>
      </a>
    </li>
    <li>
      <a class="social__icon" href="https://www.instagram.com" target="_blank" rel="noopener">
        <img src="../../assets/icons/social/inst.svg" alt="">
        <span>Instagram</span>
      </a>
    </li>
    <li>
      <a class="social__icon" href="https://www.youtube.com" target="_blank" rel="noopener">
        <img src="../../assets/icons/social/youtube.svg" alt="">
        <span>Youtube</span>
      </a>
    </li>
  </ul>
</div>

Answer №1

Issues with the styling in the provided image

ol,
ul,
li,
menu {
  list-style: none;
}

a {
  text-decoration: none;
}

.social__list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.social__icon {
  display: inline-block;
  text-align: center;
  -webkit-transition: all 0.25s linear;
  -moz-transition: all 0.25s linear;
  -ms-transition: all 0.25s linear;
  -o-transition: all 0.25s linear;
  transition: all 0.25s linear;
}

.social__icon img {
  width: 26px;
  height: 26px;
  vertical-align: middle;
  border-radius: 100%;
  background: rgba(196, 196, 196, 0.5);
}

.social__icon:active {
  background: #4b9200;
  color: #4b9200;
}

.social__icon:hover {
  animation: shake 500ms ease-in-out forwards;
}

@keyframes shake {
  0% {
    transform: rotate(2deg);
  }
  50% {
    transform: rotate(-3deg);
  }
  70% {
    transform: rotate(3deg);
  }
  100% {
    transform: rotate(0deg);
  }
}
<div class="social">
  <ul class="social__list">
    <li>
      <a
        class="social__icon"
        href="https://en-gb.facebook.com"
        target="_blank"
        rel="noopener"
      >
        <img
          src="https://cdn3.iconfinder.com/data/icons/free-social-icons/67/facebook_circle_color-512.png"
          alt=""
        />
        <span>Facebook</span>
      </a>
    </li>
    <li>
      <a
        class="social__icon"
        href="https://twitter.com"
        target="_blank"
        rel="noopener"
      >
        <img
          src="https://cdn4.iconfinder.com/data/icons/social-media-icons-the-circle-set/48/twitter_circle-512.png"
          alt=""
        />
        <span>Twitter</span>
      </a>
    </li>
    <li>
      <a
        class="social__icon"
        href="https://www.instagram.com"
        target="_blank"
        rel="noopener"
      >
        <img
          src="https://cdn2.iconfinder.com/data/icons/social-media-applications/64/social_media_applications_3-instagram-512.png"
          alt=""
        />
        <span>Instagram</span>
      </a>
    </li>
    <li>
      <a
        class="social__icon"
        href="https://www.youtube.com"
        target="_blank"
        rel="noopener"
      >
        <img
          src="https://cdn4.iconfinder.com/data/icons/logos-and-brands/512/395_Youtube_logo-512.png"
          alt=""
        />
        <span>Youtube</span>
      </a>
    </li>
  </ul>
</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

ensure that html tags display properly when retrieved from json in an angular directive template

Trying to embed ruby tags in a directive template but struggling with escaping them. Despite reading about $sce and filters, the confusion deepens as browser tabs multiply. The directive code is as follows: angular.module("ngFlashCard", ["ngSanitize"]).d ...

Tips for preventing an element from scrolling horizontally along with the page body

This is the structure of my HTML: <div class='header-wrapper'> <div class='title'>Title</div> </div> <div class='some-wide-content'> </div> Let's imagine a scenario where the br ...

What is the best way to adjust the maxHeight within AccordionDetails and enable scrolling functionality?

I am looking to display a large amount of data using the Accordion component from material-ui nested inside a Box element. However, I am unsure how to customize the default styles in order to set a specific maxHeight. Is there a way for me to take control ...

I am looking to place two HTML buttons next to each other on the same line

I am trying to display two HTML buttons next to each other on the same line, with the "Submit Request(s)" button appearing first. The issue I am facing is that the top of the second button aligns with the bottom of the first one. The second button is cor ...

Is there an equivalent of getElementById for placeholder text?

I need help automating the input of information on a webpage using JavaScript. Each field has a unique ID, like this: <div id="cc-container" class="field has-float-label"> <input placeholder="ccnumber" id="credit_card_number" maxlength="16" ...

Guide to retrieving the primary key auto-increment value for the ID field in an SQL record using PHP Scripting

I am currently working on a multi-page web survey form and I have a PHP script called process.php that handles my responses on www.buythosecars.com. This script stores the responses in a MySQL table and then redirects the user to www.buythosecars.com/surve ...

Achieve a full-width background video without adjusting the height, preferably without the use of JavaScript

I have scoured various sources in search of the answer to this question but have come up empty-handed. While I am aware that similar queries have been made before, please hear me out. I am interested in incorporating a video background on a website where ...

Are there any PHP functions available that can check if the query string is empty?

I have experience with server-side development but not much in PHP. Currently, I'm working on a semi-basic tool with 10-15 pages and using the $_GET parameter for navigation. Is there a PHP function that can check if the query string is empty to dete ...

What could be the reason for the body background color refusing to change

I'm currently working on a JavaScript calculator project and I'm using this code snippet from codepen. The issue I'm facing is that despite setting the body background color to black, it still appears white. Could there be a spacing problem ...

Wrapping content in flexbox and aligning it justified

I have an issue where I want to display a page title on the left side and a rating number with stars on the right side. My goal is to center all items once flexbox wraps. Specifically, when the "Longer Page Title" reaches the rating and stars and the flexb ...

Using Font Awesome Icons and Bootstrap to Enhance Google Maps Info Bubble?

I'm currently working on customizing links within a Google Maps info-bubble using Bootstrap and font awesome Icons. Successfully integrated a list-group from bootstrap for my links in the info bubble, but running into issues when trying to include a ...

Create the columnHeader to match the width of the CSS column

Here's what I attempted: http://codepen.io/helloworld/pen/BcjCJ I aim for each column to have the same width as the column header visually. Currently, a slight difference in width exists between the column header and the actual column. Refer to the ...

`Loading CSS and JS files in node.js: A step-by-step guide`

I've searched through numerous similar questions without success, so I'm reaching out for help. My folder structure looks like this: Source Code Frontend Graphs.html Graphs.css Temperature.js Server_Backend server.js I aim ...

Identify Horizontal Swipe Gestures on Page-level

I am currently focused on ensuring accessibility for users utilizing voiceover technology. While navigating their phone, these individuals rely on right and left swipes to interact with elements on a page. I am seeking to implement swipe detection at the ...

Just finished my first webpage - can't seem to get the footer to stay put!

After spending 3-4 months learning HTML and CSS, I am now working on my first web page. However, I'm facing an issue where the footer is stuck to the slideshow and I can't seem to figure out how to position it at the bottom of the page. Any tips ...

Issue with locating image source in Angular 4

I'm struggling to source an image using angular 4. It keeps giving me an error message saying that the image cannot be found. Here is my folder structure: app_folder/ app_component/ - my_componenet - image_folder/ - myimage I am trying to ...

Tips on eliminating the 'first', 'previous', 'next', and 'last' buttons in the twbs pagination plugin

I am searching for a straightforward pagination solution that only displays page numbers without control buttons like "first," "previous," "next," and "last." I have looked through the options available in twbs-pagination's github documentation and on ...

Retrieve a specific item from a Database ListView in Django

I'm currently working on a project where I have a class that includes a django ListView. The issue I am facing is that when accessing my database items through this ListView, it loads all the entries. What if I only need to access one specific entry, ...

Is a footer fixed at the center anchored?

I've noticed that many solutions shared here seem to be overly complicated for what should be a simple task. My goal is to have a footer that remains fixed at the bottom of the screen regardless of page length. Although everything else seems to be wor ...

Is it necessary to encode the content before transmitting HTML in JSON from the server to the client?

When it comes to sending HTML content from the server to the client for displaying user comments in a rich JS app that communicates through a JSON API, there are some considerations to keep in mind. One important question is how to handle the content with ...