What is the best way to center the circle and arrow within the border using CSS?

When the "hit" button is clicked, the arrow should move to touch the circle and change the color of the circle.

My goal is to position the circle on the left side and center, with the arrow on the right side and center.

section {
  border: 3px solid black;
  height: 60vh;
  width: 90vh;
  margin: auto;
}

h1 {
  text-align: center;
}

.circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background-color: red;
  position: relative;
  display: flex;
  align-items: center;
}

.icon-arrow {
  width: 90px;
  height: 3px;
  background-color: black;
  border-radius: 2px;
  position: relative;
  top: 49px;
  float: right;
}

.icon-arrow:after {
  content: '';
  display: inline-block;
  width: 30px;
  height: 2px;
  background-color: black;
  transform: rotate(45deg);
  position: absolute;
  left: -5px;
  top: 11px;
}

.icon-arrow:before {
  content: '';
  display: inline-block;
  width: 30px;
  height: 2px;
  background-color: black;
  transform: rotate(-45deg);
  position: absolute;
  right: 65px;
  bottom: 9px;
}
<h1>Bubble App</h1>

<section>
  <div class="container">

    <div class="circle"></div>
    <div class="icon-arrow" style="display: flex; align-items: center; "></div>


  </div>

</section>

<div class="button">
  <button onclick="hit()">Hit</button>
  <button onclick="reset()">Reset</button><br>
</div>

I'm facing alignment issues with the circle and arrow, where changing the circle's position affects the arrow's position. How can this be resolved?

Additionally, how do I align the button to the right side under the border section?

Answer №1

Are you satisfied with the changes I made? If you need further assistance, feel free to reach out.

I implemented the display flex feature to align the elements based on the border as per your request. As a result, the circle and arrow are now centered within the border.

.container{
border: 3px solid black;
height: 60vh; 
width: 90vh;   
margin: auto;
display: flex;
justify-content: space-between;
align-items: center;
}

h1{
    text-align: center;
}

.circle {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background-color: red;
}

.icon-arrow{
    width: 90px;
    height: 3px;
    background-color: black;
    border-radius: 2px;
    position: relative;
}

.icon-arrow:after{
    content: '';
    display: inline-block;
    width: 30px;
    height: 2px;
    background-color: black;
    transform: rotate(45deg);
    position: absolute;
    left: -5px;
    top: 11px;
}

.icon-arrow:before{
    content: '';
    display: inline-block;
    width: 30px;
    height: 2px;
    background-color: black;
    transform: rotate(-45deg);
    position: absolute;
    right: 65px;
    bottom: 9px;
}


    
<h1>Bubble App</h1>

<section class="container">
  <div class="circle" ></div>
  <div class="icon-arrow"></div>
</section>

<div class="button">
  <button onclick="hit()">Hit</button>
  <button onclick="reset()">Reset</button><br>
</div>

Answer №2

Hopefully, this information proves to be helpful. If there is any confusion or if you need more specific details, please feel free to reach out and ask your question in more detail.

.container{
border: 3px solid black;
height: 60vh; 
width: 90vh;   
margin: auto;
display: flex;
justify-content: center;
align-items: center;
}

h1{
    text-align: center;
}

.circle {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background-color: red;
}

.icon-arrow{
    width: 90px;
    height: 3px;
    background-color: black;
    border-radius: 2px;
    position: relative;
}

.icon-arrow:after{
    content: '';
    display: inline-block;
    width: 30px;
    height: 2px;
    background-color: black;
    transform: rotate(45deg);
    position: absolute;
    left: -5px;
    top: 11px;
}

.icon-arrow:before{
    content: '';
    display: inline-block;
    width: 30px;
    height: 2px;
    background-color: black;
    transform: rotate(-45deg);
    position: absolute;
    right: 65px;
    bottom: 9px;
}

.button {
    text-align: right;
}

    
<h1>Bubble App</h1>

<section class="container">
  <div class="circle" ></div>
  <div class="icon-arrow"></div>
</section>

<div class="button">
  <button onclick="hit()">Hit</button>
  <button onclick="reset()">Reset</button><br>
</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

The stickiness of elements causes scrollbars to disappear in Chrome 77 on OSX

In this scenario, I have set up two tables where the first one has a sticky header achieved with position: sticky; top: 0px; https://codepen.io/seunje/pen/JjjRVLm The sticky header works perfectly fine, but there is an issue with scrollbars disappea ...

Can you please tell me the term used to describe when a background adjusts and follows the movement of a mouse cursor?

Just wrapped up freeCodeCamp's HTML & CSS Responsive Web Design course and noticed a cool feature in some portfolios that I'd like to learn. However, I'm not sure what it's called. Here are some examples: The video game Escape From Ta ...

