I am having trouble placing the button within the image

Essentially, my goal is to place the button within the image and ensure it remains in its position when transitioning to mobile mode or adjusting window size.

This is the desired outcome:

https://example.com/image

https://example.com/button-image

.img-wrapper {
  position: relative;
}

.img-responsive {
  max-width: 100%;
  height: auto;
  margin-top: 180px;
  margin-left: 360px;
}

a.btn {
  display: inline-block;
  padding: 0.2em 1.45em;
  margin: 0.1em;
  border: 0.15em solid #CCCCCC;
  box-sizing: border-box;
  text-decoration: none;
  font-family: 'Segoe UI', 'Roboto', sans-serif;
  font-weight: 400;
  color: #000000;
  background-color: #ffc966;
  text-align: center;
  position: relative;
}

a.btn:hover {
  border-color: #7a7a7a;
}

a.btn:active {
  background-color: #999999;
}

@media all and (max-width:30em) {
  a.btn {
    display: block;
    margin: 0.2em auto;
  }
}
   

<h1>The leading VR/AR hardware supplier in Benelux</h1>

<div class="img-wrapper">
  <img class="img-responsive" src="vrgt.png">
</div>

<a href="#" class="btn">More Info</a>

Answer №1

(Oops! Accidentally clicked on the post button too soon)... Looks like there was no CSS for the image or H1 element in your code. I went ahead and added some CSS, including a max-width property for the image in both the main CSS and responsive (media) CSS. There are still some adjustments that could be made, but I recommend taking a closer look and customizing it to fit your specific requirements. It seems to be closer to what you're aiming for!

UPDATE: I suggest incorporating more media queries to cater to various screen resolutions since absolute positioning can be tricky on devices with different sizes. You can use tools like Screenfly to test how your layout appears on multiple screens. When setting heights, avoid using large pixel-based margins (e.g., 360px), as this might cause elements like buttons to not display correctly. Instead, consider using vertical height (vh) or percentages. The [calc function] and CSS centering techniques like margin : 0 auto or text-align:center; can also come in handy.

Good luck, and I hope this guidance proves helpful!

h1 {
  text-align: center;
  font-weight: bold;
  font-size: 1.8em;
}

img {
  max-width: 70%;
  max-height: 80%;
  margin: 10px 12%;
}

img-wrapper {
  display: inline-block;
  position: relative;
}

nav {
  margin: 0 auto;
}

nav ul {
  list-style-type: none;
  background-color: lightgrey;
  width:100%;

}

nav ul li {
  min-width:18%;
  display: inline-block;
  text-align: center;
  padding: 10px;
  margin:0 auto;
}

ul li a {
  padding: 10px 15px;
  text-decoration: none;
}


/*.img-responsive {
  /* margin-top: 100px;
  margin-left: 360px;
}*/

a.btn {
  display: inline-block;
  padding: 0.2em 1.45em;
  margin: 0.1em;
  border: 0.15em solid #CCCCCC;
  box-sizing: border-box;
  text-decoration: none;
  font-family: 'Segoe UI', 'Roboto', sans-serif;
  font-weight: 400;
  color: #000000;
  background-color: #ffc966;
  text-align: center;
  position: relative;
}

a.btn:hover {
  border-color: #7a7a7a;
}

a.btn:active {
  background-color: #999999;
}

@media all and (max-width:30em) {
  img {
    max-width: 400px;
  }
  a.btn {
    display: block;
    margin: 0.2em auto;
  }
}
<h1>De zakelijke VR/AR hardware leverancier van Benelux</h1>

<nav>
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Gallery</a></li>
    <li><a href="#">Contact</a></li>
  </ul>
</nav>

<div class="img-wrapper">
  <img class="img-responsive" src="https://gilsig.ca/wp-content/uploads/2015/10/12391435_192385974441516_971157875868647436_n.jpg-North-Shore-Mountains-Dec-2015.jpg">
</div>

<a href="#" class="btn">Meer Info</a>

Answer №2

The button should be positioned absolutely in relation to its first parent element.

a.btn {
    position: absolute;
    top: 50%;
    left: 50%;
}

.img-wrapper {
  position: relative;
}

a.btn {
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 0.2em 1.45em;
  margin: 0.1em;
  border: 0.15em solid #CCCCCC;
  box-sizing: border-box;
  text-decoration: none;
  font-family: 'Segoe UI', 'Roboto', sans-serif;
  font-weight: 400;
  color: #000000;
  background-color: #ffc966;
  text-align: center;
}

a.btn:hover {
  border-color: #7a7a7a;
}

a.btn:active {
  background-color: #999999;
}
<div class="img-wrapper">
  <img src="https://www.w3schools.com/css/img_5terre_wide.jpg" alt="Cinque Terre" width="1000" height="300">
</div>
<a href="#" class="btn">More Info</a>

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

Utilizing browser local storage in web development

