Experiencing a problem with adjusting the layout on a backdrop picture

https://i.sstatic.net/s6eD5.png

Encountering issues depicted in the image while attempting to shift the form on the background image. Problems include the inability to change the width of textboxes, dropdown lists, and buttons. Below are the CSS and registration.html code snippets for review:

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333;
  justify-content: center;
  align-items: center;
  display: flex;
}

li {
  float: left;
  color: white;
  font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
  font-size: 15px;
  font-weight: bold;
}

li a {
  display: inline-block;
  color: white;
  padding: 14px 16px;
  text-decoration: none;
  font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
  font-size: 15px;
  font-weight: bold;
  letter-spacing: 3px;
}

li a:hover {
  background-color: #b0b0b0;
}

#logo {
  width: 200px;
  height: 200px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}


/* register.html & feedback.html */


/* Width remains constant after form relocation to top left */

input[type=text],
select {
  width: 21%;
  padding: 12px 20px;
  margin: 8px 0;
  box-sizing: border-box;
}

#feedbkdetails {
  width: 25%;
  padding: 12px 20px;
  margin: 8px 0;
  box-sizing: border-box;
}


/* Width remains constant after form relocation to top left */

input[type=number] {
  width: 21%;
  padding: 12px 20px;
  margin: 8px 0;
  box-sizing: border-box;
}


/* Width remains constant after form relocation to top left */

