Creating a contact page with Font Awesome icons similar to my design using Flexbox in CSS

How can I achieve the desired layout for this image?

I have written some code and applied CSS to get the output, but I encountered an issue. When the text in my address section is too large, the icon gets misaligned and collapses. How can I fix this issue without using bootstrap? I want to learn more about using the flex property. Here is a link to my JSFiddle.

 *{
      margin: 0;
    }
    section{
      background-color: #555;
      padding: 2rem 0;
      text-align: center;
    }
    .contact{
      display: inline-block;
      text-align: left;
    }
    .contact h2{
      color: white;
      font-size: 1.125rem;
      font-weight: 500;
      text-align: center;
      text-transform: uppercase;
      margin-bottom: 20px;
    }
    .contact li{
      display: flex;
      align-items: center;
      margin-bottom: 10px;
    }
    .contact li:last-child{
      margin: 0;
    }
    .contact a{
      color: white;
      text-decoration: none;
    }
    .contact a:hover{
      color: yellow;
    }
    .contact p{
      color: white;
      line-height: 1.4;
    }
    .contact .fa{
      color: white;
      font-size: 1.5rem;
      line-height: 30px;
      margin-right: 10px;
      width: 30px;
      height: 30px;
      text-align: center;
    }
 <section>
      <div class="contact">
        <h2>Contact us</h2>
      <ul>
        <li>
          <i class="fa fa-envelope"></i> 
          <a href="#"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7302061600071a1c1d00331d1604101c5d101c1e">[email protected]</a></a>
        </li>
        <li>
          <i class="fa fa-phone"></i> 
          <a href="#">111-222-333</a>
        </li>
        <li>
          <i class="fa fa-building-o"></i>
          <p>NewCo, Inc <br>
            123 Main St. <br>
            Somewhere, CA 12345
          </p>
        </li>
      </ul>
      </div>
      
    </section>

Answer №1

Since the h2 element does not contain an icon on its left side, it requires compensation for this. Additionally, the default padding of the ul element needs to be addressed.

To achieve the desired outcome, you can introduce a new rule, .contact ul, with padding-left: 0. Add margin-left: 40px; (the total width including the right margin of the icon) to the existing .contact h2 rule while removing text-align: center.

This adjustment will align elements as intended:

