Place the divs over the background image by using relative positioning

I am working on a project where I have a full-width div with a background image containing people. I want to display a tooltip when hovering over each person, but I am facing challenges in aligning the divs properly.

Image maps with % widths do not seem to be feasible for this task, so I am experimenting with using DIVs instead. Here is an example of what I have tried:

<div class="homepageimage">
<div class='artistmap' id='davidmap'></div>
<div class='artistmap' id='ceceliamap'></div>
<div class='artistmap' id='erinmap'></div>
<div class='artistmap' id='aimap'></div>
<div class='artistmap' id='tommap'></div>
</div>

Here is the CSS code snippet that accompanies it:

.homepageimage{
 width:100%;
  max-width:2000px;
  height:750px;
  margin:auto;
  margin-top:-50px;
 background: url({{ 'homepage_test2.jpg' | asset_url }});
  background-size:cover;
  background-position:center center;
  background-repeat:no-repeat;
  clear:both;
  overflow:hidden;
 }

 .artistmap{
   height:100%;
   border:2px solid red;
   float:left;
 }

 .artistmap:hover{
  content:attr(title); 
 }

 #davidmap{
  width:10%; 
 }

 #ceceliamap{
   width:15%;
 }

 #erinmap{
  width:5%; 
 }

 #aimap{
    width:5%; 
 }     

 #tommap{
  width:10%; 
 }

I have realized that depending on the screen size, the alignment of the divs may be off. What is the most effective way to address this issue?

You can view the code I mentioned above live at .

Your insights and suggestions would be greatly appreciated. Thank you!

Answer №1

Take a look at this interactive FIDDLE that could assist you.

Styling with CSS

