Using z-index and position values to align divs - html

I'm trying to create a banner which spans the page width. A centered container measuring 1130px within this region holds five blocks of color at 20% of the container. Behind this container should be two divs at 50% each - one containing the first color swatch and the other containing the last to create a seamless palette but maintain the same width.
The issue I'm having at the minute is that the .modal-container which holds the five colour blocks will not display on top of the two background blocks .modal-left and .modal-right. I've tried tinkering with the z-index values of all three classes to no avail. position: absolute isn't an option either as this knocks the margin: 0 auto alignment off. Any ideas?
JSFiddle
The effect I'm looking for

EDIT:
I just got really carried away and did a total overhaul on that code. I'M SORRY I COULDN'T HELP MYSELF LOL
New and improved ya dig.
Your HTML simply needed some re-arranging. The inner div placed above the other two fixed it right up.
CSS (updated):
.modal {
background-image: -webkit-linear-gradient(right, #3e454c 50%, #ff7f66 50%);
background-image: -moz-linear-gradient(right, #3e454c 50%, #ff7f66 50%);
background-image: -ms-linear-gradient(right, #3e454c 50%, #ff7f66 50%);
background-image: -o-linear-gradient(right, #3e454c 50%, #ff7f66 50%);
background-image: linear-gradient(to left, #3e454c 50%, #ff7f66 50%);
background-size: cover;
background-attachment: fixed;
background-position: left top;
background-repeat: no-repeat;
height: 54px;
width: 100%;
max-width: 1130px;
}
.modal-inner {
position: relative;
max-width: 1130px;
}
.modal-block {
float: left;
width: 20%;
height: 27px;
}
.una {
background: #3e454c;
background: rgba(62, 69, 76, .5);
}
.dos {
background: #2185c5;
background: rgba(33, 133, 197, .5);
}
.tres {
background: #7ecefd;
background: rgba(126, 206, 253, .5);
}
.cuatro {
background: #fff6e5;
background: rgba(255, 246, 229, .5);
}
.cinco {
background: #ff7f66;
background: rgba(255, 127, 102, .5);
}
HTML (less is more :) ):
<div class="modal">
<div class="modal-inner">
<div class="modal-block una"></div>
<div class="modal-block dos"></div>
<div class="modal-block tres"></div>
<div class="modal-block cuatro"></div>
<div class="modal-block cinco"></div>
</div>
</div>

See demo here http://jsfiddle.net/Godinall/cq27S/3/
First, re-arrange your divs to put the 50/50 underneath
Second, and most importantly, add this to .modal-inner
I believe this is better solution than setting position/margins
display:block;

Related

I want to horizontally split the background into two colors where one is black color. And de other one is a grandient of 2 colors like purple and pink

body {
height:100%;
background: linear-gradient(top, #d808a4 50%, black 50%);
background: linear-gradient(top, #d808a4 50%,black 50%);
background: linear-gradient(to bottom, #d808a4 50%,black 50%);
height: 229vh;
}
I want to horizontally split the background into two colors where one is black color. And I want the other one to be a gradient that goes from pink to purple, I have manage to split into purple and black, but i want a purple pink grandient, can someone help me?
#top-half {
position: absolute;
left: 0;
width: 100%;
height: 50%;
background-color: black;
}
#bottom-half {
position: absolute;
left: 0;
top: 50%;
width: 100%;
height: 50%;
background: linear-gradient(90deg, rgba(255,0,209,1) 0%, rgba(151,0,255,1) 100%);
}
<div id="bottom-half"></div>
<div id="top-half"></div>
2 divs for each half
position: absolute and left: 0 and top: 50% sets the position
width: 100% sets it to screen width
height: 50% sets the height for each one to half the screen width
background-color: black obviously sets the background color to black, and background: linear-gradient(90deg, rgba(255,0,209,1) 0%, rgba(151,0,255,1) 100%) sets the background to a gradient (you can generate nice CSS gradients at https://cssgradient.io/ )
You cannot have multiple background, the newer one will overwrite the old ones. What you can do is to have multiple gradients in a single background such as (try scrolling):
body {
height: 200vh;
background:
linear-gradient(to bottom, transparent 50%, black 50%),
linear-gradient(100deg, #8a07ff, #f500d7);
}
You can do this with just one background setting.
This snippet separates out each of the CSS background settings to make it clearer what is going on.
The whole element gets a black background, then a background-image which is a linear-gradient is defined. This will sit on top of the black background-color. It is given a size and a position and is made not to repeat.
Obviously change the colors and the size to what you want.
.bg {
width: 100vw;
height: 100vh;
background-color: black;
background-image: linear-gradient(to right, purple, magenta);
background-size: 80% 50%;
background-position: center top;
background-repeat: no-repeat;
}
<div class="bg"></div>

Create a transparent div that cuts into another div

I have two divs on top of each other. I need the bottom div to have a slanted angle like this:
I only need help with slant of the top of the blue div, I can handle to bottom slant myself.
I could create a psuedo element and skew it, but the issue is that the blue div has a gradient and making a psuedo element with the same gradient makes the two elements not flow together with their gradients.
I think my only solution is to create a transparent div, skew it and place it on top of the blue div. I was wondering if this is even possible to create a skewed transparent div and have it cut into the blue div, slanting the blue div while showing the image in the background.
I'm open to any other ideas to achieve this slanted div.
Ive created a simple jsfiddle with the divs for anyone to mess around with.
Here is the basic mark up:
<div class="main">
<div class="main-top">
</div>
<div class="main-bottom">
</div>
</div>
.main-top {
background: url("http://stock-wallpapers.com/wp-content/uploads/2015/01/Huawei_P7_home_wallpaper_02_.jpg") center center no-repeat;
background-size: cover;
height: 300px;
width: 600px;
}
.main-bottom {
height: 300px;
width: 600px;
background-image: -moz-linear-gradient( -51deg, rgb(28,35,80) 0%, rgb(27,31,71) 41%, rgb(25,26,62) 100%);
background-image: -webkit-linear-gradient( -51deg, rgb(28,35,80) 0%, rgb(27,31,71) 41%, rgb(25,26,62) 100%);
position: relative;
top: -150px;
}
Thanks
It is in fact very easy if you use this site
http://bennettfeely.com/clippy/
.main-top {
background: url("http://stock-wallpapers.com/wp-content/uploads/2015/01/Huawei_P7_home_wallpaper_02_.jpg") center center no-repeat;
background-size: cover;
height: 300px;
width: 600px;
}
.main-bottom {
height: 300px;
width: 600px;
background-image: -moz-linear-gradient( -51deg, rgb(28, 35, 80) 0%, rgb(27, 31, 71) 41%, rgb(25, 26, 62) 100%);
background-image: -webkit-linear-gradient( -51deg, rgb(28, 35, 80) 0%, rgb(27, 31, 71) 41%, rgb(25, 26, 62) 100%);
position: relative;
top: -150px;
-webkit-clip-path: polygon(0 0, 100% 32%, 100% 100%, 0 68%);
clip-path: polygon(0 0, 100% 32%, 100% 100%, 0 68%);
}
<div class="main">
<div class="main-top">
</div>
<div class="main-bottom">
</div>
</div>

4 gradient borders in CSS

I need help applying a gradient border on all the 4 sides of a box. I tried it, but it only works for two sides. After looking at all the links and SO answers I have got this:
.test{
height:250px;
border: 2px solid;
border-image: linear-gradient(to left,rgba(78,137,176,1) 1%, rgba(115,192,85,1) 100%) 100% 0 100% 0/2px 0 2px 0;
padding-top:50px;
}
<div class="test">
This is a box and I want borders for all the sides
</div>
I would appreciate any help. I am trying something similar to the image below.
Thank you.
Using background image: (produces the exact output as your image)
You seem to be having gradients that are different on each sides and so it is difficult to achieve this with the border-image property. You could try and mimic the behavior using background-image like in the below snippet.
Basically what the below snippet does is that it creates the gradient for each of the 4 sides as gradient background image strips and then uses background-position to place them on the correct location.
The transparent border on parent is a placeholder where the mimiced border would end up appearing. The background-origin: border-box makes the background of the element start from border-box area itself (and not padding-box or content-box). These two are just extra steps to avoid the usage of unnecessary calc stuff in the background-position.
.test {
height: 250px;
border: 2px solid transparent;
background-image: linear-gradient(to right, rgb(187, 210, 224), rgb(203, 231, 190)), linear-gradient(to bottom, rgb(114, 191, 87), rgb(116, 191, 86)), linear-gradient(to left, rgb(204, 233, 187), rgb(187, 210, 224)), linear-gradient(to top, rgb(84, 144, 184), rgb(80, 138, 176));
background-origin: border-box;
background-size: 100% 2px, 2px 100%, 100% 2px, 2px 100%;
background-position: top left, top right, bottom right, bottom left;
background-repeat: no-repeat;
padding-top: 50px;
}
<div class="test">
This is a box and i want border for all the side
</div>
Using border image: (produces a border on all 4 sides but not same output as your image)
The best output that you could get with border-image property would be the below but as you can see from the demo it is not exactly the same as your image (or the first snippet's output):
.test {
height: 250px;
border: 2px solid;
border-image: linear-gradient(to left, rgba(78, 137, 176, 1) 1%, rgba(115, 192, 85, 1) 100%);
border-image-slice: 1;
padding-top:50px;
}
<div class="test">
This is a box and i want border for all the side
</div>
I realized this for myself in this way:
the background changes inside the background-image.
div {
width: 170px;
height: 48px;
border-style: solid;
border-width: 2px;
border-image-source: linear-gradient(to bottom, #fff042, #ff5451);
border-image-slice: 1;
background-image: linear-gradient(to bottom, #f9e6e6, #c5e0c3), linear-gradient(to bottom, #fff042, #ff5451);
background-origin: border-box;
background-clip: content-box, border-box;
display: flex;
align-items: center;
justify-content: center;
text-transform: uppercase;
}
<div>text</div>

One 100vh height div containg 3 divs, the 2nd of which should be the only one with variable height

I'm quite new to CSS3. I've read other questions but I'm not sure they cover my case, so please be patient :)
I have this example page:
<html>
<head>
<style type="text/css">
body { background-color: black; margin: 0; }
#main { background-color: red; width: 60%; height: 100vh; margin: auto; }
#header { background-color: white; width: 100%; height: 25%; max-height: 100px; }
#article { background-color: orange; width: 100%; height: 55%; }
#footer { background-color: blue; width: 100%; height: 20%; max-height: 80px; }
</style>
</head>
<body>
<div id="main">
<div id="header"></div>
<div id="article"></div>
<div id="footer"></div>
</div>
</body>
</html>
There's one additional mandatory behaviour I have to implement, plus an optional one.
The mandatory
As you can see yourself, once the browser window gets quite high, #header and #footer correctly stop to grow, leaving their height to the background red #main div. What I need is that #article gets this space, therefor always "pushing" the #footer to the lower border of the browser screen.
The optional
The layout itself resizes horizontally without any limit, but the #article div has setted a background image that does fade on its left and right sides. To be more precise, it's a 1000x1 image fading in from coords (1,1) to (100,1) and fading out from (901,1) to (1000,1), vertically repeated to cover the height of #article.
How can I get the effect that this image stretches only in its non-fading area (so that the faded borders would not get stretched)?
Can I get it without any extra div (as in that case, the mandatory behaviour would reapeat it self horizontally)?
Thank you so much :)
Having a percentage height for footer and header along with max-height makes it very difficult to work with (or atleast using the technique I go to for this). I changed the css to be a fixed height which is the max-height value. You could use media queries if the percentage height is for screen size compatibility.
Below is how I would achieve the layout, along with a gradient background image, which uses CSS only, rather than an image:
body {
background-color: black;
margin: 0;
}
#main {
background-color: red;
width: 60%;
height: 100vh;
margin: auto;
position: relative;
}
#header {
background-color: white;
width: 100%;
height: 100px;
}
#article {
background-color: orange;
width: 100%;
top: 100px;
bottom: 80px;
position: absolute;
background: rgb(179, 220, 237);
/* Old browsers */
background: -moz-linear-gradient(left, rgba(179, 220, 237, 1) 17%, rgba(41, 184, 229, 1) 49%, rgba(188, 224, 238, 1) 81%);
/* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(17%, rgba(179, 220, 237, 1)), color-stop(49%, rgba(41, 184, 229, 1)), color-stop(81%, rgba(188, 224, 238, 1)));
/* Chrome,Safari4+ */
background: -webkit-linear-gradient(left, rgba(179, 220, 237, 1) 17%, rgba(41, 184, 229, 1) 49%, rgba(188, 224, 238, 1) 81%);
/* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left, rgba(179, 220, 237, 1) 17%, rgba(41, 184, 229, 1) 49%, rgba(188, 224, 238, 1) 81%);
/* Opera 11.10+ */
background: -ms-linear-gradient(left, rgba(179, 220, 237, 1) 17%, rgba(41, 184, 229, 1) 49%, rgba(188, 224, 238, 1) 81%);
/* IE10+ */
background: linear-gradient(to right, rgba(179, 220, 237, 1) 17%, rgba(41, 184, 229, 1) 49%, rgba(188, 224, 238, 1) 81%);
/* W3C */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#b3dced', endColorstr='#bce0ee', GradientType=1);
/* IE6-9 */
}
#footer {
background-color: blue;
width: 100%;
height: 80px;
position: absolute;
bottom: 0;
}
and the fiddle I created to test it out:
Fiddle
Dynamic vertical sizing in CSS is very tricky, even for the pros. To my knowledge, here is how I've done it; sorry for lack of code sample, but if anything is wrong with it I would prefer you understand how it's put together so you know how to fix it.
#header and #footer use position: absolute to take itself out of normal flow. As you said, they need an absolute height.
#article has padding-top equivalent to #header's height. It also has padding-bottom set to the footer's height plus its margin, so that the footer's height is included in integrated height calculation. Its height is set to 100%, and box-sizing is set to border-box so that when it tries to stay at 100%, it is including padding (not default behavior; normally it's only counting actual content)
Some of this is easier to do if you're using a CSS-compiling framework like LESS, to avoid re-calculating pixel amounts yourself each time (change one margin, have to change another height and padding)
I don't have knowledge of backgrounds offhand, but your goal does sound very doable with CSS parameters like background-repeat and background-size; you'd need to take a look at a reference guide like the one on the Mozilla Developer Wiki.
Just wondering, have you tried setting the following?
html,body { height:100%; }
#main { height:100%; }
#article { height:100%; }
This will force #article to be the same height as the window.

Set Multiple Background of One HTML Element

I want to set different backgrounds of a div.
1) A color that will be on whole background.
2) An image on the right.
3) Another image on left.
Something like this
HTML
<div class="theTwoBG" />
CSS
.theTwoBG {
background: #24a342, url('path/to/image1.png') no-repeat right, url('path/to/image2.png') no-repeat left;
}
How can I achieve this?
See Using CSS multiple backgrounds you need to add background-position
.multi_bg_example {
background: url(http://demos.hacks.mozilla.org/openweb/resources/images/logos/firefox-48.png),
linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 1)),
url(http://demos.hacks.mozilla.org/openweb/resources/images/patterns/flowers-pattern.jpg);
background-repeat: no-repeat, no-repeat, repeat;
background-position: bottom right, left, right;
}
Important:
In your case you are using the shorthand writing, here is a working demo for that
.multi_bg_example {
width: 480px;
height: 300px;
background: url(http://lorempixel.com/200/200/) no-repeat left top,url(http://lorempixel.com/100/100/) no-repeat right bottom;
}
<div class=multi_bg_example></div>
This may be usefull...
<div class="my_cls">
</div>
<style type="text/css">
.my_cls {
width: 800px;
height: 500px;
background: url("3.jpg") center left, url("4.jpg") center right;
background-repeat: no-repeat;
background-color: #cccccc;
background-position: left, right;
background-size: 200px, 100px;
}
</style>