Adjustable fixed <h1> does not match background pattern dimensions

Having trouble positioning images and text on your website? When the screen size is minimized, the proportionality of the elements is lost. You've tried using an image for the text, which worked, but now you're struggling to do the same with actual text.

Thank you for any help you can provide. I've been stuck all day trying to figure this out!

 .title {
   width: 74.5%;
  }
 /*text image png
 .title.s1{
   position: absolute;
   margin-top: 36%;

 }
 /*text in h1*/

 h1.title.s1 {
  color: rgb(60, 255, 0);
  position: absolute;
  margin-top: 34.5%;
  margin-bottom: 0;
  text-align: center;
  display: inline;
}


   <div id="r_bg-img">
    <img src="/img/rokubun_background.png"  width="100%">
</div>
<div class="content">
    
    <img src="/img/title1.png" class="title s1" >

    <h1 class="title s1">The premise</h1>

</div>

Check out this link for the output - the gray text is added as an img, the green text is a , and below those elements, the background titles are orange.

Answer №1

To ensure your content is proportionate, you can utilize styles like the ones demonstrated below. Utilizing the padding-top property as a percentage allows for creating spacing between elements such as headers and images.

Below is an example that showcases how to properly apply these styles to your content. Establishing outer and inner containers makes it easier to organize components like headers and images.

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>


.container {
   background-color: red;
   position: relative;
   width: 100%;
   height:100%;/* 1:1 Aspect Ratio */
}

