In responsive web design, positioning a div at a specific point in the background is essential for displaying content effectively

I'm working on a responsive website and facing an issue with displaying a div in the background at a specific point. Every time I resize the browser, the div ends up moving to a different random location. Check out this fiddle (couldn't attach the background image in the fiddle) Background Image: blue background with a gray stamp. Here's the code snippet:

<!DOCTYPE HTML>
<html>
<head>
    <link href="jsfiddle.css" rel="stylesheet" type="text/css" />
    <style>
        body{margin:0 auto;padding:0;font: 0.8em Arial,sans-serif;}
       .jsfiddle {
          float:left;
          display:block;
          background-image: url(Images/jsfiddle.jpg); 
          width:45%; 
          height:240px; 
          z-index:1; }
         .con1{
           float:right;
           padding:6% 2% 0 0;}
         .con1 a{
           text-decoration:none;
           font-weight:bold;
           color:#1f5198; 
           padding-top:1%;}
    </style>
</head>

<body>
    <div class="jsfiddle">
        <div class="con1"><a href="#">Click here for <br> information on 
          <br> CEO<br> Conference <br> October 9-10 </a>
        </div>
    </div>                    
</body>
</html>

Answer №1

To achieve the desired layout, you can utilize position:absolute on the .con1 element and then adjust its transformation by subtracting a percentage of its position to accommodate for the width and height. Additionally, make sure to add position:relative; to the .jsfiddle element so that .con1 is positioned relative to it.

body{
  margin:0 auto;
  padding:0;
  font: 0.8em Arial,sans-serif;
 }

.jsfiddle {
  position:relative;
  float:left;
  display:block;
  background-size:cover;
  background-position:center center;
  background-image: url(http://www.placecage.com/c/460/300); 
  width:45%; 
  height:240px; 
  z-index:1; 
}
.con1 {
  position:absolute;
  right:6%;
  top:10%;
  transform:translate(-10%, -2%);
  background:#fff;
}
.con1 a{
  text-decoration:none;
  font-weight:bold;
  color:#1f5198; 
  padding-top:1%;
}
<div class="jsfiddle">
  <div class="con1"><a href="#">Click here for <br> information on <br> CEO<br> Conference <br> October 9-10 </a>
  </div>
</div>

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

Two objects precisely located in the same spot yet not visible simultaneously

There are two elements here. One is a transparent button, and the other is an image positioned behind it. The background property didn't work for me, so I attempted different variations without success: .top-container > button { background-ima ...

The contents on the table are surpassing the card

Hello, I am encountering an issue with the table contents exceeding in size. You can see a screenshot of the problem https://i.sstatic.net/YDYoP.png Interestingly, when I un-collapse the sidebar, the view is perfectly fine. Here is a screenshot for refere ...

What is the best way to display images one by one from a map using a random fade effect?

I am in the process of creating a logo wall for a website. I successfully managed to display them randomly using a map, but now I want to make them appear one by one in a random order (for example: image 1, image 6, image 3, ...) and keep them visible once ...

Unable to properly align divs vertically

Having trouble getting some divs to align properly, whether they are in an accordion or not. The current layout is not what I want: My goal is to have them vertically aligned at the top, despite varying lengths. Any help would be appreciated. I attempted ...

Difficulty Encountered when Using Colorbox in Internet Explorer (all iterations)

I've been struggling to get Colorbox working properly on this particular page, even after spending more time than anticipated. The link to the page has been removed for privacy reasons. There's a Colorbox test link at the bottom right corner tha ...

Please include text beneath the input group addon class

Hey everyone, I'm facing some issues with my layout. Whenever the input fields are empty or null, I encounter errors. I want to ensure that the input text and input group addon have equal heights. Also, upon clicking the submit button, I use jquery/aj ...

Implementing a Scroll-down Functionality for Drop-down Menu Choices with the Power of CSS and HTML

My select menu has too many options to fit on the page. How can I implement a scrollable menu within the select box when it runs out of space? <form> <ul> <li id="snow_filter"> <label>Enter Resort&l ...

Adding a prefix and categorizing all items

When crafting HTML templates, my approach is to prefix every class and id. This method not only enhances the readability of the markup but also simplifies the styling process. As an illustration, if I were to create a template named MyTemplate, I would pr ...

What could be causing the disappearance of the value I'm trying to add to an unordered list immediately after I add it?

Is there a way to transfer the content of a "text box" to an unordered list when the user presses the "Enter" key? This is the HTML structure: <input type="text" name="InputUPC" id="InputUPC" /> <ul id="CandidateUPCs" name="CandidateUPCs" class= ...

"Creating Interactive Slider Bullets: A Guide to Linking them to Their Respective

I can't seem to figure out how to connect my slider bullets to my slider slides. I want bullet 1 to correspond to slide 1, bullet 2 to slide 2, and so on. It should be a simple task, but I'm struggling to make it work. I have set up a basic reset ...

Combining left-aligned and centered elements within a grid using flexbox

Looking to create a fluid responsive grid layout using flexbox, without the need for media queries. The number of elements in the grid can vary and each item should have a fixed, equal width with left alignment. The entire group should have equal left and ...

When the button switches to an ASP Button, the CSS after gets removed

Query: Is there a way to maintain the functionality of the 'after' part of the code when switching from an HTML button to an ASP button? I am experiencing issues with it dropping. Issue: After changing <button to <asp:button, the after e ...

Utilizing event delegation for JavaScript addEventListener across multiple elements

How can I use event delegation with addEventListener on multiple elements? I want to trigger a click event on .node, including dynamically added elements. The code I have tried so far gives different results when clicking on .title, .image, or .subtitle. ...

Issues with Google Fonts displaying poorly on Chrome

While working on my project, I've encountered an issue with the rendering of Source Sans Pro from Google Fonts in Chrome. Sometimes the font completely breaks, and unfortunately, I haven't been able to pinpoint when or why this occurs. At times, ...

Stop divs from wrapping without introducing default scrolling

I'm a bit confused about something: on the website for the Polymer Project, they have tabs that can scroll horizontally if there are too many. I want to create a similar effect, but I'm struggling to find a way to prevent the tab <div> elem ...

Is there a way to customize the navbar layout so that link 1 is aligned to the right side, link 2 is centered, and link 3 is positioned on the right?

I attempted to utilize the flex property and justify content, but unfortunately that did not yield the desired result. I experimented with the code provided below. The goal is to create a website layout with a logo at the top and a navigation bar directly ...

CSS code completion in PhpStorm is not functioning properly for Twig extended templates

Currently, I am working with PhpStorm 2016.1 and facing an issue with file autocomplete. The scenario is as follows: @mycss .style {color : red} @base.html.twig [...] <link rel="stylesheet" href="/vendor/mycss.css" /> <!--HERE AUTOCOMPLETE OF s ...

Align an image in the center both vertically and horizontally, with a line of text placed directly underneath

I'm currently designing a landing page for one of my clients with their logo placed prominently in the center. Right below the logo, they want their catchy slogan to appear on page load with a fading effect. To achieve this, I have included the slogan ...

What is the best way to incorporate a minimum width and maximum width in CSS that add up to 100% when necessary?

Can anyone help me find CSS rules that can set a fixed width for an element (width: 500px) but also allow it to be responsive with max-width: 100% if the container is narrower than the element? I saw this example and it works perfectly: .elem { width: 60 ...

CSS: Select the final child within a parent element depending on the specific class assigned to the child element

Is there a way to change the text color of 5 to red? I've tried some solutions, but nothing seems to work. Any ideas on how to fix this issue? Please Note: This example is just a simplified version of the actual problem, so the structure and quantit ...