Incorporating a clickable button over a video

I've exhausted all available resources trying to figure this out and have hit a dead end. My goal is to place a button on top of the video, but my lack of CSS expertise is hindering me. Can someone please help me identify what I'm doing wrong wit ...

Changing the positions of objects on a resized HTML Canvas

I am currently developing a tool that allows users to draw bounding boxes on images using the Canvas and Angular. Everything was working smoothly until I encountered an issue with zooming in on the canvas causing complications when trying to draw bounding ...

Discovering additional element information while utilizing the 'Sortable' feature

My Current Objective: In my setup, I have a 'calendar' comprising 5 columns, each column containing 5 separate divs known as timeslots. The main purpose here is to show appointments in these specific timeslots and utilize JQuery's Sortable ...

Personalize PDF display using Bootstrap and CodeIgniter

In my Bootstrap collapse menu, I have the following setup: <div class="card"> <div class="card-header" id="headingTwo"> <h5 class="mb-0"> <button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo" a ...

Preventing HTML form from being resubmitted upon page refresh after submission

I am facing an issue with my HTML form. Whenever I click submit, the form data is sent to the same php page. However, after submitting, when I refresh the page, the web browser shows a re-submission dialog. How can I prevent the form from submitting again ...

iOS exhibits a flashy display of Material Select lighting up

In my attempt to develop a website using Material Design, I encountered an issue with the Material Select component. Whether I utilize MDB (Material Design for Bootstrap) or the Materialize CSS framework, both function well on Windows/OSX/Android devices. ...

What measures can be taken to stop links from disrupting the style of a Polymer site?

In Polymer, it seems that many styles are inherited from the surrounding document. For example, the code snippet below will display the icon and button with a white foreground color and adjust spacing: <paper-toolbar> <paper-icon-button icon=" ...

Launch a nearby hyperlink in a separate tab

I am currently facing an issue where all the URLs in a Text get linked as Hyperlinks. However, when a user types www., the browser interprets it as a local URL and associates the link with the application's URL. Does anyone know how to open a local U ...

Issue with border styling in Material-UI vertical ToggleButtonGroup

In my current front-end project, I have implemented the React Material UI ToggleButtonGroup. For a Multiple Selection example with vertical styling, you can refer to this code snippet: https://codesandbox.io/s/eyk66?file=/demo.js However, I encountered a ...

"Enable a smooth transition and switch the visibility of a div element when clicked

How to create a dropdown form with a transition effect that triggers on click of an element? Once triggered, the transition works smoothly but clicking again only hides the div element without triggering the transition. See the demo here: Check out the fu ...

Using various designs on elements generated from ng-repeat

Is it possible to apply different styles to buttons created using ng-repeat by having b.color return a value from the btnValues object? Currently, it is not returning the value. If this is not possible, are there alternative methods to achieve this? < ...

Duplication of elements in a Meteor and React environment

When it comes to creating a basic Meteor app with React, this is the structure I have put in place: <head> <title>test</title> </head> <body> <div id="render-target"></div> </body> Here is the start ...

Modify content or display picture within accordion panel based on its identifier

In my view, I have a model representing a list of items. Each item has a unique ID, which is included in the H2 header tag. The details of each item are displayed in a div below the header. Initially, there is an image within the header that is set to disp ...

What strategies can be used to accurately position a rotated image within a rotated div?

Below is the code snippet I am using: <div class="container"> <img class="img"/> <div class="underlay"></div> </div> The image is a picture of some rotated text by 10 degrees, although the ...

Set the height of the div to be the full height of the page when designing for responsiveness

For my responsive design, I am looking to have a footer that sticks to the bottom of the page while allowing the content to fill up the remaining space. You can view an example here: http://jsfiddle.net/rzjfhggu/1/ In this example, the header has a fixed ...

IE11 is unable to display the background image

I am attempting to create a process roadmap by using background images on list items. The background-image on the list item is not showing up in IE11 (also in all versions of IE10, 9, etc). CSS CODE body{padding: 50px 0;} .status-line { width: 80%; ...

Set a variable to a specific cell within a table

I've been attempting to insert images into a table and have had success so far - clicking cycles through the available options. However, I've encountered an issue where the counter is not cell-specific but rather global. Is there a way to create ...

What is the method for creating a beveled text effect using CSS?

Is there a CSS-only method to achieve a beveled text effect? https://i.sstatic.net/s4Wlw.png Just to clarify, I'm seeking a way to make text appear thick with a beveled style rather than using something like text-shadow which simply extends the font ...