Placing an image beyond the boundaries of the design

Currently, I am in the process of creating a website that is 960px wide. One of my goals for this site is to have images on both sides of the header visible to those with larger screens.

However, maintaining the site at 960px width poses a challenge when it comes to ensuring that these additional side images do not affect the overall layout in the browser. While I have been successful in achieving this on the left side as demonstrated here:

Here is the code snippet:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body { margin: 0; padding: 0; border: 0; background-color:#096 }

img { border: 0; }

#main { 
    width:960px; 
    height:216px; 
    background-image:url(main.jpg);
    position:relative;
    top:0; margin: 0 auto;
}

#left {
    width:170px;
    height:216px;
    background-image:url(left.jpg);
    float:left;
    left:-170px;
    position:relative;
}

#right {
    width:170px;
    height:216px;
    background-image:url(right.jpg);
    float:right;
    left:170px;
    position:relative;
}
</style>

</head>

<body>

    <div id="main">
        <div id="left"></div>
        <div id="right"></div>
    </div>
</body>
</html>

When resizing the window to different widths, you'll notice that the right side image does not behave as expected compared to the left side. This can be seen here:

The only difference in the code is that the

<div id="right"></div>
section is missing from the latter example.

If you're curious about why this discrepancy exists between the left and right layouts, visit this link for more insights:

Why does the approach work smoothly for the left side but encounter issues on the right?

Answer №2

It would be more effective to merge the two images and set them as the background of the body. Here is an example:

HTML

<div id="main"></div>

CSS

body {
 margin: 0;
 padding: 0;
 background:#096 url(http://imgur.com/JHXDv.png) no-repeat top center; 
}

#main {
    width:960px;
    height:216px;
    background-image:url(http://www.wireframebox.com/test/sideimages/main.jpg);
    margin:0 auto;
}

View the result here http://jsfiddle.net/PVWzA/1/

Answer №3

For a website page to be 960px wide, adjust the width of the main image to 620px by subtracting 170 from both sides. This should resolve your problem.

Hope this helps!

Answer №4

To add an image in a larger div or image tag than your center div, insert it as a child of the center content div. Ensure that its positioning is absolute to remove it from the flow. By adding a negative margin, you can shift the image outside of the content div without affecting its position.

 #center div.top{
        width:1200px;
        height:170px;
        margin: 0px -170px;
        position:absolute;

        background:url("randombackground.png") no-repeat;
    }

The structure of the HTML will look something like this:

<div id="center">
<div class="top"></div>
Content content content
</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

Using PHP variables in JavaScript to access getElementById

I have multiple forms displayed on a single PHP page. They all follow a similar structure: <form id="test_form_1" action="test_submit.php" method="post" name="test_form"> <label>This is Question #1:</label> <p> &l ...

What is the process to design and implement this button using HTML and CSS?

I am in need of creating a button similar to the google button shown in the image, but I am struggling to position it correctly on the margin. Can someone please assist me with this? The google button is the specific type of button that I am aiming to rep ...

do not display bullet points

The bullets from the list-style type are not appearing. Despite the CSS code never declaring list-style-type: none, I have specifically declared list-style-type: disc for the section in question. I even checked with Firebug and other tools, and it is evide ...

Learn how to dynamically set the "selected" option in Vue based on object data

I've done some digging on SO but haven't found exactly what I need. So, here's the situation - I've got a sorting function in progress. I have an array of date ranges (PayPeriods) that I want to render into a select with option compone ...

Google Extension PHP Plugin

Is it feasible to integrate a PHP file into a Google Extension for Chrome? I've been exploring the idea of creating an extension and most resources only mention HTML, CSS, and JavaScript. Any guidance on using PHP in the extension would be highly valu ...

Issues arise when a questionnaire is duplicated

Currently, I am working on a questionnaire that involves the cloning feature in jQuery using .clone(). The questions are answered using checkboxes with options for yes or no. These checkboxes are placed within a table and controlled by the following script ...

Accessing and manipulating a intricate JSON structure within an Ionic 3 framework to seamlessly connect it to the user

I'm currently developing an app using Ionic 3. Within my project, I have a JSON object structured like this: { "player": { "username": "thelegend", "platform": "xbox", "stats": { "normal": { "shots ...

Is it possible to manually trigger a version change transaction in IndexedDB?

I have been working on a Chrome extension that uses the IndexedDB to store data client-side in an IDBObjectStore within an IDBDatabase. The data structure requires users to be able to modify the object store freely, such as adding new objects or modifying ...

Utilizing erb within a coffeescript file for modifying the background styling

Is there a way to change the background image of a div based on user selection from a dropdown menu? For instance, if the user picks "white" the background image becomes white, and for "red" it changes to red. I'm struggling with this in coffeescript ...

Textarea with integrated checkbox

Can checkboxes be incorporated within a textarea using basic HTML and CSS? I'm aware that this can be achieved with tables, but I'm curious if it's possible within a textarea itself. ...

Which takes longer to render: individually drawn images placed via absolute positioning, or one complete image?

I currently have a collection of "cards" on my website that are jpg images, but I am considering switching to an HTML/CSS solution. This change would involve placing numerous small icons on a background and adding stylish text on top. My concern is determ ...

What might be the reason for jQuery not functioning in Internet Explorer 11?

Working on developing a slideout menu for my website using jQuery. It functions perfectly in Chrome, but encountering issues in Internet Explorer (IE11). Extensive search hasn't provided a solution yet. Seeking assistance and any help would be highly ...

CSS magic: Text animation letter by letter

I have a <div> with text. <div> to be revealed on the page one character at a time:</p> <div>, the animation should stop and display the full text instantly.</p> In summary, I aim to replicate an effect commonly seen in Jap ...

CSS Background color only applies to the lower section of the page

I'm attempting to create a social media button using an anchor tag and a fontawesome icon. My goal is to have the entire background colored black with CSS, but my previous attempts only resulted in the bottom half turning black. https://i.sstatic.net ...

Issue with Material Design Lite input floating label not functioning properly post page navigation

I am currently developing a mobile hybrid application using Material Design Lite, but I have run into a small issue. When I add input field elements to my pages, the floating text and placeholder do not function properly. In my application, I am utilizing ...

Is there a way to include a textarea or text input in a table row and have it expand upon clicking or dragging, without increasing the row height?

I am looking for a way to allow a textarea to expand or grow when clicked or dragged, without affecting the height of the table row it is in. You can see an example of the issue on this CodePen: https://codepen.io/kerastensorflow/pen/PobaRvK?editors=1010 ...

Selecting the incorrect label while hovering over a checkbox

I am using Bootstrap and encountering an issue with displaying checkboxes after clicking on an accordion element. While the first checkbox is displayed correctly, the checkboxes inside the accordion do not appear as expected. It is confusing to me why thi ...

Split total based on checkboxes toggled with JavaScript

I'm facing a challenge. I have a total sum of donations collected, for example, 10€. Additionally, there are various NGOs that one can select to donate to. Individuals have the option to toggle on/off which NGO's they wish to contribute toward ...

Avoiding the selection of duplicate values

I am currently working on a project that involves a form containing multiple 'select' inputs, all offering the same set of options. My goal is to utilize jQuery in order to disable/hide an option in the other 'select' inputs if it has a ...

Can the "value" of an HTML form field rendered by Django be altered?

Essentially, I have a form that includes a radio select widget for the field named Queue. The choices available for the Queue are sourced from a model, which is accessed and defined within the views.py file. To display this form on my template, I am using ...