Currently, I am in the midst of working on an e-commerce platform, a project that holds significant importance for me as it marks my debut into major projects. For the first time, I am delving into the realm of local storage to manage basket data such as q ...

Enhancing React-Admin with custom Material-UI theme overrides for targeted CSS selectors on a global scale

When working with React-Admin, I encountered a challenge in applying specific CSS code globally within my Material UI theme. As I set up my theme, I included the following lines in the overrides section: overrides: { "@global": { &quo ...

Is there a way to superimpose multiple PNGs and ensure that each one is clickable within its designated area?

I am looking to implement a interactive image system for dynamically generated content. The image includes a background image and various grey-scale mask images. Background Image: (source: goehler.dk) Masks: (source: goehler.dk) , (source: goe ...

Filter search results to display only posts

My website uses a custom Wordpress theme that has a search functionality. The issue I'm facing is that when I perform a search, it redirects me to the search.php page. However, instead of just displaying posts, it also shows pages and events from the ...

Issue encountered while trying to exhibit jpg image content from server side on html

I am attempting to display an image from server-side data using an Ajax call. The data stored on the server looks something like this: "ÿØÿàJFIFÿÛC4­¶¸UOHlʵcBò)3¹_È'I4~&éüÿ§Ú<ã©ã4>'Øù¿ÇÄmËCÈgÚsZ¥ë" Upo ...

Having trouble making `overflow: hidden` work correctly when using padding on an element with `height:

Looking for some coding help here. My aim is to create a customized select menu with a sleek animation effect. I initially decided to set the default height to 0 and use overflow: hidden, then switch it to auto when .active class is applied. But, I'm ...

Obtaining User Input in React JS within the Fetch Statement

I've written a code to fetch weather data from an API. Currently, the location is set to "chennai" in the link provided. I'd like to make this location user-dependent. How can I achieve this using React? import React,{useState,useEffect} from ...

Highlighting table rows on mouseover using CSS

I am trying to add a hover effect to my table rows, but when I apply the CSS styles for this behavior, the rows start wrapping. Here's a comparison of how the table rows look before and after applying the styles. You can see the wrapping issue in the ...

Extending the href value using jQuery at the end

Can someone help me with this link: <a id="Link" href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2745425453424b4b524940674e0a4355464e4909494253">[email protected]</a>?subject=I-Drain Bestellung& ...

Show the entire background photo

Below is the CSS code I am currently using within an inline style: <div class="home-hero" style="background-image: url(https://dummyimage.com/300); background-position: 100% center; background-repeat: no-repeat; background-size: cover; height: 100%; wi ...

Carousel-Owl, glide through two items simultaneously

I am currently in the process of developing a slider using the beta version of Owl-Carousel 2, but I am encountering several issues. My goal is to configure the owlCarousel to function as follows: It should scroll through 2 items at a time while displayin ...

Issue with external JavaScript file being unresponsive on mobile browser

Hello everyone, hope you're having a great afternoon or evening I've encountered an issue with mobile browsers like Chrome Mobile and Kiwi where the external js file is not visible in the html file. The script.js file looks like this: alert(&ap ...

The Node.js application is unable to locate the source file path

Currently, I am in the process of creating a simple quiz application. While working on this project, I encountered an issue with linking a JS file in an HTML template. Even though I have confirmed that the path is correct, every time I run my node app, the ...

Styling with Radial Gradients in CSS

Struggling to create a banner with a radial gradient background? I'm almost there, but my code isn't matching the design. Any assistance would be greatly appreciated as I can't seem to get the right colors and only part of the first circle i ...

Revamp the website's design

I am looking to revamp the color theme of my website with just a click of a button. Can someone provide me with a link to a reference website where I can get some inspiration? ...

Searching Text Boxes with Javascript: A Better Way to Handle Arrays

I'm struggling to implement a feature where users can search for authors in a database and be redirected to the corresponding HTML if found. Otherwise, it should display a message saying "No Author Found"... I need some assistance in getting this fun ...

What makes styling the iconic Browse button (file input) such a challenge?

Many people are curious about how to style a file input in an HTML form, as evidenced by the plethora of well-known techniques available. However, I am more interested in understanding why we encounter such technical limitations that seem so trivial and fr ...

Encountering a problem with the divLogoBlock element in the code snippet below

I am experiencing an issue with the code below. The divLogoBlock does not appear when I copy and paste the entire page into Outlook as a signature. I believe there may be a problem with the CSS. Can someone please assist me? <html lang="en"><he ...

CSS3 transition applied to a jQuery direction-aware hover effect

I'm encountering difficulties making direction-aware hover and css transitions function correctly. Specifically, I am attempting to create a grid of elements with front and back faces, and on hover, have a css transition that flips the element to disp ...

Displaying an additional section using hover effects in Bootstrap

I recently utilized Bootstrap to create pricing tables which can be viewed here: http://www.bootply.com/VyHsJBDoNc Is there a way for me to implement hover functionality on a span element (+ More Information!) that will display additional information as s ...