Solving the enigma of CSS positioning: mastering floats, margin-left/right, and auto

Hey there, I'm having trouble posting an image but here is the link:

I believe this explanation will be clearer,

D2, D3 & D4 need to be aligned next to each other and centered on the screen at all times. (960px)
         D2-680px, D3-10px, D4-270px (all three together & must be centered on the screen)

D1 and D5 should adjust according to the screen width.

Moreover, if the user's browser width exceeds 1200px, D1 will also come into play.

Only a D5 is included here for centering purposes (mainly because my thinking is still based on tables. D5 might not actually be utilized.)

To provide a better understanding, I have developed a sticky notes app that I intend to add to the site. Ordinarily, all notes must remain within the 680 div, but if the browser is 1200px wide, I want to enable users to place them in the left column (D1) as well.

My workaround plan involves centering the three columns with the code specified above (within the 960 area)...and then adding a layer of div(D1) if the browser-width is at least 1200px. [My calculation for the d1 layer width would be (browserWidth-960/2)].

<style>
    BODY {margin:0px;padding:0px;}<BR>
    #container {width:960px;margin-left:auto;padding:0px;margin-right:auto;height:60px;}<BR>
    #dx {width:690px;}<BR>
    #d2 {background-color:#ff0000;margin:0px;padding:0px;width:680px;height:60px;}<BR>
    #d3 {background-olor:#00ff00;margin:0px;padding:0px;width:10px;height:60px;float:right;}<BR>
    #d4 {background-color:#0000ff;margin:0px;padding:0px;width:270px;height:60px;float:right;}<BR>
</style>

<div id="container"><BR>
  <div id="d4"><BR>
   &nbsp;<BR>
  </div><BR>
  <div id="dx"><BR>
      <div id="d3"><BR>
       &nbsp;<BR>
      </div><BR>
      <div id="d2"><BR>
       &nbsp;<BR>
      </div><BR>
  </div><BR>


In simple terms, I cannot make changes to the 960 area (as it represents the site), but if their screen is wide enough, I also want to offer the option of placing stickys in the left side column (D1).

Answer №1

These suggestions may not be exactly what you were looking for, but one of them might come close to meeting your needs.

Suggested Idea #2: http://jsfiddle.net/DXmLE/

HTML Code snippet:

<div id="container">
    <div id="d1">d1</div>
    <div id="d2">d2</div>
    <div id="d3">d3</div>
    <div id="d4">d4</div>
    <div id="d5">&nbsp;</div>
</div>

CSS Styling:

html, body {
    margin: 0;
    padding: 0
}
#container {
    width: 100%;
    display: table;
    table-layout: fixed
}
#container > div {
    display: table-cell;
    height:60px
}
#d1, #d5 {
    overflow: hidden
}
#d2 {
    background-color: #f00;
    width: 680px
}
#d3 {
    background-color: #0f0;
    width: 10px
}
#d4 {
    background-color: #00f;
    width: 270px;
}

Alternate Suggestion:#1: http://jsfiddle.net/PnujB/

If any of these solutions work for you, I can provide the HTML/CSS code accordingly.

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

Having trouble with Jquery's .mouseover() method? Let's catch the solution!

I'm currently working on a jQuery homework assignment and I've been attempting to enhance the mouseover feature, but unfortunately, it's not functioning as expected. $("button").mouseover(function() { $(this).css({ left: (Math.rando ...

Improve the design of the email newsletter

Having some trouble coding a particular element in my email newsletter layout. This is the desired outcome: View Screenshot Here's what I currently have: View Screenshot Any idea what could be going wrong here? Check out the code snippet below: &l ...

Steps to create a responsive iframe for Slideshare

Recently, I included a slideshare iframe presentation on my webpage. Here is the code snippet I used: <iframe src="//www.slideshare.net/slideshow/embed_code/key/HQoiz6GR1oLe1n" width="860" height="600" frameborder="600" marginwidth="0" marginheight="0 ...

The Datatable feature is malfunctioning, unable to function properly with Javascript and JQuery

As a novice in the world of jquery/javascript, I find myself struggling with what may seem like an obvious issue. Despite following tutorials closely (the code for the problematic section can be found at jsfiddle.net/wqbd6qeL), I am unable to get it to wor ...

