Circular container housing SVG icons next to another container using Bootstrap 4.5

Currently, I am delving into the world of Bootstrap 4.5 and SVG icons. However, I'm facing some challenges in grasping how it all comes together. My goal is to place an SVG inside a rounded-circle shape for now, positioned next to another div. Unfortunately, I'm struggling to align them side by side on the same line. Here's a snippet of the code I've been working with:

.svg-icon {
  display: block;
  margin: 0 auto;
  position: absolute;
  top: calc(50% - 14px);
  left: calc(50% - 14px);
}

.poll-icon-container {
  height: 50px;
  width: 50px;
  position: relative;
  border-radius: 50%;
  background-color: pink;
}
<div class="rounded-circle poll-icon-container text-success">
  <svg
    width="2em"
    height="2em"
    viewBox="0 0 18 18"
    class="bi bi-box-arrow-in-up-right svg-icon"
    fill="currentColor"
    xmlns="http://www.w3.org/2000/svg"
  >
    <path
      fill-rule="evenodd"
      d="M14.5 3A1.5 1.5 0 0 0 13 1.5H3A1.5 1.5 0 0 0 1.5 3v5a.5.5 0 0 0 1 0V3a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 .5.5v10a.5.5 0 0 1-.5.5H9a.5.5 0 0 0 0 1h4a1.5 1.5 0 0 0 1.5-1.5V3z"
    />
    <path
      fill-rule="evenodd"
      d="M4.5 6a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 .5.5v5a.5.5 0 0 1-1 0V6.5H5a.5.5 0 0 1-.5-.5z"
    />
    <path
      fill-rule="evenodd"
      d="M10.354 5.646a.5.5 0 0 1 0 .708l-8 8a.5.5 0 0 1-.708-.708l8-8a.5.5 0 0 1 .708 0z"
    />
  </svg>
</div>
<div>
  should be on the right side of the icon 
</div>

Answer №1

When utilizing Bootstrap, consider enclosing those 2 divs within a single parent div and implement the flex display in a bootstrap-friendly manner

d-flex - A Bootstrap class that sets block to display: flex;

justify-content-start - A Bootstrap class that aligns content at the start of the flex container with justify-content: flex-start;

align-items-center - A Bootstrap class that centers items vertically by setting align-items: center;

ml-3 - A Bootstrap sizing class that applies a left margin of 1rem with margin-left: 1rem;

.svg-icon {
  display: block;
  margin: 0 auto;
  position: absolute;
  top: calc(50% - 14px);
  left: calc(50% - 14px);
}