.container .outer {
    width: 100%;
    padding-top: 5%; /* defines aspect ratio */
    position: relative;
}
.container .outer .inner {
    text-align:center;
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

img {
    display: block;
    width: 50%;
    height: 50%;
    padding: 0% 25%;
}

 h1 {
    margin:auto;
  color: rgb(60, 255, 0);
  text-align: center;
}

</style>
</head>
<body>


<div class="container">
    <div class="outer">
        <h1 class="inner">Your content</h1>
    </div>
    <div class="outer">
        <img src ="https://www.pngmart.com/files/13/Tetris-PNG-Free-Download.png">
    </div>
    <div class="outer">
        <h1 class="inner">Your content</h1>
    </div>
    <div class="outer">
        <img src ="https://www.pngmart.com/files/13/Tetris-PNG-Free-Download.png">
    </div>
</div>

</body>
</html>

You can refer to this guide for more insights https://wellcaffeinated.net/articles/2012/12/10/very-simple-css-only-proportional-resizing-of-elements#:~:text=For%20proportional%20resizing%20purposes%2C%20it,the%20aspect%20ratio%20you%20need.&text=And%20that's%20it!

This should provide the guidance you need to achieve your desired layout effectively.

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

Is it practical to extract the page type/name from the CSS of the selected tab?

My website has multiple tabs on a single page and I want to integrate Google Analytics code. However, since all the tabs are part of the same page, I need a way to track which tab the user is interacting with. Would using CSS to check for the selected tab ...

Implement a JavaScript function that toggles the visibility of a div based on changes to an anchor tag

My objective is to have the lds-roller div only displayed when the text within the anchor tag with the ID of searchFor is equal to _. This change in text should occur with an HTTP response. <div class="lds-roller"><div></div><div> ...

The usage of an import statement is not permissible outside of a module

Having some trouble using the mathjs library to calculate complex solutions for the quadratic equation. No matter how I try to import the library into my code, I keep encountering errors. Initially, I attempted this method: At the top of my root.js file, ...

Creating a universal function to handle setTimeout and setInterval globally, inclusive of clearTimeout and clearInterval for all functions

Is it possible to create a universal setTimeout and setInterval function with corresponding clearTimeout and clearInterval for all functions while passing values to them? The situation is as follows: 1. More than 8 functions utilizing setInterval for act ...

When fetching data from a parse object, JavaScript displayed [object, Object] as the result

When trying to access information from my parse data, I am able to display user table data on my document without any issues. However, when I attempt to query another object and insert it into an id element using jQuery with functions like text();, html(); ...

Transform a cropped portrait image into a resized landscape cover using CSS

Is there a way to crop the middle part of an image and turn it into a landscape cover background using HTML and CSS? The goal is to achieve a responsive background like the one shown below: pic The background should be 100% width and about 400-500px in h ...

What is the best way to adjust the canvas size within a list item?

I have successfully created a 3D model with Zdog that dynamically resizes based on the screen size. The model includes a dome and brim, which rotate smoothly as intended. Here is the code snippet: const TAU = Zdog.TAU; let hat = new Zdog.Illustration({ ...

The color of hyperlinks in firefox varies based on the specific URL being visited

I am a beginner in the world of html and css. I have two links placed consecutively. In my css file, I have defined classes for a:link and a:hover. However, I noticed that the second link is displaying a purple color instead of silver. Both links correctly ...

Customize the color of a Bootstrap btn-group

Is there a way to modify the background color of the active or selected button within a button group? <div class="btn-group" role="group" aria-label="Basic radio toggle button group"> <input type="radio" c ...

Steps to Show an Image When Hovering and Clicking on the Relevant Div

CSS: .imgECheck { position: absolute; top: 0; right: 5px; width: 15px; height: 15px; display: none; } .imgFCheck { position: absolute; top: 0; right: 5px; width: 15px; height: 15px; display: none; } Is ther ...

Struggling with determining the perfect transition speed for the sidemenu display

I'm a newcomer to web development and facing an issue with setting the transition speed for opening and closing this side menu. Despite adding transitions in the CSS and specifying duration in the Javascript, the menu continues to open instantly. I di ...

The JavaScript file is functioning properly when loaded locally, but encounters issues when loaded from the server

My Android webview app is giving me some trouble. I recently moved a JavaScript file online so that I could easily make updates that would immediately affect the app without requiring an update. However, when I try to load the script from the server where ...

Is there a way to update the input box value with a variable using jquery?

I am currently facing an issue with changing the value attribute of an input box in a form using jquery. Although I am able to change the value, it does not reflect in the outer html. Below is my current code snippet: $("a").click(function(event) { va ...

Issues with fonts in Google Chrome Version 32.0.1700.76 m

After recently updating my Google Chrome browser, I noticed that some of the fonts are not displaying correctly. Interestingly, they appear fine on other browsers, but the issue only seems to occur in Chrome v32.0.17...76 m. The fonts I used were "Open Sa ...

Selecting the incorrect label while hovering over a checkbox

I am using Bootstrap and encountering an issue with displaying checkboxes after clicking on an accordion element. While the first checkbox is displayed correctly, the checkboxes inside the accordion do not appear as expected. It is confusing to me why thi ...

Replacing menu styling with JavaScript using C#

I'm currently working on a C# project to develop a smartphone-friendly website for motorists to easily pay their parking fees. However, I'm facing some challenges with the menu design. My goal is to have a white menu with black text, where the cu ...

Customizing Bootstrap Styles in Angular: How to Override Specific Classes

Looking to customize an HTML element <div [style.color]="themeService.backgroundColor" class="col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1 col-lg-10 col-lg-offset-1"> <ul class="pagination" id="pag-bar"> <l ...

Utilizing jQuery time intervals within a jQuery click event: A step-by-step guide

For my dropdown menu project, I am facing an issue where the menu bar is not reappearing after collapsing the dropdown. It seems that the jQuery function responsible for toggling classes within a time interval is not executing properly. Specifically, the " ...

Is there a way to apply a unique style or design to the initial post in a set of data?

I'm working with a data collection that consists of 7 single posts. I want to apply a different design to the first post, but keep the rest uniform. Is it possible to achieve this using only one Laravel Eloquent query instead of separate ones for the ...

Modifying the label focus does not alter the CSS style

I'm struggling with a simple form where I want to highlight the focused labels by changing their background colors. However, the jquery code doesn't seem to be working as expected. Despite no errors showing up in the console, the functionality is ...