Placing a button that is not visible on the screen

As I was designing a webpage for a new company, everything was perfect in the header except for the fact that we didn't have a logo yet. So, I decided to put a placeholder image in its place. Now that we finally have the actual logo and replaced the placeholder, the call to action button underneath has been unexpectedly pushed off screen. Despite there being countless tutorials on positioning available online, I find myself stuck and unable to resolve this issue!

<body>
<header>
   <nav>
       <div class="row">
            <ul class="main-nav">
                <li><a href="#">Home</a></li>
                <li><a href="#">Quote</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
       </div>
   </nav>
    <div class="hero-text-box">
       <img src="img/test.png" width="500px" height="500px" alt="test">
       <a class="btn" href="#">Get a Quick Quote</a>
    </div>
</header>

header {
background-image: url(img/hero2.jpg);
background-size: cover;
background-position: center;
height: 100vh;
}

.hero-text-box {
position: absolute;
width: 1140px;
top: 20%;
left: 60%;
}

Answer №1

When it comes to placing elements, there are various methods you can use. If you haven't specified where you want the button to be positioned, we'll assume you want it centered. One way to achieve this in a simple and backwards-compatible manner is:

.button { 
  position: absolute;
  left: 50%;
  width: 50px;
  margin-left: -25px;
}

The reason for using a negative margin is that when an element is positioned to the left, with top: 0 and left: 0 being at the top left of the element, setting left: 50% actually offsets the element by an extra 25 pixels from the center.

Ensure that the button element does not have any parent elements with a position attribute. If a parent element of the button has a position attribute, the button will be placed relative to that parent element. We hope this explanation helps, cheers!

Answer №2

This should get the job done.

.main-heading {
    position: relative;
    width: 80%;
    height:120%
    display: flex;
    justify-content: center;
    align-items: center;
    z-index:1;
    top: 10px;
    left:20px;
}

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 data from a dynamic identifier

When testing the sort order of search results, I encountered an issue with one specific search. The problem lies in the auto-generated ID for each row, which changes every time the search is performed. For example, I can use the following code snippet: s ...

The hyperlink for social media is not functioning properly within a list element

Having some trouble with the href-tags for social media on my contact page. Clicking on them doesn't seem to do anything. Any ideas on what might be causing this issue? html { height: 100%; box-sizing: border-box; background-color: #001725; ...

Sliding out menu using AngularJS

I have been attempting to create a slide out menu without success. My goal is for the text (home,users) to appear when the >> button is clicked. I seem to be stuck and can't figure out what I'm missing. This project also marks my initial ve ...

Having trouble getting JavaScript to select a stylesheet based on time?

I am attempting to implement two different styles based on the time of day. Here is the code I am using to select the CSS file depending on the current time: <script type="text/javascript"> function setTimedStylesheet() { var currentTim ...

Can AJAX Delete requests be executed without using jQuery?

Is it possible to use AJAX delete request without using jQuery? My JSON object at localhost:8000 appears like this: { "Students":[{"Name":"Kaushal","Roll_No":30,"Percentage":94.5}, {"Name":"Rohit","Roll_No":31,"Percentage":93.5}, {"Name":"Kumar ...

The logo on my header is being covered by the menu due to the CSS code

Check out my website at bee-barcelona.herokuapp.com I'm facing an issue where the menu overlaps with the logo when I resize the browser or view the webpage on a tablet. I want to fix this using CSS. What changes do I need to make to ensure that the e ...

Arrange flexbox containers side by side in a horizontal row

I am attempting to create two flexbox containers one after the other, utilizing a combination of classes to achieve this layout. While the flexbox is created successfully, I encounter an issue where the lower container goes below the upper one when scrolli ...

Best practices for managing a Media Stream in Node.js

One of the latest and most exciting features in modern browsers is HTMLMediaElement.captureStream(), which has recently been released in Chrome. Having grasped how it functions on the client side - allowing you to redirect the stream to other HTMLMediaEle ...

Ways to design siblings that are not currently being hovered over

Is there a way to achieve an effect where hovering over one list item causes all other list items to fade out? I'm searching for a method to style an element that is not being hovered, when one of its siblings is in the hovered state. I've trie ...

What is the best way to insert a space between the radio buttons in a RadioButtonList and the accompanying text?

After researching various solutions, none have seemed to work for me. In my ASPX page, I am utilizing Bootstrap to showcase a RadioButtonList with options for "Yes" and "No" like this: <div class="form-group my-3"> <label class=" ...

Retrieve a div element using Ajax from the result of an If statement

I need to extract a specific div from the data returned by an if statement that is formatted as HTML, and then display it within another div. I have been attempting to achieve this using the code below, but so far it has not been successful... Here is my ...

Expanding Image with HTML and CSS: A Guide

In the process of creating my website, I encountered an issue with the logo placement. I wanted the logo to be in the top left corner, similar to the one shown in this image. Initially, everything was working fine until I made some adjustments to move the ...

Discovering the point of exit for a mouse from an image

Visit this website to see the effect in action: I am curious about how the image scrolls into and out of the direction where the mouse enters and leaves. Can you explain how this is achieved? ...

Incorporate a smooth transition effect to a dynamically resizing div button

In my current setup, I have 3 buttons that can toggle between different visible divs. In the future, I may add more buttons to switch between additional divs. At the moment, the first div is active (display set to block), while all other divs are hidden ( ...

Creating a standalone Wordpress child theme with its own CSS

After creating a child theme based on the responsive i-transform theme from http://templatesnext.org/itrans/, I found myself continuously undoing the i-transform CSS, which is taking up a lot of my time. However, if I remove the entire parent stylesheet, t ...

Experiencing a 500 internal server error while running my Python script, struggling to identify the root cause

Here is a python script designed to open a .ssv file (space-separated vector) and create a survey page based on the file's contents. The .ssv file includes the survey name and the questions to be asked in the survey. As part of our project, each team ...

Is there a way to smoothly incorporate a new animation into a page, while ensuring that existing elements adjust to make room for it?

I am looking to smoothly fade and move a hidden element (display:none) within the page, shifting other elements to animate into their new positions as necessary. When I reveal the hidden element by changing it to "display:initial," it should seamlessly a ...

What is the process for dynamically populating a select dropdown based on the selection made in another select dropdown?

I need to dynamically populate the second select box based on the option selected in the first select box. Here's what I have tried so far, but it doesn't seem to be working as expected. HTML: <form id="step1"> <p> Creat ...

Strange height problem detected in embedded YouTube video

Currently, I have a page with an embedded YouTube video that is intended to be placed in a container with a variable width. When the video is outside of the container, the aspect ratio appears normal. However, once it is placed inside the container, the he ...

Adding dynamic HTML to the body in AngularJS based on URL alterations

I am currently developing a single-page application using Angular. I am trying to create a card stack made of divs, similar to this concept. https://i.stack.imgur.com/42M06.png The idea is that the app will have various URL links and a card should be app ...