What is the best way to create responsive radio buttons on top of an image?

I have a photograph of the beautiful Hawaiian islands, and I've positioned 8 radio buttons using absolute positioning. However, when I inspect the image with the radio buttons on Chrome, I notice that they are not responsive and do not stay in their correct spots on the image when viewed in full screen mode. Any suggestions on how to fix this?

CSS:

#radio1{
    position:absolute;
    top:58.9%;
    left:24.4%;
}

#radio2{
    position:absolute;
    top:57.5%;
    left:27.1%;
}

#radio3{
    position:absolute;
    top:63.2%;
    left:34.05%;
}

#radio4{
    position:absolute;
    top:66.8%;
    left:38%;
}

#radio5{
    position:absolute;
    top:68.9%;
    left:40.4%;
}

#radio6{
    position:absolute;
    top:69.7%;
    left:38.8%;
}

#radio7{
    position:absolute;
    top:73.1%;
    left:40.5%;
}

#radio8{
    position:absolute;
    top:78.8%;
    left:45.5%;
}

#third.form img{
    display:block;
    max-width: 100%;
    height: auto;

HTML:

<img src="map.png">
<label for="radio1"></label><input type="radio" name="radio" id="radio1" required><br>
<label for="radio2"></label><input type="radio" name="radio" id="radio2"><br>
<label for="radio3"></label><input type="radio" name="radio" id="radio3"><br>
<label for="radio4"></label><input type="radio" name="radio" id="radio4"><br>
<label for="radio5"></label><input type="radio" name="radio" id="radio5"><br>
<label for="radio6"></label><input type="radio" name="radio" id="radio6"><br>
<label for="radio7"></label><input type="radio" name="radio" id="radio7"><br>
<label for="radio8"></label><input type="radio" name="radio" id="radio8"><br>

Answer №1

The shifting of the dots occurs due to the fact that their left and top coordinates are calculated based on the overall container dimensions, rather than just the individual div they are contained in.

Answer №2

When positioning radio buttons in relation to the body element, it is important to consider using absolute positioning. However, since image tags are inline and cannot contain HTML child elements, a workaround is to place the radio buttons within a parent div element. By adding a background image to this div element, you can achieve the desired layout where the radio buttons are positioned absolutely with respect to the parent container.

#container{
  position:relative;
  background-image:url(https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRiWmnVBwnR9ddbHOGmGaoA3gTrU5r3pslI-IybKWIJz4Amy6VA);
  background-size:cover;
  width:200px;
  height:200px;
}
#radio1{
position:absolute;
top:58.9%;
left:24.4%;
}

#radio2{
position:absolute;
top:57.5%;
left:27.1%;
}

#radio3{
 position:absolute;
top:63.2%;
left:34.05%;
}

#radio4{
position:absolute;
top:66.8%;
left:38%;
}

#radio5{
position:absolute;
top:68.9%;
left:40.4%;
}

#radio6{
position:absolute;
top:69.7%;
left:38.8%;
}

#radio7{
position:absolute;
top:73.1%;
left:40.5%;
}

#radio8{
position:absolute;
top:78.8%;
left:45.5%;
}

#third.form img{
display:block;
max-width: 100%;
height: auto;
<div id="container">
  <label for="radio1"></label><input type="radio" name="radio" id="radio1" required><br>
  <label for="radio2"></label><input type="radio" name="radio" id="radio2"><br>
  <label for="radio3"></label><input type="radio" name="radio" id="radio3"><br>
  <label for="radio4"></label><input type="radio" name="radio" id="radio4"><br>
  <label for="radio5"></label><input type="radio" name="radio" id="radio5"><br>
  <label for="radio6"></label><input type="radio" name="radio" id="radio6"><br>
  <label for="radio7"></label><input type="radio" name="radio" id="radio7"><br>
  <label for="radio8"></label><input type="radio" name="radio" id="radio8"><br>
</div>

Answer №3

To start, create a container to group the radio button elements and use an island image as the background.

Next, utilize media queries to adjust the image size for a responsive layout.

.container {
  position: relative;
  background-image: url(http://hawaiian-words.com/hw/wp-content/uploads/2014/09/hawaii-island-road-map.jpg);
  background-size: cover;
  width: 884px;
  height: 927px;
}

#radio1 {
  position: absolute;
  top: 58.9%;
  left: 24.4%;
}

#radio2 {
  position: absolute;
  top: 57.5%;
  left: 27.1%;
}

#radio3 {
  position: absolute;
  top: 63.2%;
  left: 34.05%;
}

#radio4 {
  position: absolute;
  top: 66.8%;
  left: 38%;
}

#radio5 {
  position: absolute;
  top: 68.9%;
  left: 40.4%;
}

#radio6 {
  position: absolute;
  top: 69.7%;
  left: 38.8%;
}

#radio7 {
  position: absolute;
  top: 73.1%;
  left: 40.5%;
}

#radio8 {
  position: absolute;
  top: 78.8%;
  left: 45.5%;
}

#third.form img {
  display: block;
  max-width: 100%;
  height: auto;
}

@media screen and (max-width: 768px) {
  .container {
    width: 884px;
    height: 927px;
  }
}

@media (max-width: 768px) and (min-width: 480px) {
  .container {
    width: 663px;
    height: 695px;
  }
}
@media (max-width: 480px) {
  .container {
    width: 442px;
    height: 463px;
  }
}
<div class="container">
  <label for="radio1"></label><input type="radio" name="radio" id="radio1" required><br>
  <label for="radio2"></label><input type="radio" name="radio" id="radio2"><br>
  <label for="radio3"></label><input type="radio" name="radio" id="radio3"><br>
  <label for="radio4"></label><input type="radio" name="radio" id="radio4"><br>
  <label for="radio5"></label><input type="radio" name="radio" id="radio5"><br>
  <label for="radio6"></label><input type="radio" name="radio" id="radio6"><br>
  <label for="radio7"></label><input type="radio" name="radio" id="radio7"><br>
  <label for="radio8"></label><input type="radio" name="radio" id="radio8"><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

