Sorry for my english.
I have a problem. I need to create a DIV inside another DIV, which has to have a white background. I tried using skew, but It didnt work well.
Here is an image:
There are at least several ways to achieve this, however the simplest way may be using linear-gradient background. Its quality is not really good compared with others but it's totally acceptable.
Try this:
div {
width:600px;
height:300px;
background:teal;
border:1px solid teal;
}
.top {
width:100%;
height:100px;
font-size:25px;
padding-left:30px;
background:linear-gradient(175deg, white 60%, transparent 62%);
border:none;
box-sizing:border-box;
}
HTML:
<div>
<div class='top'>Custom<br/>Home</div>
</div>
Demo.
You can do that with a pseudo element and transform rotate :
DEMO
HTML :
<div id="header">
Custom<br/>
Home
</div>
<div id="content"></div>
CSS :
#header{
background:#fff;
position:relative;
height:50px;
z-index:1;
font-size:30px;
padding-left:10%;
}
#header:before{
content:'';
position:absolute;
bottom:0;
right:0;
width:110%;
height:1000%;
background:inherit;
z-index:-1;
border-bottom:2px solid #636A6E;
-webkit-backface-visibility: hidden; /* to fix pixelisation in chrome */
-ms-transform-origin:100% 100%;
-webkit-transform-origin:100% 100%;
transform-origin:100% 100%;
-webkit-transform: rotate(-5deg);
-ms-transform: rotate(-5deg);
transform: rotate(-5deg);
}
#content{
min-height:500px;
background:#778385;
}
Since you need the border in your diagonal div, try this:
CSS:
.logo {
width:110%;
height:147px;
top:-10%;
left:-14px;
border:2px solid black;
position:absolute;
background:#fff;
transform:rotate(-7deg);
-ms-transform:rotate(-7deg);
/* IE 9 */
-webkit-transform:rotate(-7deg);
/* Opera, Chrome, and Safari */
}
.container {
width:100%;
height:612px;
overflow:hidden;
background:#7b8284;
position:relative;
}
.inner {
position:absolute;
height:200px;
transform:rotate(7deg);
-ms-transform:rotate(7deg);
/* IE 9 */
-webkit-transform:rotate(7deg);
/* Opera, Chrome, and Safari */
padding:20px 90px;
top:30%;
font-size:30px;
}
HTML:
<div class="container">
<div class="logo">
<div class="inner">My Logo</div>
</div>
</div>
Demo: http://jsfiddle.net/lotusgodkk/BKfe9/1/
You can modify the top,left,font-size,background-color,transform, border as per your need
If you want to do it in pure CSS I would recommend using the transform: rotate(xxx) feature of CSS3. I've created a JS-Fiddle that will help you get started (not the best solution...), it is not based on your fiddle: http://jsfiddle.net/syTu7/
I think I understand your question, I think my example will help
HTML
<div class="wrapper">
<div class="innter">some text</div>
</div>
CSS
.wrapper {
position: relative;
width: 960px;
margin: 0 auto;
background: #ddd;
min-height: 100%;
height: 800px;
}
.innter {
height: 500px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
background: #ececec;
}
In HTML,
<div class="wrapper">
<div class="inner">some content</div>
</div>
In CSS,
.inner {
background: #fff;
}
Related
I have a div-container, a bootstrap collapse element. In it there is another round element, which changes position, when using the collapse function. Means: It should be positioned on the top-border, but behind the bottom-border.
How would you solve this task?
My first idea was to use object-fit to cut off the bottom part of the round element, but that did not look well with transition and collapse. Second idea was to use a thick border-bottom as an after-pseudo-element to cover the bottom part, which did not work so far.
Do you have any ideas or have you done something like that?
Thank you!
Use clip-path:
.box {
border: 3px solid;
height: 200px;
margin: 50px;
position: relative;
clip-path: inset(-200% 0 0); /* a big negative value on the top to clip only left/right/bottom */
transition: 1s;
}
.box:hover {
height: 50px;
}
.box:before {
content: "";
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
width: 100px;
height: 100px;
border: 3px solid;
border-radius: 50%;
background: red;
}
<div class="box">
</div>
You may also use transform3D + background to hide portions of it:
div {
margin:0 1em;
padding:1px;
display:flex;
padding-bottom:2em;
background:white;
transform-style: preserve-3d;
}
div[class] {
border:solid;
border-bottom:none;
height:150px;
transition:0.25s;
}
div[class] + div {
border-top:solid;
}
div[class]:hover {
height:60px;
}
div span {
height:150px;
width:150px;
align-self:center;
background:red;
border-radius:50%;
margin-right:1em;
border:solid;
margin-left:auto;
margin-bottom:-2.2em;
transform:rotatex(-0.15deg) translatez(1px);;
}
<div>Whatever stands here</div>
<div class>
<p>hover to collapse</p>
<span></span>
</div>
<div>Whatever stands next</div>
I'm building a carousel with HTML/CSS and have a problem I can't get my head around.
I have absolutely positioned children (.card) in a carousel-container and want them to slide from side to side when clicking the links below. This works fine when going from card4 backwards to card1, but not forwards from card1 to card4. Then it just jumps to card4 and seems to push the active card off the screen.
Strangely, when I edit my non-active cards' position to
left:95%;
instead of
left:100%;
(see at the very bottom of the CSS snippet), it works as expected.
Tested in Chrome, Firefox and on Codepen
View on CodePen
Thank you very much for your help.
This is my code:
*{
box-sizing: border-box;
}
.carousel-links{
text-align:center;
position:fixed;
bottom: 5%;
left:0;
right:0;
z-index:100;
}
.carousel-links a{
display: inline-block;
border-radius: 5px;
border: 1px solid black;
padding: 1em;
background:white;
}
.carousel{
position: relative;
width:100%;
height:80vh;
background:yellow;
border:5px solid black;
display:block;
overflow-x: hidden;
}
.card{
position: absolute;
top:0;
left:-100%;
width:100%;
height:100%;
border: 1px dashed black;
font-size:100px;
transition: all 2s;
z-index:1;
}
.carousel > .card:target{
left:0%;
//background:rgba(255,0,0,1);
z-index:2;
}
.carousel > .card:target~*{
left:100%;
/* left:95%; /*with this line it works */
z-index:0;
}
<div class="carousel-links">
1
2
3
4
</div>
<div class="carousel">
<div class="card" id="card1">1</div>
<div class="card" id="card2">2</div>
<div class="card" id="card3">3</div>
<div class="card" id="card4">4</div>
</div>
I'm trying to create a skewed section with a picture background. The point is that I want this background with the skew of the parent cancelled. I tried to achieve this with a pseudo-element.
I don't understand why the overflow:hidden of the parent does not affect the ::after element. Could someone help?
.main::after {
content:"";
background: url("https://images.unsplash.com/photo-1420310414923-bf3651a89816?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=47f355d1a7520ad5f1718e9388dd4967");
background-size:cover;
position:absolute;
display:block;
width: 110%;
height:110%;
transform: rotateZ(5deg) skew(5deg);
Here is the code and example: http://codepen.io/anon/pen/jWEZxK
Thanks in advance
Chris.
Try to this
Demo
* {
margin:0;
padding:0;
/*height:100%;*/
}
body {
background: #272727;
}
section {
width:100%;
min-height:500px;
transform: rotateZ(-5deg) skew(-5deg);
}
.main {
background-color: crimson;
overflow:hidden;
position:relative;
z-index:1;
}
.main::after {
content:"";
background: url("https://images.unsplash.com/photo-1420310414923-bf3651a89816?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=47f355d1a7520ad5f1718e9388dd4967");
background-size:cover;
position:absolute;
display:block;
left:-10%;
right:-10%;
top:-10%;
bottom:-10%;
transform: rotateZ(5deg) skew(5deg);
z-index:2;
}
<section class="main">
</section>
the after pseude needs the same deffinitions as parent element .. to we just repeat declarations..
http://codepen.io/mkdizajn/pen/GogQev?editors=110
overflow:hidden;
transform: rotateZ(0deg) skew(0deg); }
cheers :)
I am stuck here. Please help.
I want to make the following through css.
But when I use CSS positioning, I am getting this output
The fourth(GREEN) layer should go under first layer(BLUE) which is not happening.
This is the code I used.
HTML:
<div class="box1">
</div>
<div class="box2">
</div>
<div class="box3">
</div>
<div class="box4">
</div>
CSS:
div{
height:100px;
width:100px;
border:solid 1px;
}
.box1{
position:relative;
left:500px;
background-color:#00d8ff;
}
.box2{
position:relative;
left:570px;
top:-30px;
background-color:#f6ff00;
}
.box3{
position:relative;
left:500px;
top:-60px;
background-color:#ff69fa;
}
.box4{
position:relative;
left:430px;
top:-230px;
background-color:#24ff00;
}
JSFiddle: http://jsfiddle.net/rkubs/
Even I tried to use Z-index. But no use. Help me. Thanks in advance.
WORKING DEMO :before
senario:
Using only one pseudo-element :before you just need to set border-top and border-right then give it an absolute position on the bottom left of div2
With the same HTML code as OP all you need is a Pseudo-element :before or :after combine witn z-index. To make it easy i put numbers in your HTML.
Note: you habe to set position relative to the element with the pseudo, the set the top border and the right border you can skeep that using box-shadow too see WORKING DEMO WITH BOX-SHADOW.
HTML
<div class="box1">1
</div>
<div class="box2">2
</div>
<div class="box3">3
</div>
<div class="box4">4
</div>
CSS
div{
height:100px;
width:100px;
border:solid 1px;
}
.box1{
position:relative;
left:500px;
background-color:#00d8ff;
z-index:3;
}
.box2{
position:relative;
left:570px;
top:-30px;
background-color:#f6ff00;
z-index: 3;
}
.box2:before{
content: '';
position: absolute;
bottom: -2px;
left: -2px;
width: 32px;
height: 30px;
border-top: 1px solid black;
border-right: 1px solid black;
z-index: 14;
background-color: #ff69fa;
}
.box3{
position:relative;
left:500px;
top:-60px;
background-color:#ff69fa;
z-index:1;
}
.box4{
position:relative;
left:430px;
top:-230px;
background-color:#24ff00;
z-index:2;
}
WORKING DEMO WITH BOX-SHADOW
Here you just need to change the width and height of .box2.
senario:
you choose one div in my case div2 you don't set the background-color then reset the the borders border:none; .
Since you have set div width, height and position relative you can now set :before and 'after' width a 100% width and 50% height, one on the top and the other on the bottom, then for :before set border-top and for :after set border-bottom.
Now set for both of then border-left and border-right.
div{
height:100px;
width:100px;
border:solid 1px;
position:relative;
}
.box1{
left:500px;
background-color:#00d8ff;
z-index:3;
}
.box2{
left:570px;
top:-30px;
border:none;
}
.box2:before,.box2:after{
content: '';
position: absolute;
background-color:#f6ff00;
width: 100%;
height: 50%;
left: 0;
border-left:1px solid black;
border-right:1px solid black;
}
.box2:before{
top: 0;
z-index: 3;
border-top:1px solid black;
}
.box2:after{
bottom: 0;
z-index: 0;
border-bottom:1px solid black;
}
.box3{
left:500px;
top:-60px;
background-color:#ff69fa;
z-index:1;
}
.box4{
left:430px;
top:-230px;
background-color:#24ff00;
z-index:2;
}
WORKING DEMO :BEFORE :AFTER FLEXIBLE
I'm not sure you can do that with normal way, a little hack may be help.
What i do is to add another box right under .box1 with z-index above of all, and with size 50% of the parent.
HTML:
<div class="box1">
<div class="box1-fake"></div>
</div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
CSS:
.box1-fake{
background-color:#00d8ff;
position:absolute;
left: -1px;
top: -1px;
z-index: 1000;
width: 50%;
border-right: 0 none;
}
You could use clip on a pseudo element after the first box to get this working:
.box1:after {
content: "";
border:solid 1px;
background: #00d8ff;
height: 100%;
width: 100%;
position: absolute;
z-index: 1;
top: -1px;
left: -1px;
clip: rect(76px 32px 102px -1px);
}
FIDDLE
For more information about the css clip property see this mozilla page
It also has cross browser support
Split the left box in two sections, upper and lower section, and assign z-indexes accordingly.
How about somethign like this:
<div class="box2">
<div class="box-top"></div>
<div class="box-bot"></div>
</div>
## css ##
.box2 {
position: relative;
left: 570px;
top: -30px;
border: none;
}
.box-top {
z-index: 200;
position: relative;
border-bottom: none;
height: 50%;
background-color: #f6ff00;
}
.box-bot{
z-index: 200;
/* position: relative; */
left: 570px;
border-top: none;
height: 50%;
background-color: #f6ff00;
}
http://jsfiddle.net/a8fXP/30/
I am trying to make a div with transformation(CSS) stack up on top; here is the markup, I need only the green div to show up on top of blue div. Basically the blue is a masked layer and the green is a dialog that shows up on top of it.
I tried setting the z-index, which din't work. The blue always shows up on top of the green.
Also if I change the blue div to be the sibling of the the green div then it works, but I want to keep the mark up the same i.e the blue div is a sibling parent to green div
Any pointers?
Here is the js fiddle link...
http://jsfiddle.net/YRTxt/9/
CSS
#wrapper{
width:100%;
}
#red, #green{
height:200px;
width:400px;
}
#red{
background-color:red;
position:absolute;
-webkit-transform: scale(1);
}
#pink{
background-color:pink;
height:250px;
width:150px;
top: 50px;
position:absolute;
-webkit-transform: translate3d(0%,0px,0px);
-webkit-perspective: 1000;
}
#green{
background-color:green;
position:absolute;
-webkit-transform: translate3d(0,0,0);
top:100px;
right: 0px;
left: 0px;
z-index: 1111;
}
#blue{
background-color: blue;
width: 100%;
height: 100%;
opacity: 0.8;
position: absolute;
top:0px;
right: 0px;
z-index: 100;
}
HTML
<div id="wrapper">
<div id="red">
<div id="pink">
<div id = "green"/>
</div>
</div>
</div>
<div id="blue">
</div>
For z-index to work you have to have a z-index for both elements. I updated the http://jsfiddle.net/rTkyR/, where I only added the z-index to the CSS two the blue and the green divs.
HTML
<div id="wrapper">
<div id="red">
<div id="pink">
<div id = "green"/>
</div>
</div>
</div>
<div id="blue">
</div>
CSS
#wrapper{
position:relative;
width:100%;
}
#red, #green{
height:200px;
width:400px;
}
#red{
background-color:red;
position:relative;
}
#pink{
background-color:pink;
height:250px;
width:150px;
top:50px;
right:20px;
position:absolute;
}
#green{
background-color:green;
position:absolute;
-webkit-transform: translate3d(0,0,0);
top:0px;
right: 0px;
left: 0px;
z-index: 1;
}
#blue{
background-color: blue;
width: 100%;
height: 100%;
opacity: 0.8;
position: absolute;
top:0px;
right: 0px;
z-index: 0;
}