How do I make this element clear the image and appear centered on the page, above the background?

I am trying to position this text block in the center of the page on top of an image, rather than at the bottom. How can I achieve this?

Here is my code where I want the process section to be displayed in the middle of the page on top of the image.

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <link href="style/styles.css" type="text/css" rel="stylesheet">


</head>
<body>

        <h2 id="siteTitle">Westend</h2>
        <nav>
            <ul class="main_menu">
                <li><a href="index.php">Home</a></li>
                <li><a href="booking.php">Booking</a></li>
            </ul>
        </nav>

<div><img src="images/curtains.jpg" id="open"/> 
<div id="process">
<br>Hi <?php echo "'".$_SESSION['name']."'"; ?></br>
Your tickets have been booked for <?php echo "'".$_SESSION['production']."'";?>  
<br>Playing on <?php echo "'".$_SESSION['date']."'";?> at <?php echo "'".$_SESSION['time']."'";?> <br>
You are in <?php echo $_POST["zone"];?> in row <?php echo $_POST["row"];?><br>
The total cost is £<?php echo $_POST["quotation"];?><br>
Confirmation of your booking has been sent to: <?php echo "'".$_SESSION['email']."'"; ?><br>
Enjoy the show!
<br>
</div>




    <footer id="pageBottom">

        <p>&copy Westend 2015</p>
    </footer>




</body>
</html>

This is my CSS

#process {
    text-align: center;
    font-family: San-Serif;
    font-size: 20px;
    text-shadow: 1px 1px 0 #1a1a1a;
    background-color: #802000;
    width: 450px;
    height: 270px;
    margin-top: 25px;
    margin-bottom: 10px;
    margin-left: 750px;
    border: 1px solid white;
    padding-bottom:2px;
    box-shadow: 3px 4px 5px grey;
    clear: inherit;
}

Answer №1

To implement absolute positioning, you can use the following CSS code:

#process {
position: absolute;
top: calc(50% - 135px);
left: calc(50% - 225px); 
text-align: center;
font-family: San-Serif;
font-size: 20px;
text-shadow: 1px 1px 0 #1a1a1a;
background-color: #802000;
width: 450px;
height: 270px;
border: 1px solid white;
padding-bottom:2px;
box-shadow: 3px 4px 5px grey;
clear: inherit;
}

For a live example, check out this CodePen link. I hope this information proves helpful.

Answer №2

It seems like there might be a better solution to address your issue.

One suggestion could be adding a .process background-image with the property background-size set to contain.

You can then center the element .process by using position: absolute:

.process{
    background-image: url("../images/curtains.jpg");
    background-size: contain;
    background-position: center;
    position: absolute;
    width: 450px;
    height: 270px;
    top: 50%;
    left: 50%;
    margin-left: -225px;
    margin-top: -135px;
}

Answer №3

There are various methods you can utilize to achieve this effect. One effective approach is to remove your div from the normal page flow and position it absolutely. To center the element within the page, you will also need to adjust the positioning properties accordingly:

#process {
    position: absolute;
    width: 450px;
    height: 270px;
    top: 50%; /* distance from top border */
    left: 50%; /* distance from left border */
    margin-left: -225px; /* half the width */
    margin-top: -135px;  /* half the height */
}

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

Retrieving ng-repeat object in Angular

How can I retrieve the current object from an ng-repeat on ng-click without using $index? The $index method is giving me the wrong index due to my use of orderBy. Ideally, I would like to be able to click on the object (thumbnail) and have $scope.activePer ...

adjusting the header position for an HTML anchor

I'm in the process of improving the functionality of my anchor links. I have a fixed header at the top of my page, so when you click on an anchor link elsewhere on the page, it jumps to that position with the anchor aligned at the top, leaving the fix ...

What is the best way to extract duplicate HTML elements based on their class attribute?

I am attempting to parse an HTML file containing similar tags. My desired output is as follows: BTC - Bitcoin, BEP20(BSC), Bitcoin(Segwit) ETH - ERC20, BEP20(BSC), POLYGON, ARBITRUM, AURORA, MATISEVM USDT - OMNI,TRC20,ERC20,BEP20(BSC),HECO,POLYGON,FTM, ...

Repair the masthead background during overscroll