Using CSS to mask images with border-radius

I am currently designing a website for a friend, and I have encountered an issue with an image that I have masked using CSS border-radius. The image is larger and taller than its container, so I used JavaScript to center it correctly. However, it appears ...

Modifying inner content without altering CSS styling

Inside this div, there is a paragraph: This is the HTML code: <div id="header"><p>Header</p></div> This is the CSS code: #header p { color: darkgray; font-size: 15px; Whenever a button is clicked, the innerHTML gets updated: H ...

Difficulty with aligning textfield controls to the right

I'm currently working on adding StaticTextField controls to a page. We are using ExtJS, but we incorporate VB.NET methods for implementing ExtJS so manual coding isn't necessary. So far, I attempted to align the text to the right by using this c ...

When state updates in React, the component will rerender without affecting its style

There seems to be a minor oversight on my part. The issue arises in the parent component where I maintain a state of selected items, which are added from the child component. The background color of the child component changes when an item is selected. Ad ...

The PNG image keeps getting cropped

The bottom of a PNG image is being cropped off. View the picture illustrating the issue .loadMoreBtn-label { background-image: url(picture); background-repeat: no-repeat; padding-left: 30px; background-size: 23px 23px; background-posit ...

Decrease the height of h1 by using the display property set to table-cell

I managed to center text inside a table cell using display: table-cell, vertical-align: middle, and text-align: center. However, I'm experiencing unwanted spacing above and below the text. How can I completely eliminate it? I want zero margin/padding ...

Repeated Hover Effects on CSS Menu Icons

the webpage I need help with is (issue with general menu drop down) Hello I recently decided to enhance my menu by incorporating icons. I had successfully implemented a drop-down menu using only HTML and CSS, but when I attempted to add icons next to ea ...

Material-UI's simplification of 10px comprehension

I'm a bit confused about why we have to do this for the 10px simplification: html { font-size: 62.5%; /* 62.5% of 16px = 10px */ } Shouldn't the following code handle everything? const theme = createMuiTheme({ typography: { // Set the ...

Issues arise when the elements <html> and <body> fail to adhere to a 100

Lately, I've been struggling with various problems related to heights. I was able to resolve the height issues of certain elements using flex:auto and flex-shrink:0. However, I'm facing difficulties getting the HTML and Body tags to cooperate ( ...

Sentence following the original passage

I want to achieve a similar look as the example below: Here is what I have done so far: h2:after { content: ""; display: inline-block; height: 0.5em; vertical-align: bottom; width: 48px; margin-right: -100%; margin-left: 10px; border-bo ...

What is the best way to make all <li> elements appear on one line above, regardless of the content within each <li>?

Is there a way to align all li elements on the same line regardless of their content? Check out this screenshot for reference: ? The main issue I'm facing is that when I try to code it, the content within each li element shifts the other lis like thi ...

Mysterious Chrome glitch causes SVG element to shift down by 2 pixels

I am currently facing an issue with creating image links from an SVG spritesheet that is causing cross-browser problems between Chrome, Safari, and Firefox. Here are some of the anchor tags I am using: <a href="#" id="twitter-logo" class="socialIcon"&g ...

Troubleshooting padding problem in mobile gallery view with Bootstrap

Having a problem with the gallery layout in Bootstrap. It looks great on desktop view, but on mobile, there's no space between images on the same row. On mobile, the images stack vertically without any spacing between them within a row. However, ther ...

HTML and CSS: Centering elements inside div containers

Is it possible to align elements within a </div> using the align attribute? For example, as shown in the image below: e1:align="top" e2:align="right" e3:align="bottom" e4:align="left" EDIT: This query is purely for self-learning purposes in HTML ...

Arranging a flex item below another flex item within a flexbox container

Is there a way to use flexbox to ensure that the 2.5 element is placed below the 2 element instead of beside it on the same row within the flex container? Given the HTML provided, how can I achieve this layout using flexbox? I attempted to accomplish thi ...

Add extra space to the dimensions of the div by incorporating padding

Showing my issue with an accompanying image: I am looking for a solution to include padding in the width: 50%; calculation. Currently, the first div's width is actually 50% + 2em because the padding was not factored in initially. Is there a way to i ...