.americangothic {
    float: left;
    width: 315px;
    height: 384px;
    background: url(http://www.artic.edu/aic/collections/citi/images/standard/WebLarge/WebImg_000256/190741_3056034.jpg );
    background-size: 315px 384px;
    position: relative;
}
.changemediv1 {
    float: left;
    width: 50px;
    height: 50px;
    margin-left: 20px;
    background-color: red;
    border: 3px solid gray;
}
.changemediv2 {
    float: left;
    width: 50px;
    height: 50px;
    margin-left: 20px;
    background-color: blue;
    border: 3px solid gray;
}

.face1:hover ~ .changemediv1  {
    background-color: green;
}
.face2:hover ~ .changemediv2  {
    background-color: green;
}
.face1 {
    width: 80px;
    height: 110px;
    border: 0px solid red;
    position: absolute;
    top: 70px;
    left: 35px;
}
.face2 {
    width: 80px;
    height: 130px;
    border: 0px solid red;
    position: absolute;
    top: 30px;
    left: 180px;
}

img {
    width: 315px;
    height: 384px;
}

Remember to keep all the divs within the same container for proper display.

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

Incorporating and utilizing the HTML5-captured image as a point of reference

I understand that all I need to do to achieve this is insert <input type="file" id="photo" accept="image/*;capture=camera"> However, my lack of coding skills has caused issues with actually grabbing and using the image selected/taken by the user. ...

Tips for showing placeholder text on Safari

I'm having an issue with the placeholder attribute in Safari. It seems to be working fine in all other browsers, but not in Safari. <textarea class="concerncommentArea" placeholder="Place your comment here"></textarea> Does anyone know h ...

The operation of inserting values into the database encountered an issue due to an invalid cursor state, resulting in a java.sql.SQLException error with the

I am encountering an issue with invalid cursor state error while running this code snippet in my application. The technology stack I am using includes SQL Server 2005 along with JSP and HTML. <% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Conn ...

When trying to load a php page2 into page1 via ajax, the Javascript code fails to execute

Currently, I am in the process of learning PHP and JavaScript. I have encountered a particular issue with a webpage setup. Let's say I have a page called page1 which consists of two input fields and a button labeled 'Go'. Upon clicking the & ...

Tips for improving the speed of loading infinite scroll pages

I am currently working on scraping over 100k rows from the provided URL. The data goes back approximately a month, loading in batches of 7-8 rows at a time. My current approach involves using a macro to scroll down the page slowly, which is effective but ...

Switch from Index.html to Index.html#section1

Currently, I am working on a website and sending someone a draft for review. However, the Home screen is designed as a 'a href' link with "#home". The issue arises when the website opens from my computer; it goes to ...../Index.html instead of .. ...

What is the best way to assign both first and last names to an array with keys and values, then showcase the result?

<!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8> <title>practice session</title> </head> <body> <!-- $name1 = first--> <!-- $name2 = last--> <?php echo " ...

Issue: Map container not located when implementing a leaflet map with Angular

Here is the complete error message: core.js:6479 ERROR Error: Map container not found. at NewClass._initContainer (leaflet-src.js:4066) at NewClass.initialize (leaflet-src.js:3099) at new NewClass (leaflet-src.js:296) at Object.createMap [a ...

Bring a div box to life using AngularJS

Struggling to animate a div-Box in AngularJS? Despite trying multiple examples, the animation just won't cooperate. I'm aiming to implement a feature where clicking on a button triggers a transition animation to display the search form. I under ...

What is the method for aligning a button label to the left and an icon to the right?

I have a list of items and I want to display label text on the left and a check icon on the right. This works fine when the text is short, but when I added the textOverflow property, the icon gets hidden along with the rest of the text. Here is my list ...

Using Node.js and the Jade templating engine, display the value of a passed variable

Asking such a basic question makes me feel guilty. app.get('/skumanagement/:id', function (req, res){ var options = req.params.id; // req.params.id = itemidx database.skuGetDetail(options, function (error, data){ winston.log('inf ...

Developing a placeholder directive with AngularJS

Are you looking to create a unique element in AngularJS to facilitate nested ng-repeats? Take a look at the example below: data.test = [{h:1, d:[11,12]}, {h:2, d:[21,22]}]; ---------------------- <custom ng-repeat="a in data.test"> <h3>{{a ...

JavaScript code: "Retrieve the div element and append metadata to the HTML file

Currently, I am utilizing the subsequent technique to save a target tag on my webpage as an HTML file. function retrieveHtml(filename, elId, format) { var htmlEl = document.getElementById(elId).innerHTML; if (navigator.msSaveBlob) { // IE 10+ ...

Delete the line-height property from the initial line

I have created text that is aligned using the "justify" option, and I would like to add some leading to the text. However, I want the first line of the text to remain at x:0px y:0px. Does anyone know how to remove the line-height from the first line of a ...

Utilizing Bootstrap in Laravel to align the heights of rows in adjacent columns

I am in the process of developing a calendar application that includes a header row and a header column. The layout displays six days in columns with a fixed number of time periods per day. <div class="row"> <div class="col-md c ...

The Jquery ajax request fails to function properly once the webpage has been published live

We've implemented a basic jQuery ajax call. A "more" button triggers a call to another PHP file when clicked. While it worked fine on my local server and initially on the live server, it suddenly stopped working live. The code functions perfectly o ...

Integrate a resizable sidebar on the webpage's right side that dynamically adjusts the layout

As I develop a Chrome Extension, my goal is to incorporate a sidebar into all webpages without overlapping the existing content. The sidebar should be placed beside the content, effectively reducing the width of the body of the webpage to the initial width ...

Is it possible to use display:grid with a parent element set to a height of 100%

Why doesn't the display:grid property stretch my content to the height of this column? The HTML structure row - col-6 is created using Bootstrap. I am aware that I can manually set a specific height for the parent container, but I would prefer not to ...

What is the best way to run a JavaScript function once another function has finished executing?

I am looking to ensure that a JavaScript function runs only after another one has finished executing. Here is the code I currently have: $(window).load(function(){ $('#dvLoading').fadeOut(2000); }); window.addLoadEvent = function() { $('#p ...

How can I make my modal box appear after someone clicks on selecting a college?

Can someone help me figure out how to display my modal box after clicking into the selecting list? I've already coded it, but I'm struggling with getting it to show up after the click event. Any assistance is appreciated! In the image provided, ...