Centered image in circles positioned horizontally and vertically, all styled in Bootstrap 4

I am currently working on achieving a design similar to the one shown in the image below using Bootstrap 4 and CSS:

https://i.sstatic.net/now05.png

Here is the CSS code I have developed so far:

.inner-circle {
    display: block;
    height: 70px;
    width: 70px;
    line-height: 70px;

    -moz-border-radius: 50%; /* or 50% */
    border-radius: 50%; /* or 50% */

    background-color: #d2e4ff;
    text-align: center;
    font-size: 2em;
}

.outer-circle {
    display: block;
    height: 90px;
    width: 90px;
    line-height: 90px;

    -moz-border-radius: 50%; /* or 50% */
    border-radius: 50%; /* or 50% */

    background-color: #e7f1ff;
    text-align: center;
    font-size: 2em;
}

In addition, here is the HTML code I have used:

<div class="container" style="margin-top: 50px;">
        <div class="row">
            <div class="col-sm-6">
                <div class="row" class="h-100">
                    <div class="col-sm-2 h-100">
                        <span class="outer-circle mx-auto my-auto">
                            <span class="inner-circle mx-auto my-auto">
                                <img src="images/breakfast.svg" height="40" width="40" />
                            </span>
                        </span>
                    </div>
                    <div class="col-sm-10 my-auto">
                        <h4 class="display5">Cool stuff</h4>
                    </div>
                </div>
            </div>
            <div class="col-sm-6"></div>
        </div>
    </div>

The current result of this setup can be seen in the following image link:

https://i.sstatic.net/otucq.png

This result does not match my desired outcome. I have struggled to center the image within the inner circle and then position the inner circle within the outer circle. Is there an easy way to achieve this alignment, or should I consider creating the entire design as an image and inserting it instead?

Answer №1

If you want to center align both vertically and horizontally, using flex is the way to go.

.inner-circle {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 70px;
  width: 70px;
  -moz-border-radius: 50%;
  border-radius: 50%;
  background-color: #d2e4ff;
}

.outer-circle {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 90px;
  width: 90px;
  -moz-border-radius: 50%;
  border-radius: 50%;
  background-color: #e7f1ff;
}
<div class="container" style="margin-top: 50px;">
  <div class="row">
    <div class="col-sm-6">
      <div class="row" class="h-100">
        <div class="col-sm-2 h-100">
          <span class="outer-circle mx-auto my-auto">
                            <span class="inner-circle mx-auto my-auto">
                                A
                            </span>
          </span>
        </div>
        <div class="col-sm-10 my-auto">
          <h4 class="display5">Cool stuff</h4>
        </div>
      </div>
    </div>
    <div class="col-sm-6"></div>
  </div>
</div>

Answer №2

There are various methods to achieve this effect. The following approach utilizes absolute positioning for the inner circle.

.inner-circle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: block;
  height: 70px;
  width: 70px;
  line-height: 70px;

  -moz-border-radius: 50%;
  /* or 50% */
  border-radius: 50%;
  /* or 50% */

  background-color: #d2e4ff;
  text-align: center;
  font-size: 2em;
}

.outer-circle {
  display: block;
  height: 90px;
  width: 90px;
  line-height: 90px;
  position: relative;

  -moz-border-radius: 50%;
  /* or 50% */
  border-radius: 50%;
  /* or 50% */

  background-color: #e7f1ff;
  text-align: center;
  font-size: 2em;
}
<div class="container" style="margin-top: 50px;">
  <div class="row">
    <div class="col-sm-6">
      <div class="row" class="h-100">
        <div class="col-sm-2 h-100">
          <span class="outer-circle mx-auto my-auto">
            <span class="inner-circle mx-auto my-auto">
              <img src="https://www.iconsdb.com/icons/preview/tropical-blue/stackoverflow-6-xxl.png" height="40" width="40" />
            </span>
          </span>
        </div>
        <div class="col-sm-10 my-auto">
          <h4 class="display5">Exciting content</h4>
        </div>
      </div>
    </div>
    <div class="col-sm-6"></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

Change the position on the second click

I am trying to implement a manual sorting feature for a table of persons. The idea is to allow users to select a person by clicking on the row, then select another person by clicking on them, and have the two selected rows switch positions without using dr ...

Ways to enable users to showcase the files they have uploaded

I've successfully implemented code for file uploading. When saving the uploaded file in the database, I retrieve the uploader's username from another database. Additionally, I have a page that displays all uploaded files, functioning perfectly. N ...

How to adjust the size of the text on a button in jQuery mobile using custom

I am facing an issue with my jQuery mobile buttons that are placed inside a fieldset. Specifically, I need to adjust the font-size of one of the buttons. Despite attempting to add an inline style, it did not have the desired effect. Furthermore, I tried u ...

