Overlap elements without using absolute positioning and prevent resizing distortion

Looking to incorporate a line with tick marks and a ball (similar to a scale) into my design.

Some tutorials recommend using absolute positioning or float for this effect. While these methods work partially, I've noticed that the divs tend to shift out of place when the screen size is changed.

.line {
  width: 100%;
  min-height: 5px;
  background-color: black;
  padding: 20px;
  margin-top: 20%;
}
.point {
  -moz-border-radius: 50px/50px;
  -webkit-border-radius: 50px 50px;
  border-radius: 50px/50px;
  border: solid 21px #f00;
  width: 50px;
  height: 50px;
  background-color: red;
  float: right;
  overflow: visible;
  position: relative;
  z-index: 1000;
  padding: 20px;
  margin-top: -15%;
}
<div class="line"></div>
<div class="point"></div>

Answer №1

Enclose it in a div and make sure to use absolute positioning for the inner divs, avoid using margin-top percentages (https://jsfiddle.net/xv259d4p/1/):

.line {
    width:100%;
    min-height:5px;
    background-color:black;
    padding:20px;
    margin-top:60px;
    position: absolute;
}
.point {
    -moz-border-radius: 50px/50px;
    -webkit-border-radius: 50px 50px;
    border-radius: 50px/50px;
    border:solid 21px #f00;
    width:50px;
    height:50px;
    background-color:red;
     float: right;
    overflow: visible;
    position: absolute;
    z-index: 1000;
    padding:20px;
    right: 0;
    margin-top: 20px;  

}
.outer {
  display: block;
  width: 100%;
  top: 0px;
  left: 0px;
  position: relative;
}
<div class="outer">
  <div class="line"> </div>
  <div class="point"></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

Unable to view Bootstrap modal upon click

Whenever I attempt to display a modal using Bootstrap, it mysteriously appears upon page refresh but fails to show up when the button is clicked. Ideally, I want the modal to only appear when the user clicks on the button. The structure of my html file lo ...

Incorporating External Content into Your HTML Website

Looking to incorporate third-party content in the form of an HTML page within my own website, I considered utilizing iframes. This would allow me to embed the external HTML page within my site while keeping their libraries and CSS separate from mine. Howe ...

The issue with NGX-Bootstrap/Angular Pagination arises when attempting to adjust the maxSize input while the screen view (width) is being altered

Currently, I am utilizing the Pagination component from Valor Software (click here to access). I am interested in adjusting the maxSize input dynamically based on changes in screen width. For reference, please see this example: Click to view example. It ...

Reloading a webpage does not clear HTML tables containing jQuery interactions in Firefox

Apologies if this question has already been asked. I incorporated hide/unhide features using jQuery into a simple HTML table. The table functioned correctly in Chrome 24.0.1312.52 m and IE8+. Yet, upon refreshing the page in Firefox 15.0.1, the pr ...

Tips for customizing the CSS styling of the validation ng-class error

Seeking advice: Is there a way to customize the CSS style of the 'error' validation error for ng-class in Bootstrap v3? This is my current code: ng-class="(form.datos.$invalid) && ( form.datos.$touched || submitted) ? 'error&apos ...

It seems that CSS shadows are working perfectly on Firefox and Chrome, but unfortunately, they are not displaying on

I have encountered an issue where CSS shadows appear fine on Firefox and Chrome, but do not display in Internet Explorer. Below is the code I am using: -moz-box-shadow: 0 0 20px #000; Can anyone provide a solution for this compatibility problem? Thank ...

Customize your form fields with Bootstrap 3 input groups

Currently, I am working on implementing a bootstrap 3 input group, but unfortunately, the outcome is not meeting my expectations. My goal is to create a select [input]-[input text]-[button] structure all in one line. However, in my scenario, the button has ...

Animating a SVG element within a group tag using the path element

I'm struggling to make a slice of a circle rotate using the :hover selector in CSS. Even though my initial attempt at applying CSS transformations works perfectly, the rotation stops when I introduce the :hover selector. Below is the HTML and CSS co ...

Tips for preventing an element from scrolling horizontally along with the page body

This is the structure of my HTML: <div class='header-wrapper'> <div class='title'>Title</div> </div> <div class='some-wide-content'> </div> Let's imagine a scenario where the br ...

Executing a JavaScript function using document.write()

When I try to click on the SWF part1 links within the document.write() function in order to call the openswf function, nothing happens. Here is my code: <html> <a href="#" onclick="Popup();">show popup</a> <script> functio ...

A PHP script or regular expression that swaps the positions of characters within a string

(Update1: per suggestion by George Cummins) I need assistance in creating a regex search and replace or a php function to switch positions of characters within a string. (since I couldn't figure it out on my own) For example, if I have the following C ...

Submitting the form with a target of _blank will result in the form being submitted on both a

I am currently working on a form that includes both a "Submit" button and a "Preview" button. While the submit button is functioning correctly, I am experiencing an issue with the Preview button. When clicked, it opens up a new page with the preview as in ...

Unable to set height:auto for the background image

For more information, visit this link. I am looking to customize the comments area by giving it a solid color that dynamically adjusts its height based on the number of comments. The background color should expand if there are many comments and shrink if ...

When the user clicks, automatically direct them to a different webpage

I tried to create a changing background color effect in the following order: Black, White, Red, Green, Blue. <body style="background-color:black"> <script type="text/javascript"> function changeColor() { var currentBg ...

How can I create an element in Javascript that does not inherit any CSS styles?

I'm creating a basic userscript with Greasemonkey for a school project that inserts a bright yellow box containing links onto all websites. Currently, my approach is straightforward: var guesses_div = document.createElement("div"); guesses_div.style. ...

Customize the CSS styling of third-party components in different pages using NextJS

When working with third-party components, you can include their styles by importing their stylesheet into your component or _app.tsx file. For detailed instructions on how to do this, you can refer to Next.js documentation. Another option is to add the sty ...

Compatibility of HTML5 websites with Internet Explorer

Following a tutorial on HTML5/CSS3, I meticulously followed each step to create a basic website. While the demo of the site worked perfectly in Internet Explorer 8 during the tutorial, my own version did not display correctly when viewed in IE8. I discove ...

Select a specific date range from a form and export CSV file containing MySQL data within that range

I have successfully implemented a database CSV export functionality, but now I am looking to allow the user to specify a date range for the export process. Below is the HTML section that handles the date selection (date format: mm/dd/yyyy): <form act ...

What is the reason that CSS does not have built-in support for variables and hierarchy?

I am relatively new to UI development and I find CSS to be quite challenging to work with. Scenario: [ Experimented with CSS & less ] I wanted to apply specific styles within a particular div on a page. CSS approach : div.class1 { font: normal 12px ...

Extract certain headers from a JSON file

For API details, visit I am looking to extract specific headers like "issue_text" from the HTML format data obtained through a GET request. Can someone assist me in achieving this? ...