The Dilemma At the top of my webpage, I have a sleek masthead with a captivating background image that scrolls along with the page. However, there is an issue when users overscroll upwards, causing an undesirable white overflow to appear. To rectify this ...

The functionality of the Ajax code is taking an unusually long time

After running my Ajax code, it took a surprising 3 minutes and 15 seconds to load. What could be causing this delay? <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.j ...

Generating numerous variables simultaneously is a feature of SASS

Is it possible to utilize a SASS map in order to generate individual variables for each key-value pair? For instance, I aim to achieve the following: $heading: ( 1: 5rem, 2: 4.5rem, 3: 4rem, 4: 3.5rem, 5: 3rem, 6: ...

send data to a hyperlink

I need to pass a parameter to the href based on the first name in the list. The names are links to another page that I retrieve via an _id passed in the URL. The issue I am facing is that the id is not being passed to the URL, resulting in an error. How ...

Updating a JSON array by inserting a new object using AngularJS $http

I am attempting to include a fresh object in an existing JSON array. The JSON array is currently stored in the database. { "Id":4, "UserId":2336276, "Name":"Data", "Widgets":[ { "Id":1, "Description":"Test1", ...

Connect to a particular section of the webpage with additional top spacing

The navigation on this page is not transparent. Whenever I link to a specific part of the page, some text becomes hidden behind the navigation bar. This is illustrated in the image below: https://i.sstatic.net/h0ExX.png What I desire is a navigation bar l ...

Personalize a bootstrap theme specifically for the mobile interface

My current template, based on Bootstrap, displays a text along with a button and an image. Using a checkbox, you can choose whether the image appears to the right or left of the text. One issue I'm facing is that in the mobile view, the text and butt ...

Dropzone failing to verify the maximum file limit

I am currently using dropzone to upload files on my website. I have limited the number of files that can be uploaded to a maximum of six. The code works perfectly when uploading one image at a time, but if I select more than six images by holding down the ...

During DragAndDropToObject in Selenium IDE, the initial element in the list is overlooked

I have a webpage that is split into two datagrids. The left datagrid is structured like this: <ul class="left_dg"> <li> <ul></ul> </li> <li> <ul></ul> </li> <li&g ...

Is there a way to incorporate a JavaScript variable as the value for CSS width?

I created a scholarship donation progress bar that dynamically adjusts its width based on the amount donated. While I used CSS to handle the basic functionality, I am now trying to implement JavaScript for more advanced features. My goal is to calculate ...

What causes the modal to appear and then vanish suddenly?

I've created a simple modal code with minimal JS involved. When the button is clicked, the modal appears briefly, then the page refreshes and the modal disappears. I'm not sure what could be causing this issue. Any help would be appreciated! h ...

Is it possible to duplicate content from one div to another?

With over 90 divs, each containing an image or icon, I am looking for a way to display the clicked image in another div. I am not very familiar with JS yet, so I would appreciate a simple example using HTML5, Ajax, and js. EDIT: Just to clarify, the desti ...

How to Align Plotly Graphic Perfectly in Bootstrap Card

Here's my code snippet for creating a plotly visualization inside a boostrap card. I'm looking for the best way to make sure it appears centered within the card on all devices. <div class="col-sm-6"> <d ...

Clicking on a button within the parent element will enable you to remove the parent element multiple times with the use of VanillaJS

Within a ul element, each li contains multiple elements in the following structure: <ul> <li> <div> <p>some text </p> <button>delete</button> <div> </li> <li> ...

The execution of the selenium script is unreliable

Recently, I created a selenium script to automate certain manual checks on http:obsessory.com. The script utilizes a looping concept, such as mouse hovering over the Top menu and clicking on various submenus. However, during testing, I have encountered spo ...

The extensive magnetic scrolling functionality in Ionic 2 sets it apart from other frameworks

Hi everyone, I could really use some assistance! I've been working on developing an Ionic 2 App and my navigation setup is not too complex. I have a main menu where clicking on an item opens another menu with a submenu. From there, if I click on an i ...

Custom Map Markers - troubleshooting extraneous spacing in icon graphics (CSS/HTML)

For a Drupal site I'm working on, I decided to create custom map icons to replace the standard set in Leaflet maps. Using Photoshop, I meticulously crafted these icons and ensured that the final image was trimmed to perfection with no extra pixels at ...