I have three div boxes
box1 - menu, box3 - info, and box2 - slide box which I want to be back of box1 and box3, (As the photo shows http://s16.postimg.org/u9mwuhmcl/111.png)
My attempt:
.box1 {
width:980px;
height:100px;
background-color:#CCCCCC;
}
.box2 {
width:980px;
height:100px;
background-color:#000;
position:relative;
z-index:1 ;
}
.box3 {
width:980px;
height:100px;
background-color:#CCCCCC;
}
<div class="box1">Menu</div>
<div class="box2">Slider</div>
<div class="box3">Info text</div>
Here is one options using position relative on the top and bottom boxes.
JSfiddle Demo
* {
color: white;
}
.box1,
.box3 {
margin: auto;
}
.box2 {
height: 100px;
background-color: #000;
position: relative;
z-index: -1;
}
.box1 {
width: 980px;
height: 100px;
background-color: #CCCCCC;
position: relative;
top: 1em;
}
.box3 {
width: 980px;
height: 100px;
background-color: #CCCCCC;
position: relative;
top: -1em;
}
<div class="box1">Menu</div>
<div class="box2">Slider</div>
<div class="box3">Info text</div>
2nd option with position relative on the second box.
JSfiddle Demo 2
* {
color: white;
}
.box1,
.box3 {
margin: auto;
}
.box2 {
height: 100px;
background-color: #000;
position: relative;
top: -1em;
z-index: -1;
}
.box1 {
width: 980px;
height: 100px;
background-color: #CCCCCC;
position: relative;
}
.box3 {
width: 980px;
height: 100px;
background-color: #CCCCCC;
position: relative;
margin-top: -2em;
}
<div class="box1">Menu</div>
<div class="box2">Slider</div>
<div class="box3">Info text</div>
Try
.box1, .box3 {
position: relative;
z-index: 0;
}
.box2 {
z-index: 1;
}
for box 1 and box 3.
Note: please set top,width,height according to your need.
.box1 {
width:500px;
height:50px;
background-color:#CCCCCC;
position:absolute;
left:0px;
right:0px;
top:0px;
}
.box3 {
width:500px;
height:50px;
background-color:#CCCCCC;
position:absolute;
left:0px;
right:0px;
top:100px;
}
For box 3
.box3 {
width:980px;
height:100px;
background-color:#CCCCCC;
margin-top:40px;
}
You better need a wrapper to simply the code.
No need to play with z-index in your case because position: relative; will give your block priority to the default position: static;
.wrapper{
width: 980px;
}
.box1, .box3 {
height:100px;
margin: 0 20px;
background-color:#CCCCCC;
box-sizing: padding-box;
position: relative;
}
.box2 {
height:100px;
margin: -20px 0;
background-color:#000;
}
<div class="wrapper">
<div class="box1">Menu</div>
<div class="box2">Slider</div>
<div class="box3">Info text</div>
</div>
use this-
.box1 {
width:90%;
height:100px;
background-color:#CCCCCC;
margin:0 auto;
position: relative;
z-index: 2;
bottom: -10px;
}
.box2 {
width:100%;
height:100px;
background-color:red;
position:relative;
z-index:1 ;
margin:0 auto;
padding:10px;
}
.box3 {
background-color: #cccccc;
height: 100px;
margin: 0 auto;
position: relative;
top: -10px;
width:90%;
z-index: 4;
<div class="box1">Menu</div>
<div class="box2">Slider</div>
<div class="box3">Info text</div>
I hope it will helps you.
Related
i want to ask you. I'm trying to create a border using pseudo element (after). I want to place a border in the middle of the div box that I have created, without setting (top, bottom) and (left, right). Can it be automated in the middle?
My Codepen
<div class="box">
</div>
.box{
height:500px;
width:300px;
background-color:red;
position:relative;
&::after{
content:'';
position:absolute;
border:2px solid #fff;
height:90%;
width:90%;
}
}
I've used percentages for the top and left and than correect the positioning with transform: translate(-50%, -50%); so its in the middle
.box{
height:500px;
width:300px;
background-color:red;
position:relative;
}
.box::after{
content:'';
position:absolute;
border:2px solid #fff;
height:90%;
width:90%;
left: 50%;
transform: translate(-50%, -50%);
top: 50%;
}
<div class="box"></div>
.box{
height:500px;
width:300px;
background-color:red;
position:relative;
}
.box:after {
content: '';
position: absolute;
border: 2px solid #fff;
top: 3%;
left: 4%;
height: 93%;
width: 90%;
}
<div class="box">
</div>
Yes it can:
.box {
width: 500px;
height: 500px;
position: relative;
background-color: blue;
padding: 10px;
}
.box:after {
content: '';
position: absolute;
display: block;
width: 95%;
height: 95%;
border: 1px solid #FFF;
}
<div class="box">
</div>
Allthough I don't completely understand why you wouldn't want to use top, right, bottom, left values. With transform, you can't automate it ALWAYS. You'll have to set it to half the height of the box. With a top value, you could just set it to 50%.
There are couple of ways....!!
.box{
height:500px;
width:300px;
background-color:red;
position:relative;
&::after{
content:'';
position:absolute;
border:2px solid blue;
height:90%;
width:90%;
right: 50%;
bottom: 50%;
transform: translate(50%,50%);
}
}
Another way...without using positions.
.box{
height:500px;
width:300px;
background-color:red;
display: flex;
&::after{
content:'';
border:2px solid blue;
height:90%;
width:90%;
margin: auto;
}
}
You can use flexbox on the .box element to center its contents. Just make sure no other position property is set on the ::after pseudo-element:
.box {
height: 500px;
width: 300px;
background-color: red;
position: relative;
display: flex;
align-items: center;
justify-content: center;
}
.box::after {
content: '';
position: absolute;
border: 2px solid #fff;
height: 90%;
width: 90%;
}
I'm trying to get the yellow circle on top of all elements, all my elements are positioned so my z-index of 999999999 should have put it upfront but it's not working for some reason, any help?
.menu_maincontainer{width:100%; height:auto; display:flex; flex-direction:column; overflow:hidden; outline:1px solid red; position:relative; }
.menu_contents_container{width:100%; height:auto; background-color:red; position:relative; margin-top:300px; padding:25px;}
.menu_background_oval{width:105%; height:500px; border-radius:50%; position:absolute; left:50%; z-index:1; transform:translateX(-50%); top:-180px; background-color:red;}
.menu_contants_decorative_circle{width:200px; height:200px; border-radius:50%; border:1px solid blue; background-color:yellow; position:absolute; z-index:9999999999; left:50%; top:50px; transform:translateX(-50%); }
.menu_contents_texts_container{width:100%; min-height:500px; background-color:red; z-index:2; outline:1px solid blue; display:flex; flex-direction:column; position:relative; }
<div class="menu_maincontainer" style="">
<div class="menu_contents_container" style="">
<div class="menu_background_oval" style="">
<div class="menu_contants_decorative_circle" style=""></div>
</div>
<div class="menu_contents_texts_container" style="">
</div>
</div>
</div>
Because menu_contants_decorative_circle is a child of menu_background_oval, which has a z-index of 1, the circle will inherit the same z-index. You can think of it as having a z-index of 9999999999 on a certain layer (z-index: 1), but that is practically the same as z-index: 1;
Changing the z-index of the circle's parent will solve this:
.menu_maincontainer {
width: 100%;
height: auto;
display: flex;
flex-direction: column;
overflow: hidden;
outline: 1px solid red;
position: relative;
}
.menu_contents_container {
width: 100%;
height: auto;
background-color: red;
position: relative;
margin-top: 300px;
padding: 25px;
}
.menu_background_oval {
width: 105%;
height: 500px;
border-radius: 50%;
position: absolute;
left: 50%;
z-index: 5; /* changed */
transform: translateX(-50%);
top: -180px;
background-color: red;
}
.menu_contants_decorative_circle {
width: 200px;
height: 200px;
border-radius: 50%;
border: 1px solid blue;
background-color: yellow;
position: absolute;
z-index: 1;
left: 50%;
top: 50px;
transform: translateX(-50%);
}
.menu_contents_texts_container {
width: 100%;
min-height: 500px;
background-color: red;
z-index: 2;
outline: 1px solid blue;
display: flex;
flex-direction: column;
position: relative;
}
<div class="menu_maincontainer">
<div class="menu_contents_container">
<div class="menu_background_oval">
<div class="menu_contants_decorative_circle"></div>
</div>
<div class="menu_contents_texts_container">
</div>
</div>
</div>
I need to make template as it shown on picture below:
I succed with top square but failed with alligning the bottom one - can't move it to the bottom left corner.
The code is:
<style>
.red_top {
background-color:red;
position:absolute;
width:65px;
height:65px;
z-index:-1;
}
.red_bottom {
align:right;
verical-align:bottom;
background-color:red;
position:relative;
width:65px;
height:65px;
z-index:-1;
top:-35px;}
.main_cont
{
border:1px solid blue;
margin-top:25px;
margin-left:25px;
min-height:100px;
z-index:1;
background-color:#FFF;
}
</style>
<body style="margin: 60px 50px;">
<div style="width:100%; border:1px solid #000;">
<div class="red_top"> </div>
<div class="main_cont">Content Here</div>
<div class="red_bottom"> </div>
</div>
https://codepen.io/anon/pen/OxavGL
What I need to do for red_bottom div proper placing?
.red_top {
background-color: red;
position: absolute;
width: 65px;
height: 65px;
z-index: -1;
}
.red_bottom {
background-color: red;
position: absolute;
width: 65px;
height: 65px;
z-index: -1;
bottom: 0;
right: 0;
}
.main_cont {
border: 1px solid blue;
margin: 25px;
min-height: 100px;
z-index: 1;
background-color: #FFF;
}
<div style="width: 100%; border: 1px solid #aaa; position: relative;">
<div class="red_top"> </div>
<div class="main_cont">Content Here</div>
<div class="red_bottom"> </div>
</div>
body {
margin: 60px 50px;
}
.Wrap {
position: relative;
width: 100%;
}
.main_cont {
position: relative;
background-color: #FFF;
border: 1px solid blue;
margin-top: 25px;
margin-left: 25px;
min-height: 100px;
}
.main_cont::before,
.main_cont::after {
content: "";
position: absolute;
background-color: red;
width: 65px;
height: 65px;
z-index: -1;
}
.main_cont::before {
top: -33px;
left: -33px;
}
.main_cont::after {
bottom: -33px;
right: -33px;
}
<div class="Wrap">
<div class="main_cont">Content Here</div>
</div>
Try This:
body {
margin: 5%;
}
.Wrap {
position: relative;
width: 100%;
}
.main_cont {
position: relative;
background-color: #FFF;
border: 1px solid blue;
min-height: 100px;
text-align: center;
}
.main_cont::before,
.main_cont::after {
content: "";
position: absolute;
background-color: red;
width: 50px;
height: 50px;
z-index: -1;
}
.main_cont::before {
top: -25%;
left: -3%;
}
.main_cont::after {
bottom: -25%;
right: -3%;
}
<div class="Wrap">
<div class="main_cont">Content Here</div>
</div>
CSS:
.main_cont::before {
content: '';
background-color: red;
position: absolute;
width: 65px;
height: 65px;
z-index: -1;
top: 0;
left: 0;
}
.main_cont::after {
content: '';
background-color: red;
position: absolute;
width: 65px;
height: 65px;
z-index: -1;
bottom: 0;
right: 0;
}
.main_cont {
border: 1px solid blue;
margin: 25px;
min-height: 100px;
z-index: 1;
background-color: #FFF;
}
HTML:
<div style="width: 100%; border: 1px solid #000; position: relative;">
<div class="main_cont">Content Here</div>
</div>
Here you go:
.mainDiv {
position: relative;
width: 500px;
height: 700px;
border: 1px solid black;
background-color: white;
}
.red_top {
background-color:red;
position:absolute;
left: -31px;
top: -31px;
width:65px;
height:65px;
z-index:-1;
}
.red_bottom {
background-color:red;
position:absolute;
bottom: -31px;
right: -31px;
width:65px;
height:65px;
z-index:-1;
.main_cont {
border:1px solid blue;
margin-top:25px;
margin-left:25px;
min-height:100px;
z-index:1;
background-color:#FFF;
}
<body style="margin: 60px 50px;">
<div class="mainDiv">
<div class="red_top"></div>
<div class="main_cont">Content Here</div>
<div class="red_bottom"></div>
</div>
You can use the following solution without using additional <div> elements for the red boxes. This solution is using :before and :after to create the red boxes.
div.container {
border:1px solid #000;
position:relative;
width:100%;
}
div.main {
background:#fff;
border:1px solid blue;
margin:33px;
min-height:100px;
position:relative;
width:auto;
}
.red-box:before, .red-box:after {
background:red;
content:"";
height:65px;
position:absolute;
width:65px;
z-index:-1;
}
.red-box:before {
left:0;
top:0;
transform:translate(-50%, -50%);
}
.red-box:after {
bottom:0;
right:0;
transform:translate(50%, 50%);
}
<div class="container">
<div class="main red-box">Content Here</div>
</div>
I need to make responsive layout of the design attached , please help.
Things to keep in mind:
Can't fix height/width of logo image or any of the div's, it has to be dynamic
5px padding between the border line and the image.
Thanks!
.width100per {
max-width:1100px;
width:100%;
height:1000px;
text-align:center;
margin: 0px auto;
background-color: #808080;
}
.container {
width:100%;
float:left;
}
.container::after {
content: " ";
border-bottom:red 2px solid;
width: 100%;
float: left;
position: absolute;
top: 24%;
left: 0;
z-index: 10;
}
header {
float: left;
width: 100%;
}
header .logo {
float:left;
width:20%;
height:100%;
background-color:#000;
position: relative;
z-index: 20;
}
header .logo img{
width: 100%;
}
<div class="width100per">
<div class="container"></div>
<header>
<div class="logo">
<img src="jessicarose.nordicfinest.com/static/home_333333.png">
</div>
</header>
</div>
add this code in your css
header:after{
content: " ";
border-bottom: red 2px solid;
width: 100%;
float: left;
position: absolute;
bottom: -2px;
left: 0;
z-index: 10;
}
header{
position:relative;
}
.container::after {
display:none;
}
<div class="width100per">
<header>
<div class="logo">
<img src="jessicarose.nordicfinest.com/static/home_333333.png">
</div>
</header>
</div>
/* Css */
header {
float: left;
width: 100%;
padding-left: 20%;
position: relative;
}
header .logo {
float:left;
width:20%;
height:calc(100% + 10px);
height:-moz-calc(100% + 10px);
height:-webkit-calc(100% + 10px);
background-color:#000;
position: absolute;
background-color:#000;
padding: 5px;
z-index: 20;
top: 0;
left: 0;
text-align: center;
}
header .logo img{
padding-top: 20px;
display:inline-block;
float: none;
max-width: 100%;
}
Demo jsFiddle
I have div color azure I want to fill the width area in the middle column no meter what size will be.
is there any solution with css3/css no jQuery ?
i need it like this picture:
the ststus current like this:
many Thx.
Demo jsFiddle
the code html:
<div id="frame">
<div id="inside_window">
<div id="Yellow"></div>
<div id="Green"></div>
<div id="Blue"></div>
<div id="Red"></div>
<div id="ver"></div>
<div id="hor"></div>
<div id="ver2"></div>
</div>
</div>
the code css:
html, body{
height:100%;
background-color: azure;
}
#frame
{
position: relative;
background-color: black;
height: 100%;
width: 100%;
margin: auto;
padding:0;
border: 1px solid black;
}
#Yellow
{
position: absolute;
height: 100%;
width: 150px;
-webkit-border-radius: 0px;
margin: 0 ;
background-color: Yellow;
z-index:10;
display:table;
left:0px;
top:0;
}
#Green
{
position: absolute;
height: 100%;
width: 150px;
-webkit-border-radius: 0px;
margin: 0 ;
background-color: green;
z-index:10;
right:0px;
top:0;
}
#Blue
{
position: relative;
height:100%;
min-width:65.8%;
-webkit-border-radius: 0px;
margin: 0 auto;
background-color: #62A9FF;
z-index:10;
display:table;
font-size:220%;
left:0px;
top:0px;
}
#Red
{
position: absolute;
height: 150px;
width: 100%;
-webkit-border-radius: 0px;
margin: 0 ;
background-color: red;
z-index:10;
border: 1px solid black;
left:0px;
bottom:0px;
}
#inside_window
{
width:100%;
height:100%;
margin:0 auto;
position: relative;
border: 1px solid black;
background-color: brown;
-webkit-transform: rotate(0deg);
-webkit-transform-origin:50% 50%;
}
#ver
{
position: absolute;
height: 100%;
width: 5px;
margin: 0;
background-color: white;
left:150px;
top:0px;
z-index:1;
}
#hor
{
position: absolute;
height: 5px;
width: 100%;
margin: 0;
background-color: white;
left:0px;
bottom:150px;
z-index:20;
}
#ver2
{
position: absolute;
height: 100%;
width: 5px;
margin: 0;
background-color: white;
right:150px;
top:0px;
z-index:1;
}
Try removing the following CSS from your blue code:
position: relative;
display:table;
There are many ways to acheive a layout like this. Supposing that you could alter the order of your content, you could always try the "Holy Grail" layout method.