Issue caused by overflowing content and resizing the display

I am facing a challenge with my website. Essentially, my webpage has the <html> set to overflow:hidden, with two horizontal navbars, a fixed vertical sidebar on the left, and a central div with the height: 90% property. Edit: The container div now ...

Tips for eliminating extra blank space under the footer on an HTML website

Just beginning my journey with bootstrap and I am encountering an issue on my website where there is space after the footer when resizing to a mobile size. I've tried setting margin: 0; padding: 0; but it hasn't resolved the problem. Here's ...

Anchor tag in AngularJS not responding to ng-disabled directive

I have been successfully using ng-disabled for input and buttons, but I have run into an issue with anchor tags. How can I make it work for anchor tags as well? HTML code <a ng-disabled="addInviteesDisabled()">Add</a> JS code $scope.addIn ...

Tips for utilizing divs and spans in HTML5

When it comes to web development, HTML markup is utilized for structuring content, while CSS is used for styling and presenting that content. In the past, HTML elements like <div> were often assigned semantic meaning through the use of IDs and class ...

Automated form with built-in calculations

Whenever a product is selected from the dropdown menu, the price value should be automatically filled in the input field with ID #price. Then, the user can enter the quantity in the input field with ID #quantity, and the total sum of price multiplied by qu ...

Designing templates for websites and applications using node.js

Simplified Question: As I delve into improving my skills with node.js, I'm exploring the concept of templating. How would using node to serve one HTML file and loading page-specific information through AJAX/sockets impact performance and design princ ...

Show a popover within a parent div that has limited visible space due to its hidden overflow

Struggling with AngularJS, I can't seem to find a simple solution for this problem. In my code, there's a div element with the overflow: hidden property set due to an internal scrollbar. Inside this div, there's a dropdown menu that is trigg ...

Sort the elements within the *ngFor loop according to the category upon clicking the button in Angular

Currently, I have a collection of items that I am iterating through using *ngFor. Above this list, there are category buttons available as shown in the HTML snippet below. My goal is to enable filtering of the list based on the category of the button click ...

Is it advisable to utilize both bootstrap.css and normalize.css simultaneously?

Is it redundant to use both bootstrap.css and normalize.css since bootstrap already includes a version of the code from normalize.css? In order to ensure thorough cross-browser compatibility, should I use both bootstrap and normalize.css, or is using just ...

When trying to insert glyphicons into a textarea, the result is displaying the actual text instead

When the glyphicon is clicked, I want the entered content to be added dynamically to the textarea. $(document).ready(function(){ //Click Event of glyphicon class $(document).on('click','.glyphicon',function(){ ...

What size should I use for creating a responsive website?

After scouring the internet, I stumbled upon numerous dimensions referred to as proper for developing responsive designs. However, I am specifically interested in identifying the ideal breakpoints, particularly for mobile devices with small screens like ...

Stylish curved bottom border

Is it feasible to create this footer using just CSS? https://i.sstatic.net/b33w4.png Appreciate the help! ...

What is the best way to ensure an image fills the entire space within a Bootstrap modal container?

I'm having some issues with my bootstrap modals that contain images. When the images are long vertically, a scrollbar appears which is not ideal. I tried to solve this by setting a max-height for the modal-content and making the modal-body (where the ...

Displaying content in Bootstrap 5 modal with jQuery may cause a delay in the appearance of a centered spinner before the content loads

In my Bootstrap 5 modal, I have implemented specific functionality in jQuery where a centered spinner is supposed to show up in the modal before loading the content. You can see a live example of this here. The issue I am facing is that the spinner takes ...

Stop Ag grid from automatically extending to the entire width of the screen

I am encountering an issue where my table scales to the full width available even when the content is limited. Take a look at the demo here: "https://plnkr.co/edit/6L8bTAwkEV6R6Be4M1Qm?p=preview" I have attempted to address this problem by settin ...

Having RoundRect take the top left position of its rectangle container rather than its immediate parent (td)

I am currently troubleshooting an email-related issue that is specifically affecting Outlook In order to create a round Call To Action (CTA) button, I utilized Vector Markup Language (VML) The expected result should look like this: https://i.sstatic.net ...

Generate an HTML webpage with dynamic content using MySQL

How can I display data from a MySQL table on an HTML page? The content in my table includes various rows that I would like to show separately on the web page. This is the structure of my table: I envision the web page layout to showcase each row individ ...

Issue with displaying Django messages on the contact form template

Having trouble getting a message box to display on my Django site's contact form. Despite following all necessary steps outlined in the documentation, the message I am creating fails to appear upon submission. Referencing the Django docs for enabling ...

I found myself continuously revolving four images along a circular border, each time revealing the corresponding content. However, I only required the content from one of the images at a time

I attempted to animate the rotation of a circle and display the content of a specific image by pausing it for a period of time. However, I am unsure how to halt the animation and display the content of the specified image. Here's what I tried: HTML C ...

Conceal specific pages within the DataTable without deleting them

Currently, I am facing an issue where the dataTable paginates and removes the DOM pages along with the data. My goal is to extract all the data from the dataTable and convert it to JSON without losing access to the DOM when pagination occurs. I want to m ...