Creating a web page with a responsive design that features HTML elements positioned absolutely within a relative position

My goal is to create an HTML page with two colors, a resizable image in the center, and positioned text on top.

I have achieved this, but the issue arises when I resize the window - the image resizes correctly, but the text div loses its position.

.main {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 100%;
  margin: auto;
  border-radius: 0;
  background: linear-gradient(to bottom, #f1b900 0%, #f1b900 50%, #000000 50%, #272660 50%, #272660 100%);
  /* W3C */
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  -moz-box-shadow: -3px 0 6px #4a5562;
  -webkit-box-shadow: -3px 0 6px #4a5562;
  box-shadow: -3px 0 6px #4a5562;
  -moz-transition: all 300ms;
  -webkit-transition: all 300ms;
  width: 100%;
  transition: all 300ms;
  height: 100%;
}
.folderimg {
  box-sizing: border-box;
  background: url("folder.png") center center no-repeat;
  background-size: contain;
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 75%;
  height: 75%;
  z-index: -1;
}
.foldername {
  -webkit-transform: rotate(-5deg);
  -moz-transform: rotate(-55eg);
  -ms-transform: rotate(-5deg);
  -o-transform: rotate(-5deg);
  filter: progid: DXImageTransform.Microsoft.BasicImage(rotation=3);
  font-size: 4vmin;
  position: absolute;
  margin-top: 5%;
  margin-left: 12%;
}
<div class="main">
  <div class="folderimg">
    <div class="foldername">Test Username</div>
  </div>
</div>

jsfiddle

Any assistance would be greatly appreciated...

Answer №1

Instead of using background-image, try utilizing the img tag to set the size of the container tag.

HTML

<div class="main">
  <div class="folder">
    <img src="https://s22.postimg.org/qi3kmv39d/folder.png">
    <div class="foldername">Test Username</div>
  </div>
</div>

CSS

.main {
  /*...*/
  display: flex;
  align-items: center;
}
.folder {
  position: relative;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
}
.folder img {
  display: block;
  height: auto;
  width: auto;
  max-width: 50vw;
  max-height: 50vh;
}
.foldername {
  position: absolute;
  top: 5%;
  left: 5%;
  -webkit-transform: rotate(-5deg);
  -moz-transform: rotate(-55eg);
  -ms-transform: rotate(-5deg);
  -o-transform: rotate(-5deg);
  filter: progid: DXImageTransform.Microsoft.BasicImage(rotation=3);
  font-size: 3vmin;
}

Give it a try:

http://jsfiddle.net/w1om0h0o/2/

I hope this solution proves helpful.

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

Tips for configuring the tooltip feature in Bootstrap Select plugin

I've been struggling to set the tooltip for a bootstrap select control, but I haven't been able to figure it out yet. In my situation, I have a select control without a label (due to the design of the page). So, when a user hovers over a selecte ...

What is the correct way to write this unusual '<a>' tag markup using Pug language?

For a list of additional features and functionalities, click here. I'm attempting to write the above in Pug format. I've tried translating it directly from HTML, but it's not displaying correctly. Below is my attempt: li For more features ...

What is the process for creating a see-through border with CSS?

I am attempting to create a design like this for a client with a blog. They are interested in having a semi-transparent border. I understand that it can be achieved by making it a background, but I am struggling to figure out the logic/code for implementi ...

What can be done to reduce the lag time in the Web Speech API?

Anyone else experiencing a delay when using the Web Speech API on their web page? I find that it can take 3-5 seconds to return a result, which is quite slow. Any solutions or tips for speeding up this process? Here's the basic setup I have so far - ...

Save the outcomes of the response in variables

I've been working on incorporating newsapi.org's API function into my website to display headlines. The function works smoothly when tested in the Chrome console, but I'm struggling with accessing the results within the array it returns. Her ...

How can I conceal the upload button and still display the names of the files?

I created a user-friendly drag and drop zone for uploading multiple files. Users can simply drag their files into the designated drop area and see the file names displayed there. However, I encountered an issue where hiding the standard "Choose file" butto ...

I am searching for a way to apply a conditional class to the chosen element in react, as the toggle method does not

I'm working on customizing a dropdown menu and I want to add a functionality where if a parent li menu has an arrow class before the ul element, then clicking on that parent li menu will add a class called showMenu only to that specific sub-menu. Her ...

Difficulty with font rendering across different web browsers such as Firefox, Chrome, and Opera

Visit the following website: I have implemented font-face on my site: @font-face { font-family: 'SegoeUI'; src: url('{site_url}themes/site_themes/agile_records/fonts/segoeui.eot?') format('eot'), url(' ...

Tips for using JavaScript to style an array items individually

I have currently placed the entire array within a single div, but I would like to be able to display each element of the array separately so that I can style "date", "title", and "text" individually. This is my JSON structure: [ { "date": "Example ...

Why isn't the DIV I created in JavaScript appearing when the page loads?

I've been struggling to get the DIV generated by the Javascript code, particularly in the function parameter id within creatediv('xdiv', html, 100, 100, 10, 10) where id = 'xdiv'. <!DOCTYPE html> <html> <head> &l ...

What is the best method to substitute a comma and period with just a period in a textarea

Creating a text area with auto-replacing characters like straight quotes, double dashes to em dash, and double spaces to single space was simple. However, I'm facing difficulty in adding a script for replacing certain characters: word . as word. wor ...

Is there a way to make a div appear on the following line without relying on the clear:both property?

I am currently tackling a small portion of a complicated webpage where there are divs placed on the right side that I do not have direct control over. Therefore, when I attempt to use clear:both (as advised here) to push my div to the next line, it ends up ...

Every time I make a change to the code, Laravel's css/app.css file mysteriously vanishes from the mix-manifest.json

Whenever I make a change in my code, the line css/app.css in mix-manifest.json disappears. The only solution is to execute npm run watch or npm run dev, but the problem reoccurs each time I modify the code. Here is how my mix-manifest.json looks when eve ...

List of colors accepted in HTML and CSS

There are some color names that I am familiar with and use, such as 'white', 'blue', 'red'. Is there a comprehensive list of colors that can be used in HTML/CSS? ...

The switchView feature is currently malfunctioning and unable to access the content on the next page

For my application's admin panel design, I've divided my home into containers. The aim is to display details of clicked items in Images.html and Categories.html when a menu item in the 2nd container (also known as side bar) is clicked. However, m ...

Is there a method to determine the page location of a DOM element when the body has a relative position?

I came across an unusual bug that started popping up when I set the body as a relatively positioned element with a 39px margin (to accommodate a toolbar at the top of a page). Typically, when you refer to guides on calculating the position of a page eleme ...

Tips for aligning 2 columns perfectly in a 3 column layout

I am facing an issue with a grid section where the grid-template-column is set for 3 columns, but sometimes the content loaded dynamically only fills 2 columns. I am attempting to center the columns when there are only 2. Despite going through the grid CS ...

How to retrieve the background color for a horizontal rule in HTML

I currently have <hr style="margin:0; padding:0; background-color: #F7D25F" /> But for some reason, the color is not displaying in the rule. ...

Unusual behavior encountered while attempting to reset input text using AngularJS

I'm encountering an issue with what I assumed would be a straightforward scenario. Here is the form in question: <form class="form-inline" role="form"> <div class="form-group"> <input type="text" ng-model="customerInput" size="80 ...

Table lines that are indented

I am currently in the process of transforming a standard HTML table into an indented version like this: Is there a way to hide the initial part of the border so that it aligns with the start of the text, even if I can't do it directly in HTML? ...