The arrangement and hue of elements using CSS styling

I am seeking to create a unique design with a predominantly gray background, accented by a smaller blue background within it.

The design concept is illustrated below:

<body>
<div id= "background_1">
    <div id= "background_2">
    </div>
</div>
</body>

In the accompanying CSS:

#background_1
{
background-color : gray;
z-index : 1;
}
#background_2
{
background-color : blue;
z-index : 2; 
}

Looking for assistance in bringing this vision to life. Although it may be a bit vague, my goal is to achieve an overall gray background with a striking blue rectangle in the forefront.

Answer №1

Your code is functioning properly without the need for a z-index.

Consider adding some content to your divs or adjusting their sizes.

Additional notes on your other inquiries

// HTML
<body>
    <div id="background">
        Test content
    </div>
</body>

// CSS
html,body
{
  margin:0 20px 0 20px;
  background-color: gray;
  height: 100%;
}
#background
{
  width:100%;
  height: auto !important; 
  height: 100%; 
  min-height: 100%; 
  background-color: blue;
}​

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

Answer №2

z-index will only have an effect if the element has a position of relative, fixed, or absolute.

If you're going for a more classic look, you might want to try using border:

div { width:100px; height:100px; background:lightblue; border:50px solid gray;}

Answer №3

To simplify the layout, consider setting the initial background color to gray for the entire body:

body { background: gray }
body > div.blue { background: blue }
<body>
<div class="blue">
Content goes here.
</div>
</body>

It's worth noting that in this scenario, the gray area will be 8px wide due to the default margin of the body element.


Alternatively, if you prefer the blue section to fill the entire screen with a gray "border" around it, you can achieve this without using a separate division:

body { background: blue; border: 10px solid gray }
<body>
Content goes here.
</body>

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

What is the best way to hide the black icons (x) and bars on larger screens and which specific CSS code should I use to achieve this?

I'm attempting to display menu icons only on smaller screens like phones or tablets, and text on larger screens such as laptops or desktops. I've experimented with adjusting the media query and CSS, but haven't had any success. What specific ...

What is preventing me from being able to reposition certain tables on my site?

I have successfully implemented certain aspects of my responsive website, but I am encountering some difficulties in moving specific tables. I can adjust the table in various directions, except for moving it downwards. Even when adding the word !important ...

Return all HTML code from the Ajax element

I can't seem to pinpoint the issue with my code. When I make an ajax call using the code below: ajax.js: function ajaxObj(meth, url){ var x = new XMLHttpRequest(); x.open(meth, url, true); x.setRequestHeader("Content-type", "application/x-www_form-u ...

Is it better to set a timeout for executing a script in a view, or to incorporate an efficient timeout directly into the

After putting in some effort, I have managed to partially achieve my desired outcome. However, I am still exploring options to improve it further. Here is the situation: There is a controller that displays a view upon successful password reset. Within thi ...

Applying CSS rules from an array to elements by looping through

I'm looking for a way to allow users to input CSS styles and have those styles applied to the last selected element, which is determined by the "rangeselector" variable. Currently, the code selects the correct element, but only the first CSS rule is b ...

What is the best way to configure custom CSS styles in a React project?

I've been trying to position my Grid component from Material-UI, but so far, I haven't had any luck. What could be the issue here? class Scene extends React.Component { render() { const mystyle = { backgroundColor: "DodgerBlue", ...

How about this: "Leveraging the power of #IEroot to achieve a

Has anyone successfully implemented the IE CSS hack #IEroot? I came across it while reading this informative article, but unfortunately, it doesn't seem to be working for me. I'm currently trying to resolve an inline styling bug in order to achi ...

Toggle the menu using jQuery on unordered list items

Below is the HTML code I am using : <ul class="main-block"> <li class="firstLevel"> <a href="#category">EXAMPLE CATEGORY 1</a> <ul class="dijete"> <li class="child"> <a href="some-sub-categ ...

The navigation menu that usually appears on mobile devices is surfacing on desktop screens instead - update: images now

I have recently been working on my website juniorgoldreport.com, which was created using WordPress. The plugin I am using specifically for the mobile nav bar is The functionality and ease of use of this plugin are incredible. The setting to show the toolb ...

What is the method to make xsl:function return a string value containing HTML tags?

I am currently working on converting a Java function into an XSL:Function specification. The function is responsible for adding HTML tags around substrings. I have encountered some challenges in this process: while the Java code works perfectly with inline ...

Creating columns with equal heights in Bootstrap 3 without compromising on the column padding

I am using a standard Bootstrap 3 CSS setup and I am trying to give columns inside a row the same height. I have been experimenting with using display: table and display: table-cell, which does work, but it seems to add vertical padding to columns with les ...

Creating a visual feast: A guide to crafting a stunning image gallery

Is there a way to ensure all the pictures in a table are the same size, orientation, and inline? Currently, my images vary in size and rotation. The CSS I have applied is styling only the first image differently from the rest. Any help is appreciated! CSS ...

Utilize Selenium in Python to choose an element

When working with the following HTML code: <div class="nav-category__col" id="category_nav_level_3" style="display: block;"> <input type="hidden" value="1" name="videogame_type" id="videogame_type"> <ul class="nav-category__list" adp ...

Resize image dimensions to fit within css div class container

How can I make my image completely fit the size of my div class without cutting off any parts? I've tried using background-size: cover, but it only scales the image to fill the div and cuts off part of it. I also attempted to use object-fit: fill, but ...

In order to check a checkbox, you need to ensure that the scrolling div has been scrolled to the very

I have a situation where I need to ensure that a user has scrolled to the bottom of a disclaimer before they can acknowledge it by checking a checkbox. Our legal department requires this extra step for compliance reasons. Here is an example of how the mark ...

Combining Various Template Variables into a Single Variable in Django

I am facing a challenge in assigning multiple values from a dictionary to a variable within a Django template. For example: fruit.supplier = tesco fruit.color = blue {% with test=fruit.supplier_fruit.color %} {{ test }} {% endwith %} The expected ...

Tips on how to showcase list items in a horizontal manner while maintaining consistent spacing and ensuring they are

I have a list of items denoted by the "li" tag, and I am looking for a way to display them horizontally or in a neat format. Below is the HTML code snippet: <!doctype html> <html lang="en" ng-app="app"> <head> ... </head> <bo ...

Trigger the animation with a button click by utilizing ng-class in Angular.js

How can I make an animation run more than once when a button is clicked? I've tried using ng-class but it's not working as expected. Any help would be appreciated. Thank you! <div ng-controller="MyCtrl"> <div class='contendor_port ...

Begin by positioning flex elements outside of the screen and then animate them into their final

I'm struggling to find the right approach to make this animation work effectively. Currently, I have two elements centered vertically within a flexbox layout. My goal is to animate these elements into their final positions by sliding in from off-scre ...

The HTML Canvas seems to be malfunctioning for some unknown reason

As a beginner in programming, I am struggling to understand why the code below is not working. The first three lines of the script are necessary for another part of the webpage, but I don't see how that would affect the rest of the code: <!DOCTY ...