Adding a close button inside a circular background using HTML/CSS

I'm struggling to align the X inside the circle perfectly; they just don't seem to match up no matter what I try. Here's a glimpse:

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

html:

    <div class="messages">
    <span class="closebtn dot" onclick="this.parentElement.style.display='none';">×</span>
        {% for message in messages %}
            <span><li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li></span>
        {% endfor %}
    </div>

CSS:

.messages {
    position: sticky;
    width: 235px;
    z-index: 1;
    float: right;
    border-radius: 1px;
    margin: 0 20px;
}

.closebtn {
    color: #535353;
    font-size: 30px;
    cursor: pointer;
    position: absolute;
    z-index: 1;
    margin: -25px 0 0 -10px;
}

.dot {
  height: 25px;
  width: 25px;
  background-color: #bbb;
  border-radius: 50%;
  display: inline-block;
}

Answer №1

To include these additional style settings in your CSS file for the .dot class element:

 .dot {
     text-align: center;
     line-height: 25px;
  }

Answer №2

To style the close button, you should add all the CSS properties in the .closebtn class. Make sure to set the line-height to 25px and text-align to center.

.closebtn {
    color: #535353;
    font-size: 30px;
    top: 5px;
    cursor: pointer;
    position: absolute;
    z-index: 1;
    height: 25px;
    width: 25px;
    line-height: 25px;
    text-align: center;
    background-color: #bbb;
    border-radius: 50%;
}
<div class="messages">
    <span class="closebtn" onclick="this.parentElement.style.display='none';">×</span>
    </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

Is it possible to remove strings within HTML elements?

{% for term in terms %} <div class="term term-count-{{loop.index}}"> <b>{{ term }}</b>: &nbsp;&nbsp; {{ terms[term] }} &nbsp;&nbsp; </div> {% endfor %} 'terms' is a dictionary w ...

Using Laravel and Bootstrap v4, you can easily implement a feature that redirects to a specific tab after

I have a webpage featuring 3 tabs. I am trying to set up the page so that it redirects to the same tab that was active before the reload. I assume each tab should append a string to the URL, like #menu1 or #menu2, but I'm having trouble implementing t ...

When the width of the screen is less than 992 pixels, my div will be hidden

I have been working with the bootstrap4 layout, and I noticed that when the screen width is less than 992px, the yellow-div is overlapping the brown-div. Can someone explain why this is happening and suggest a solution? Below is the code snippet: .head ...

I'm having trouble getting my accordion menu to work properly. Whenever I click on the question title, the answer doesn't seem to show up or collapse. What could be causing this issue?

I am currently working on a project to create an accordion menu where the answers are hidden and only revealed upon clicking the question. However, when I test it out, nothing happens when I click on the question. Here is my code: .accordion-Section ...

Ensure that bulleted lists and numbered lists are aligned to the left side

Check out this website where the ordered and unordered lists are not aligned correctly. The ideal alignment would have the bullets (or numbers) left aligned. For instance, the number "1." should be aligned to the left on the same line as the heading "Per ...

What is the best way to initiate a change event using JavaScript?

I am attempting to enable my 4th checkbox automatically when there is a new value in the textbox (myinput). If the textbox is empty, I want to disable it. Currently, you have to tab out before the change event is triggered. Also, how can I check for an e ...

Frame Tweet Integration

Attempting to create an iframe modal with a Twitter share source. <iframe src="https://twitter.com/share" class="tweetFrame"></iframe> The current setup is not functioning properly, resulting in a blank page. Is there a workaround to ensure t ...

React - Material UI Divider not centered

Is the title says - my divider is not centered in the middle of my text. The current result displays a misalignment: https://i.sstatic.net/0FjKN.png However, I am aiming for my divider to be placed in the center like this (refer to red line): https://i. ...

Issue with AJAX/Javascript functionality

Hey there! I'm currently working on an ajax call to a function called build_Array. This function is supposed to break down a string named myString, which contains "Call 1-877-968-7762 to initiate your leave.,1,0,through;You are eligible to receive 50% ...

Using Python's BeautifulSoup library to pull information from an HTML table

I need help extracting a table from a webpage. Here's the HTML and Python code using beautifulsoup that I've been trying with. It usually works for me, but this time it's coming up blank. Any insights are appreciated! <table> <thea ...

Adjust link when scrolling through the webpage

I am looking to update the URL while scrolling instead of changing the menu class. Here's the reference I found: https://codepen.io/anon/pen/LdLgNo I made some modifications by adding push state, but I'm facing an issue with a fixed header. I ...

Having trouble incorporating custom elements with the document.execCommand function

I have been attempting to insert a custom element into an editable div using the document.execCommand method as described in detail on https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand. However, when I try to add a custom polymer eleme ...

Several buttons, each requiring to show distinct text

Currently, I am attempting to enhance an existing project that was graciously created for me. I must admit, I am quite new to this, so please be patient with me! In my project, there are 9 buttons, each triggering the display of a different image upon bei ...

Having trouble getting JavaScript to replace tags in HTML

I've been working hard to replace all the shared code in posts on my website, but I'm having trouble getting it to work. I want everything inside <pre><code></code></pre> tags to be colorized using CSS. Here's a sampl ...

Utilize a custom endpoint for Microsoft Graph Toolkit: "Implement a domain-specific endpoint"

I'm currently following the instructions provided at this Microsoft Graph Toolkit tutorial. My code is quite straightforward, including the script reference, the mgt-msal2-provider element with my client-id specified, and a basic login component < ...

Having trouble converting HTML to Ajax

When working on my website's Videos Page Layout, I encountered this snippet in the video script: <div class="video-views pull-left"> {$videos[i].viewnumber|kilo} {if $videos[i].viewnumber == '1'}{t c='global.view&apo ...

CSS - stacking containers vertically with scrollbars

I am in need of a vertical stack of blocks, which may include scrolls, contained within a fixed-sized container without scrolls. The number of visible blocks is dynamically managed by JavaScript code. Some blocks can be hidden or shown, and when a block is ...

Using HTML video to fill entire div container

I'm currently facing an issue with using an HTML video as a fullscreen background replacement for an image. The problem is that the video overflows and covers the entire page instead of staying within the constraints of the header section. Here is th ...

Even when the dimensions are set to 100 width and height, the scroll bar still makes an

I recently embarked on my journey to learn web development by enrolling in a course on Udemy. Currently, I am diving into CSS3/HTML5 and have started a small project involving CSS3 - creating a web page that represents the Universe. My goal is to incorpora ...

Implementing a Method to Detect Keypress Event on Anchor Element

Within our application, we have implemented anchor tags as buttons to enable specific style implementations. An interesting feature of the anchor tag is that it does not receive focus when navigating through tabs. Although we have successfully implemented ...