Dynamic container elements (already arranged)

After creating a marksheet generator, I noticed that the divs positioned over an image on the resulting page are not responsive when trying to print. The print preview ends up looking strange and distorted. How can I make these already positioned divs responsive?

Specifically, how can I adjust the following HTML to be responsive? HTML

#name {
  position: absolute;
  top: 17.4%;
  left: 31%;
}

#cl {
  position: absolute;
  top: 18%;
  left: 58%;
}
<div id="name">
  <font size="3" face="courier new"><b><%out.print(name);%>  </b></font>
</div>

<div id="cl">
  <font size="2" face="courier new"><b> -<%out.print(cl);%></b></font>
</div>

Answer №1

To fully grasp how positioning functions in CSS, it is essential to familiarize yourself with the concept. Here is a helpful resource that explains positioning in CSS: https://css-tricks.com/almanac/properties/p/position/

Additionally, all absolute child elements should be contained within a relative parent div.

Here is an example structure:

<div class="relative_parent">
  <div id="name">
    <font size="3" face="courier new"><b><%out.print(name);%>  </b></font>
  </div>

  <div id="cl">
    <font size="2" face="courier new"><b> -<%out.print(cl);%></b></font>
  </div>
</div>

.relative_parent{
  position: relative;
}

#name {
  position: absolute;
  top: 17.4%;
  left: 31%;
}

#cl {
  position: absolute;
  top: 18%;
  left: 58%;
}

This setup ensures that when the parent div's dimensions change, its internal child elements will adjust accordingly.

Quick Tip: Avoid using IDs for styling in CSS as they have higher specificity than classes. It is recommended to reserve IDs for JavaScript functionality to prevent conflicts and maintain consistency.

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

What is causing my 100% height to be excessively large?

I'm facing an issue with my background containers, "background-overlay" and "background-gradient", as they are extending the height of the document beyond the actual content displayed. I am unsure of what could be causing this problem. It might be som ...

Strategies for concealing and revealing content within dynamically loaded AJAX data

I am attempting to show and hide data that is loaded using Ajax. $.ajax({ type: "POST", url: "/swip.php", data: {pid:sldnxtpst,sldnu:sldnu}, success: function(result) { $('.swip').prepend(result); } }); This data gets ...

What is the best way to generate an accordion populated with data from a MySQL query?

Everything is in order, I've got all the chapters and video series extracted without any issues: $id_course = 1; $stmt = $con->prepare("SELECT c.chapter, v.preview, v.title_video, ...

What is the process for inserting a hyperlink onto an image within a query slider?

I am experiencing difficulties when attempting to add hyperlinks to the images in my slider. I have come to understand that images cannot be clickable in jQuery sliders, so I have tried the following in the HTML: <div class="wrapper"> <div class= ...

"Troubleshooting a JSON structure containing a complex array of objects with multiple layers

I've structured a complex array with JSON objects to allow users to customize background images and create unique characters. Below is the main code snippet: var newHead; var newBody; var newArm; var masterList = [ { {"creatureName":"Snowman ...

Design and styling with HTML5 and CSS

Having a small issue with my code as I venture back into coding after a long hiatus, resulting in me forgetting some basics. Currently, I am attempting to create a simple HTML layout. Upon inspecting the page, I noticed that it appears slightly longer tha ...

What is the best way to position an image beside a jquery dialog box?

Apologies for not finding a suitable topic to discuss. Is it possible to place an image next to a jQuery dialog, similar to the following example? If so, how can this be achieved? ...

ui-grid row size set to automatically adjust using rowHeight : 'auto'

Has anyone else experienced this strange behavior with ui-grid? When I set the rowHeight to auto, each cell in the same row ends up with different heights. One of the cells contains multiline data, which seems to be causing issues for ui-grid. I've ev ...

Do you know the term for when JavaScript is utilized to display specific sections of a png image?

Imagine you have an image file in the format of a PNG which includes various icons intended for use on a website. How can JavaScript be utilized to choose and showcase a specific icon from that image? It's a technique I've observed in practice, b ...

Having trouble installing css-sprite on Windows 8.1 using NPM

Having trouble installing css-sprite on my Windows 8.1 system. Here's what I have installed so far: Windows 8.1 (x64) Node.js 0.12 (x86) NPM 2.5.1 (x86) Python 2.7.9 (x86) Visual Studio 2013 Express (x86) I tried to install using the command: npm ...

A common challenge in React is aligning the button and input line on the same level

I'm currently working on a React page where I have an input field and a button. My goal is to align the bottom edge of the button with the bottom line of the input. Here's the code snippet I have: `<form className='button-container'& ...

Display issue with ul and li elements in Safari browser causing menu to appear incorrectly

Although I am new to CSS, I managed to create a menu on my website that hovers over the background video successfully. It is a basic menu using a ul with li elements and it appears as intended in all browsers except Safari. In Safari, the menu items stack ...

Interact with various contenteditable sections by navigating with the arrow keys

I have a challenge with multiple <p contenteditable="true"></p> elements on my page. I am seeking a solution to enable the use of arrow keys to navigate seamlessly across these separate elements as if they were one cohesive editable element. F ...

Components from Bower are currently not available

Trying to automate the injection of bower components into my HTML using grunt-wiredep. It seems simple enough, but I'm having trouble setting the correct path to the bower directory when running localhost. Currently, I'm receiving this error: ht ...

What could be causing the unexpected behavior of nth-child?

I'm trying to position an image with the class photo, but unfortunately, the nth-child selector is not having any effect on that particular element. I have searched for various solutions, but none seem to be working! .container { height: 100vh; ...

What is the best way to align the navbar items in the center?

Is there a way to center the navigation bar elements using Bootstrap? HTML <body> <nav class="navbar navbar-inverse navbar-fixed-top " role="navigation"> <div> <ul class="nav navbar-nav"> ...

What is the best way to incorporate content just out of view below the parallax section that becomes visible as you scroll?

Check out this amazing parallax effect: https://codepen.io/samdbeckham/pen/OPXPNp <div class="parallax"> <div class="parallax__layer parallax__layer__0"> <img src="https://github.com/samdbeckham/blog/blo ...

Tips for organizing checkboxes in rows horizontally

My question is related to this issue I am trying to arrange my checkboxes in 4 columns horizontally <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta charset="utf-8"> ...

Retrieving data from an HTML dropdown menu in a Django views.py file

I'm new to working with Django and I could really use some guidance. I'm trying to retrieve the values selected by users from the select options in a form, and then use those values in my views.py file. So far, I haven't had much success wit ...

What could be causing my custom cursor to malfunction?

I've been attempting to customize the cursor image, but despite following all provided instructions, it's still not working: CSS: body, html { margin: 0px; padding: 0px; border: 1px solid red; cursor: url(images/rsz_red_crosshair.gi ...