.poll-icon-container {
  height: 50px;
  width: 50px;
  position: relative;
  border-radius: 50%;
  background-color: pink;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/js/bootstrap.min.js"></script>

<div class="d-flex justify-content-start align-items-center">
  <div class="rounded-circle poll-icon-container text-success">
    <svg width="2em" height="2em" viewBox="0 0 18 18" class="bi bi-box-arrow-in-up-right svg-icon" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
    <path
      fill-rule="evenodd"
      d="M14.5 3A1.5 1.5 0 0 0 13 1.5H3A1.5 1.5 0 0 0 1.5 3v5a.5.5 0 0 0 1 0V3a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 .5.5v10a.5.5 0 0 1-.5.5H9a.5.5 0 0 0 0 1h4a1.5 1.5 0 0 0 1.5-1.5V3z"
    />
    <path
      fill-rule="evenodd"
      d="M4.5 6a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 .5.5v5a.5.5 0 0 1-1 0V6.5H5a.5.5 0 0 1-.5-.5z"
    />
    <path
      fill-rule="evenodd"
      d="M10.354 5.646a.5.5 0 0 1 0 .708l-8 8a.5.5 0 0 1-.708-.708l8-8a.5.5 0 0 1 .708 0z"
    />
  </svg>
  </div>
  <div class="ml-3">
    should be on the right side of the icon
  </div>
</div>

Answer №2

Implementing inline css using position: absolute; is crucial for achieving certain design effects.

.svg-icon {
  display: block;
  margin: 0 auto;
  position: absolute;
  top: calc(50% - 14px);
  left: calc(50% - 14px);
}
.poll-icon-container {
  height: 50px;
  width: 50px;
  position: relative;
  border-radius: 50%;
  background-color: pink;
}
<div class="rounded-circle poll-icon-container text-success"   style="display:inline-block;">
                <svg
                  width="2em"
                  height="2em"
                  viewBox="0 0 18 18"
                  class="bi bi-box-arrow-in-up-right svg-icon"
                  fill="currentColor"
                  xmlns="http://www.w3.org/2000/svg"
                >
                  <path
                    fill-rule="evenodd"
                    d="M14.5 3A1.5 1.5 0 0 0 13 1.5H3A1.5 1.5 0 0 0 1.5 3v5a.5.5 0 0 0 1 0V3a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 .5.5v10a.5.5 0 0 1-.5.5H9a.5.5 0 0 0 0 1h4a1.5 1.5 0 0 0 1.5-1.5V3z"
                  />
                  <path
                    fill-rule="evenodd"
                    d="M4.5 6a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 .5.5v5a.5.5 0 0 1-1 0V6.5H5a.5.5 0 0 1-.5-.5z"
                  />
                  <path
                    fill-rule="evenodd"
                    d="M10.354 5.646a.5.5 0 0 1 0 .708l-8 8a.5.5 0 0 1-.708-.708l8-8a.5.5 0 0 1 .708 0z"
                  />
                </svg>
              </div>
              <div style="display: inline-block; margin-left:10px;line-height: 50px; position: absolute;">
                should be on the right side of the icon 
              </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 a modal be opened in Angular 6 using only Bootstrap, without the use of Material?

In my left bar component, there is a button to open a modal. How can I make sure that the modal is opened when the button is clicked, but not within the component itself? ...

"Troubleshooting: Child Component Not Reflecting Changes in UI Despite Using Angular

My child component is designed to display a table based on a list provided through @Input(). The data is fetched via http, but the UI (child component) does not update unless I hover over the screen. I've seen suggestions about implementing ngOnChange ...

The switch case functionality refuses to change when I interact with the user interface

Can someone please help me troubleshoot? I'm not receiving any errors in the Chrome console. HTML <div class="wrapper"> <i id="repeat" class="fas fa-stop-circle"></i> </div> Javascript const wrap ...

I can't figure out why my navbar-brand won't budge from the left side of the screen. I've attempted using ml-5, but it's still not

https://i.sstatic.net/wo35v.jpg I have experimented with different margin classes like ml-5 in Bootstrap 5 to create spacing. <body> <nav class="navbar navbar-expand navbar-dark bg-dark"> <a class="navbar- ...

Prevent the parent component's ripple effect from being activated by the child component

If I have a simple code snippet like the following: <ListItem button={true} > <Typography variant='caption' color='primary'> {value} </Typography> <Button onClick={foo} > Button ...

What is the best way to create a blurred effect on an image during loading, and then transition to a sharp image once it is fully loaded?

I'm currently working on a project where I want the images to display as a blurred preview initially, and then become clear once fully loaded. This is similar to the feature seen on Instagram, where the app shows a blurred image before displaying the ...

What has caused the space between these articles?

I have created a section containing three articles and I am confused about the margin/padding between the articles: This is my HTML code: <section id="home"> <article> <h1>Overview</h1> </article> <article> <h1& ...

Facing a selection list issue on a web application built with Flask and Vue.js

I'm trying to integrate Flask and Vue.js together, but I've encountered an issue with my select element. The following code snippet is present in my HTML file: <div class="col-sm-10"> <select class="form-select" v-mod ...

What could be causing my class to not be affecting a specific element in Sass?

Using React and sass, I attempted to utilize the activeClassName property on a NavLink component but found that my active class was not working as expected due to its order in relation to the default class. How can I resolve this issue? Here is the code: ...

Using CSS to style divs within fieldset tag

I've been working on creating a fieldset with divs inside, but I'm facing an issue where the 1px border-bottom on each div is not showing up. .debt_row_odd { display: table-row; width: 100%; background-color: #eef6 ...

Is it possible to use v-if in conjunction with a style tag to specify a different source file? Alternatively, is there a more efficient method I

I attempted the example provided below, but unfortunately, it did not function as expected. The reason behind my endeavor is that adding numerous modifiers (--tuned) to achieve the desired outcome seemed impractical. Therefore, I decided to try and link ...

Guide to updating text color in marquee tag with each reload

Seeking assistance in addressing the following issues... On each refresh, I want to change the text color within a marquee tag by utilizing a JavaScript function. I have obtained a color code like #18EEC5... however, when attempting to call the script fun ...

What is the best way to insert images into a div in Ionic framework?

I am facing an issue with fitting an image inside a div container. Here is my code structure: <div style="background-color: red; height: 200px; width: 200px;"> <ion-img src="{{kategori[i].img}}"></ion-img> & ...

What are the best practices for installing jQuery and Bootstrap using bower in a correct manner?

For my Laravel project, I decided to use bower to incorporate Twitter Bootstrap and jQuery. Setting up bower to place packages in the "public/components" directory seemed like a good idea initially. However, I soon realized that bower installs entire pac ...

Open $_POST in a new tab that has been edited for your convenience

<form method="post" target="_blank" action="battle.php" onsubmit="window.open('battle.php','','width=700,height=500,toolbar=0,menubar=0,location=0,status=0,scrollbars=0,resizable=0,left=30,top=0');" > < ...

Retrieve Object Key in Angular 7

I have a specific item: this.item = { name:"Michael", age:18 }; I am looking to display it in an HTML format. name: Michael age: 18 <div >{{ item (name) }}</div> --??? should put name <div>{{ item.name }}</div> < ...

Create a sorting feature for a ListView that allows users to organize items by price in both ascending and descending order, as

view.py class HomeView(ListView): model = Item template_name = "home.html" paginate_by = 12 template <div class="header-dropdown"> <a href="#">A to Z</a> <div class="header-me ...

Stop the page from scrolling when scrolling within a specific DIV to address the [Violation] warning appearing in the console

Initially, it may seem like a duplicate question that has been answered here, but there are additional aspects that need to be addressed. How do I resolve the following [Violation] warning in the Google Chrome console? [Violation] Added non-passive eve ...

What is the best way to create a sticky menu bar?

I have this code snippet at the beginning of my website: <body> <div class="agile-main"> <div class="menu-wrap" id="style-1"> <nav class="top-nav"> <ul class="icon-list"> ...

List items are loaded dynamically in an unordered fashion

I have been working on a jquery slider using flickerplate. Below is the code that works when the values are hardcoded: <div class="flicker-example"> <ul> <li data-background="lib/flicker-1.jpg"> <div class ...