Custom Tags in HTML and CSS: Managing Element Overlap with Absolute Positioning

I've recently developed a custom HTML tag called <bubble></bubble> which allows for unique styling using the custom type attribute.

Code snippet:

bubble[type=normal] {
  border-radius: 10px;
  background-color: #5e9bff;
  text-align: center;
  color: white;
  padding: 6px;
  width: 50px;
}
<bubble type="normal">Hello!</bubble>

However, I encountered an issue with positioning the element when it is nested within div tags. The specified width: 50px; property seems to be ignored unless I use Position: Absolute;, but this approach introduces another problem explained below. Additionally, the element partially overlaps surrounding text even after applying margins on Top and Bottom.

Adjusted code with Absolute Positioning:

bubble[type=absoluteposition] {
  position: absolute;
  border-radius: 10px;
  background-color: #5e9bff;
  text-align: center;
  color: white;
  padding: 6px;
  width: 50px;
  margin-top: 10px;
  margin-bottom: 10px;
}
<bubble type="absoluteposition">Hello!</bubble>

The use of position: absolute; behaves similar to float: left; which is not desired even after setting margins on top and bottom. This particular issue also arises when using div tags.

Here's a demonstration on JSFiddle.net

If you have a solution, believe there is an error in my code, know an alternative way to resolve this issue, or require additional details on my inquiry, please don't hesitate to respond.

Answer №1

If you find the need to specify height and width when using absolute positioning, consider wrapping the bubble tag in another div with a relative position like so:

<div class="container" style="
    position: relative;
    display: inline-block;
    width: 100px;
    height: 50px;
">
<bubble type="absolute-position">Hello!</bubble>
</div>

Cheers!

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

Invoke a controller method within a component's template path

Is it possible to access a controller's function from within a component enclosed within a div that is controlled by the same controller? The component: angular .module('myApp') .component('taxiCard', { templateUrl: '/t ...

What is the best way to incorporate responsive centered text into my HTML element using Bootstrap 4?

Is there a way to add a responsive centered text element to my <a> element without being affected by the overlay color? Also, is there an alternative method to using an extra overlay div in Bootstrap 4? Check out this link for more details. HTML & ...

The search bar automatically conceals any results that are not actively being searched for

I am currently looking to only display or store local data related to the words "Apple" and "Car." Specifically, if a user types in "apple", I want the results to show the word "apple" while hiding the word "car", and vice versa. Currently, each item has ...

Is there a way to convert the structure of HTML/CSS into JSON format?

<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> .collapsible { background-color: #004c97; color: white; cursor: pointer; padding: 18px; width: 100%; border: none; text ...

javascript snippet for extracting the dynamically created div IDs

Currently, I am developing an application using Java and AngularJS. Within this project, there is an HTML page that iterates through an object to display the values on the page. Here is the snippet of the HTML code: <div id="{{value.pageIndex}}" ng-re ...

Save an automatically generated number into a variable and use it to reference an image file for display. This process can be accomplished using JavaScript

I'm having trouble getting my images to display randomly on a page. The images are named 0 - 9.png and I am using a pre-made function for random number generation. However, when I try to call on this function later down the page, nothing appears. It ...

Selenium in Java is unable to send keys or click on elements

I am attempting to login to this specific website Below is the code I am using : driver.findElement(By.id("userid_sebenarnya")).sendKeys("myUserName"); This is the property for the input text field with id='userid_sebenarnya' <div class="f ...

watching a video on my site

I've been struggling to embed an .mp4 video file into my webpage. Despite searching on websites like this one and w3c here, I haven't found a solution yet. It seems that I need to use two file formats (mp4 and ogv) and I'm unsure if I can us ...

Find and make adjustments to the primary HTML document in your Magento online shop

Trying to enhance the top banner of my Magento website tamween.biz by adding a shadow effect PNG picture. Successfully managed this on my local server using firebug and creating a new class in the coding area with all selector properties modified in the bo ...

Detect when a child li element is clicked and then toggle the class of its parent div

I have a div container that contains an unordered list tab menu. By clicking on each tab, the menu content changes correspondingly. The functionality is working well, but I want to alter the background image of the container div based on which li is clicke ...

Ways of accessing an array within an if statement

I have a dashboard with admin privileges for my application. In this dashboard, the admin can select a user from a dropdown list. Once a user is selected, I make an AJAX call to retrieve the user's data and store it in a variable named $result. Howeve ...

Is it truly such a challenge to set a background image for a div?

To achieve a full-width div with a background image and text on top, you can use the following code: Below is the HTML for the div: <div class="dpsplash"> </div> And here's the CSS for the dpsplash class: .dpsplash { background-ima ...

Clicking on an anchor tag will open a div and change the background color

.nav_bar { background: #c30015; margin-left: 50px; float: left; } .nav_bar ul { padding: 0; margin: 0; display: flex; border-bottom: thin white solid; } .nav_bar ul li { list-style: none; } .nav_bar ul li a { ...

Troubleshooting problem with CSS alignment within Bootstrap framework

Having trouble with the alignment when using bootstrap CSS. My desired layout is as follows: Place name: dropdownbox Gender (radio-button)Male (radio-button)Female Amount Max: textbox Min: textbox Any advice on how to achieve this? ...

Using Jquery to dynamically add a textbox with a display:none property set to its value

In this scenario, I have added dynamic rows to a table with textboxes and span tags. Now, I am performing some calculations. In the demo, you will see a textbox for a multiplier factor. Upon change, the last column in my table (Calculated area provided) i ...

What is the process for incorporating a backup font for displaying unsupported characters in font-face?

I have incorporated a unique font for the Hebrew language on my website, but I am encountering an issue with missing English characters from a-b, A-Z. Currently, I have applied the font (reformaregular) to the body tag: body { font-family: 'reformar ...

Placing an image on the chosen option of a <mat-select> using Angular Material

I have incorporated Angular Material into my Angular 2 project, and I am trying to insert a static image (HTML element) in the selected value of mat-select. Unfortunately, I have been unable to find a solution for this issue. Is there anyone who can ...

The CSS styles are not being applied to the PHP code

I seem to have a tangled mess of CSS / PHP / HTML to deal with. The issue I'm facing is that something works on one PHP script but not the other. Here's a snippet of my code: <?php if ($daten->getData_DB_User($get_page_num) != fa ...

Craft a stunning transparent border effect using CSS

I am trying to achieve a unique border effect for an element using CSS, where the transparency is maintained against the background: This is the desired outcome: https://i.stack.imgur.com/6Z1MU.png However, the border I am currently able to create looks ...

Show photos from ftp server using php

I am looking for a way to showcase all images from an ftp server on my website using php. Ideally, I would like the images to be sorted automatically so that if I add more images to the ftp server, they will be seamlessly incorporated into the display. My ...