input[type=button] {
  width: 20%;
  background-color: #111;
  color: white;
  padding: 14px 20px;
  margin: 8px 0;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

input[type=button]:hover,
input[type=submit]:hover {
  background-color: #333;
}


/* Container holding the image and text */

.container {
  position: relative;
  text-align: left;
  color: black;
}


/* Top left text - suitable for text only, not forms */

.top-left {
  position: absolute;
  top: 8px;
  left: 16px;
}


/* CSS code for background image */

.bg-img {
  opacity: 0.5;
  width: 100%;
  height: 100%;
  background-repeat: no-repeat;
  display: block;
  position: relative;
  background-position: 0 500px;
}
<!DOCTYPE html>
<html>

<head>


  <link rel="stylesheet" type="text/css" href="../css/Ex6.css">

  <img src="https://cdn.iconscout.com/icon/premium/png-256-thumb/handstand-pose-1419568-1199014.png" id="logo">


</head>

<body>


  <ul>
    <li><a href="home.html">Home</a></li>
    <li><a href="register.html">Register</a></li>
    <li><a href="feedback.html">Feedback</a></li>
  </ul>

  <div class="container">

    <img src='https://image.shutterstock.com/image-photo/close-man-holding-weight-gym-600w-569605795.jpg' class='bg-img'>
    <!-- Encountering issue shifting the form here -->
    <div class="top-left">
      <h2> Registration </h2>

      <form action>
        <label for="name">Name :</label> <br>
        <input type="text" name="name" value="Enter your name"></input>
        <br>
        <label for="age">Age :</label> <br>
        <input type="number" name="age" min="1"></input>
        <br>
        <label for="gender">Gender :</label> <br>
        <input type="radio" name="gender" value="male"> Male<br>
        <input type="radio" name="gender" value="female"> Female<br>
        <br>
        <label for="membertype">Types of membership :</label> <br>

        <select name="type">
          <option value="OneYr">1 Year</option>
          <option value="FiveYr" selected>5 Years</option>
          <option value="LifeTime">Life Time</option>
        </select>

        <br>
        <br/>

        <label for="interests">Interests :</label>
        <br>
        <input type="checkbox" name="interest" value="Bike"> Travel<br>
        <input type="checkbox" name="interest" value="Food"> Food<br>
        <input type="checkbox" name="interest" value="Shopping"> Shopping<br>
        <input type="checkbox" name="interest" value="Cars"> Cars<br>
        </br>

        <input type="button" name="submit" value="Submit">
      </form>

    </div>


  </div>



</body>

</html>

Answer №1

Avoid using the img tag for background images. Instead, apply the CSS property

background-image: url(../img/gym.jpg);
to the container/div where you want the background image to appear. Adding an image tag in HTML will create an extra element and require additional styling to position it correctly on top of other elements. To avoid this, set the image background using CSS only. Simply update your code by removing the image tag from the HTML and placing the background image styling in the CSS.

.top-left {
  background-image:url(../img/gym.jpg);
}

Answer №2

When you want to use an image as a background, it's best to utilize the background-image CSS property instead of the img tag.

Take this code snippet for example: here

    .header {
  background-image: url("https://image.shutterstock.com/image-photo/close-man-holding-weight-gym-600w-569605795.jpg");
  background-color: #000000;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center center;
  position: relative;
  
  padding-top: 30px;
  padding-bottom: 135px;
  
  min-width: 1200px;
  height: 100vh;
}

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

How to align text to the right in the selection box list on Chrome for Android

My website includes an Arabic version. When viewing the site on mobile, the menu is displayed as a select box list. Due to the right-to-left (RTL) nature of Arabic text, I need the text within the select box to be aligned to the right. I attempted to add C ...

Please select the links located beneath the see-through triangular or polygonal shapes

Review the code snippet provided at the following link: http://jsfiddle.net/q8Ycz <div style="background-color: red; width: 200px;" onclick="alert('behind')"> <div><a href="test">test test test test test test test test test ...

After refreshing the page, Google Chrome finally displays the CSS styles correctly

I'm currently working on a JavaScript script to showcase images on a webpage. These images are loaded using an AJAX request and a CSS style is directly applied using jQuery. The script functions correctly on Firefox, Opera, and IE, but Google Chrome i ...

Using Jquery to dynamically add or remove a class based on scrolling behavior

Can someone help me with identifying the position of an element so that when the user scrolls to it and it appears on the screen, an icon can be highlighted? Currently, the script I am using adds the class too early, closer to the bottom of the block. I w ...

Detecting Specific Web Browsers on My Website: What's the Best Approach?

My website is experiencing compatibility issues with certain browsers, such as Firefox. I want to display a message when users visit the webpage using an unsupported browser, similar to how http://species-in-pieces.com shows a notification saying "Works ...

The battle between DataBind and control property settings

When considering these two methods: <asp:Label ID="Label1" runat="server"><%# DateTime.Now %></asp:Label> and Label1.Text = DateTime.Now.ToString(); Which approach do you prefer and what is your reasoning behind it? ...

How can you hide all siblings following a button-wrapper and then bring them back into view by clicking on that same button?

On my webpage, I have implemented two buttons - "read more" and "read less", using a Page Builder in WordPress. The goal is to hide all elements on the page after the "Read More" button upon loading. When the button is clicked, the "Read More" button shoul ...

Tips for eliminating excess white space in mobile view using css/bootstrap

I have successfully replicated the screenshot below using CSS/Bootstrap to ensure it looks consistent on both mobile and desktop view. https://i.sstatic.net/NS4yE.png For the upper portion of the screen-shot, I have created a fiddle which includes a sear ...

Is there a way to shift this modal to the right?

I am facing an issue with aligning a button modal to the right side. I attempted using bootstrap classes like : float:right, mt:20 Unfortunately, these did not have the desired effect. Below is my code snippet: <b-modal ref="my-modal" hide-fo ...

Condense a lineup of names into only two rows

I have a challenge where I need to showcase a list of names separated by commas, pulled from an array in my React component. The HTML output should appear as follows: <div> <span>Liza</span>, <span>Eric</span>, <span>Mic ...

Easy Peasy CSS Placement

Struggling with CSS and in desperate need of assistance. I've provided my code attempts along with pictures showing what I currently have versus the desired outcome. HTML <div class="thumbposter"><img src="http://tipmypicks.com/cssmovie ...

PushSharp powering the cutting-edge HTML5 mobile app

I am currently following an article that covers the process of configuring and sending Apple Push Notifications using PushSharp. We have successfully completed steps 1 to 20. However, I am facing issues with step 21 and step 22 of the mentioned article as ...

Browsing through tabs to locate specific text

Currently, I am developing a feature for a Chrome extension and I could use some assistance in debugging. The feature involves retrieving a user's input as a string from a text box on popup.html and then scanning through all the open tabs in the curr ...

Unable to locate web element using Selenium in C#

Here is the HTML code I am currently using: <div class="modal-footer"> <button class="btn btn-primary" type="button" value="Show Alert" ng-click="questions.getIrMessage()" data-dismiss="modal">Confirm</button> <button class ...

Ways to style CSS for inactive checkboxes?

How can I easily change the CSS for disabled checkboxes in a grid to make them more visible for users? Technologies I prefer to use, ranked from most preferred to least: CSS JavaScript jQuery Other ...

Has jQuery UI Accordion taken over the design of unordered lists?

I'm having trouble with my website's navigation styling getting messed up by the jQuery accordion. The unordered list inside the .accordion div is overflowing and losing its CSS styling. I've tried adding clearStyle true and autoHeight false ...

Triangles positioned on the edges of a division element

I am attempting to create a DIV with angled corners, as depicted in the image below: https://i.sstatic.net/1a9LY.png So far, I have successfully implemented the top right corner using a tutorial. Here is the code snippet that accomplishes this: .lifeatb ...

Ways to effectively hide one window or pop-up upon clicking another

I am working on creating an interactive website for my close circle of friends and family. One of the key features is to have a button that displays their biography when clicked. What I'm aiming for is that when a different bio is selected, the previo ...

Will the bootstrap carousel continue running in the background even if I hide it?

Currently, I have incorporated the twitter bootstrap carousel into my website with the following code: <div id="slider" class="carousel slide"> <!-- Wrapper for slides --> <div class="caro ...

A guide on dynamically altering text upon hovering over an element using Vue.js

On my website, I have the following HTML code: <div class="greetings"> <img @mouseover="hover='A'" @mouseleave="hover=''" src="a.png" alt="A" /> <img @mouseover="hover='B'" @mouseleave="hover=''" ...