*{
  margin: 0;
}
section{
  background-color: #555;
  padding: 2rem 0;
  text-align: center;
}
.contact{
  display: inline-block;
  text-align: left;
}
.contact h2{
  color: white;
  font-size: 1.125rem;
  font-weight: 500;
  /*text-align: center;                   removed */
  text-transform: uppercase;
  margin-bottom: 20px;
  margin-left: 40px;                  /* added */
}
.contact ul{
  padding-left: 0;                    /* added */
}
.contact li{
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
.contact li:last-child{
  margin: 0;
}
.contact a{
  color: white;
  text-decoration: none;
}
.contact a:hover{
  color: yellow;
}
.contact p{
  color: white;
  line-height: 1.4;
}
.contact .fa{
  color: white;
  font-size: 1.5rem;
  line-height: 30px;
  margin-right: 10px;
  width: 30px;
  height: 30px;
  text-align: center;
}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<section>
  <div class="contact">
    <h2>Contact us</h2>
    <ul>
      <li>
        <i class="fa fa-envelope"></i>
        <a href="#"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c2b3b7a7b1b6abadacb182aca7b5a1adeca1adaf">[email protected]</a></a>
      </li>
      <li>
        <i class="fa fa-phone"></i>
        <a href="#">111-222-333</a>
      </li>
      <li>
        <i class="fa fa-building-o"></i>
        <p>NewCo, Inc <br> 123 Main St. 123 Main St.123 Main St. <br> Somewhere, CA 12345
        </p>
      </li>
    </ul>
  </div>

</section>

</body>

</html>

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's the best way to undo a CSS transition animation when deleting an active class?

I'm currenty working on a straightforward icon animation within a VueJS application. I've implemented a Vue transition to create a fade effect on the background elements, but I'm exploring options for a subtle upward shift animation specific ...

A single image with dual clickable areas managed by an interactive image map

Is there a way to attach two href links to one image using CSS? I want it to function like an old school image map, but purely with CSS. Is this something that can be done? The current HTML code looks like the example below. However, I need the image to h ...

What is the best way to integrate JavaScript with my HTML command box?

I'm having some trouble with an HTML command box that is supposed to execute commands like changing stylesheets and other tasks. I thought I had everything set up correctly, but it doesn't seem to be working at all. Below is the HTML code with th ...

Choose the specific Element by its dynamicID in JQuery

Just starting out with Jquery and I have a specific task in mind. In my HTML page, I have elements with IDs generated by concatenating a string variable. My goal is to use JQuery to select the element with this dynamically generated ID. See below for more ...

Website loses its css after printing

I'm having trouble printing a website with a simple layout featuring two columns, each containing tables. The website I want to print is located at the following link: . However, when I try to print it using the JavaScript function window.print(), the ...

Checkbox: Activate button upon checkbox being selected

On my webpage, I have a modal window with 2 checkboxes. I want to enable the send button and change the background color (gray if disabled, red if enabled) when both checkboxes are selected. How can I achieve this effectively? HTML: <form action="" me ...

div table with varying cell styles on each row

Is it feasible to achieve a table layout resembling the one depicted below using only div tags and CSS? _________________________________________________ | | | | | | | | ...

Support the Cause with Paypal Contributions on Angular/Bootstrap Website!

I'm currently in the process of developing a website using Angular and Bootstrap for a non-profit organization that will facilitate donations through Paypal. On the platform, users will have the option to select their donation frequency (Weekly, Mont ...

What is the CSS solution for eliminating a line break immediately following the first word?

While designing an email template in html/css for a mailing list, I encountered an issue where on mobile devices the line breaks after the first word for every paragraph. You can see an example of this problem here. The code for the email template was gen ...

What is the best way to perfectly align an SVG inside its container?

Is there a way to horizontally center this SVG within .svg_wrapper? .svg_wrapper { border: 1px solid grey; width: 200px; } <div class="svg_wrapper"> <svg viewBox="0 0 600 425"> <path d="M 175, 175 m 0, -75 a 75,75 0 1,0 ...

Responsive design element order rearrangement

My code example is as follows: <div class="info-container"> <span class="item1">item1</span> <a class="item2" href="#">item2</a> <a class="item3" href="#">item3</a> </div> I want to rearran ...

Spacing applied to content within a fresh Vue application

Having been assigned the task of developing a Vue page for my team, I am facing an issue with a persistent white border surrounding the entire page. <script setup lang="ts"> </script> <template> <body> <div>&l ...

Discovering elements with multiple classes using watir-webdriver

In this scenario, let's consider an element like the one below: <div class="first_class second_class"></div> Now, we can locate it by its classes using the following methods: browser.div(class: 'first_class') browser.div(class ...

Unresponsive JavaScript on specific element IDs

I'm experimenting with making three lines perform different animations: line 1 rotating 45deg and translating, line 2 becoming opaque, and line 3 rotating -45deg and translating. Check out my JS Fiddle here <a href="#"><div id="menu" onclic ...

The background color of the div or section is stubbornly refusing to change, no matter how much I tweak it

.forBackground { background-color: white; } .kontaktUndMapContainer { width: 100%; padding: 20px; color: gray; text-align: center; } .überschriftKontakt { margin-bottom: 20px; } .überschriftKontakt2 { margin-top: 20px; margin-bottom: 2 ...

Using PHP's modulus operator, you can dynamically apply CSS classes to a grid of images based on alternating patterns

Exploring the use of modulus to dynamically apply a CSS class to images displayed in a grid under different scenarios: Situation 1 In this situation, the goal is to target and apply a CSS class to middle images marked with *. Since the number of images ...

Activate vertical scrolling in JavaScript when an image is clicked

I currently have a collection of button images with different hover effects specified like this: <img src="home.PNG" onmouseover="this.src='homemo.PNG'" onmouseout="this.src='home.PNG'" /> My goal is to make them scroll down to ...

Conceal the scrollbar track while displaying the scrollbar thumb

Hey there! I'm looking to customize my scroll bar to have a hidden track like this. Everyone's got their own style, right? ::-webkit-scrollbar{ width: 15px; height: 40px; } ::-webkit-scrollbar-thumb{ background-color: #DBDBDB; borde ...

Menu changes when hovering

I want to create an effect where hovering over the .hoverarea class will toggle the visibility of .sociallink1, .sociallink2, and so on, with a drover effect. However, my code isn't working as expected. Additionally, an extra margin is automatically ...

Are there any libraries available to simplify HTML development in C#, .NET, or ASP.NET?

I have a vivid memory of stumbling upon a project where an individual utilized json-like strings to generate high-quality HTML in a certain programming language. Is there a similar tool available for use with C# or .NET? radio-box{ AName, [First|Second| ...