Struggling with aligning a div in the center

I've been struggling to get my "boxes" div centered on my page so that everything inside that div is centered instead of being pushed to the left. Unfortunately, my CSS vision didn't turn out as expected. If someone could take a look at my jsbi ...

Interactive Component overlying Layer - HTML/CSS

Currently, I am working on a web application that features a navigation bar at the bottom of the screen. To enhance visibility, I decided to apply a linear gradient overlay above the underlying elements. This screenshot illustrates what I mean. However, I ...

Is there a way for me to produce a random choice depending on the option selected by the user in the <select> menu?

As a beginner in JavaScript, I am attempting to create a feature where users can select a genre from a dropdown list and receive a random recommendation from that genre displayed on the screen. In essence, my goal is to allow users to get a random suggest ...

Exploring all the options within a dropdown menu using JQuery

Within the MVC 4 view, there is a dropdown box that, when its value changes, needs to capture all selected values. Each selection consists of three items: the Id, the visible value on the form, and a path to a file. While the functionality works for readin ...

Breaking the page with HTML and CSS

* { box-sizing: border-box; } .row { display: flex; } /* Creating two equal columns that sit side by side */ .column { flex: 50%; padding: 10px; } div.row { page-break-after: always; } <body> <div<div class="row"> ...

Transform a text node into an HTML element with the help of JQuery

Consider this HTML snippet: <div> Lorem ipsum <span>dolor sit</span> amet <span>consectetur adipiscing elit</span> eiusmod tempor </div> To select the text nodes [Lorem ipsum, amet, eiusmod tempor], ...

Flexbox margins (exceeding 100% total width)

Currently collaborating with @c4rlosls and we are facing 2 issues: https://i.sstatic.net/44WcI.jpg If the parent container with class container-fluid has a px-0, it extends beyond 100% width. Additionally, the elements with classes .cont2 a and .cont3 a do ...

Problem encountered when attempting to set and retain default values in a PHP select box

<form name="search" method="post" > Seach for: <input type="text" name="find" value="<?php echo (isset($_POST['find']) ? $_POST['find'] : ''); ?>" /> in <Select NAME="field"> <Option VALUE="catego ...

Is there a way to transform this JavaScript function into a jQuery plugin?

Hey there! I've been using this JavaScript function to print a div, but now I realize that I need to switch to jQuery. Can someone lend a hand in helping me convert this to jQuery code? $(document).ready(function(){ function printData() { ...

Icons on the top banner that adjust to different screen sizes

I am still getting acquainted with Wordpress, so please bear with me if I use incorrect terminology or ask silly questions. I am eager to learn and improve. My website is focused on jewelry (using Kallyas premium), and I have a row of banner icons between ...

Are there any Bootstrap 4 classes that have the "cursor:pointer" style other than "btn"?

I am currently utilizing the Bootstrap cards class for my project and I am trying to achieve a cursor pointer effect when hovering over certain cards. However, I prefer not to resort to using the style attribute and only want to utilize Bootstrap classes ...

Adjusting the dimensions of the canvas leads to a loss of sharpness

When I click to change the size of the graph for a better view of my data in the PDF, the canvas element becomes blurry and fuzzy. Even though I am using $('canvas').css("width","811"); to resize the canvas, it still results in a blurry graph. I ...

Creating a Shadow Effect on CSS Triangles

I have created a unique design that resembles a large arrow pointing to the right. <div style=" font-size: 0px; line-height: 0%; width: 100px; border-bottom: 80px solid #8cb622; border-right: 62px solid #dadbdf; "></div> <div style=" font ...

Issues with Bootstrap split button display malfunctioning

Experiencing an issue with a Bootstrap split button while working on a test Drupal website. Although it seems to be working fine in Codepen and JSFiddle, on this particular website, the dropdown component appears to be getting pushed under the button. Desp ...

Is there a way to include an optional backslash in URLs using the .htaccess file without leading browsers to believe I am navigating to a subfolder?

As I update my php pages with the .htaccess file, I am facing an issue where the pages do not load properly when an optional backslash ("/") is included in the URLs. One possible solution is to use absolute URLs instead of relative ones so that CSS and J ...

Is it possible to combine the :last-child pseudo-class with the universal selector (*) in CSS or Sass

Here is the code I am currently using: .loken5 * padding-right: 5px .loken5:last-child padding: 0 I am wondering if there is a way in SASS to achieve the same effect with just one '.loken5' tag for saving space. Thank you :) ...

Utilize Pseudo Elements for Designing a Unique Background Overlay

I am aiming to create a div with a customizable background, and then utilize a pseudo element to generate a semi-transparent white overlay that will lighten the background of the div. The crucial requirement is for the "overlay" to appear beneath the conte ...