Diagonal overlay on background image with double border - html

I'm trying to create an image like this in CSS.
I have the following code.
#sample {
height: 200px;
width: 300px;
background: url(https://placeholdit.imgix.net/~text?txtsize=28&bg=0099ff&txtclr=ffffff&txt=300%C3%97300&w=300&h=300&fm=png);
position: relative;
}
#overlay {
height: 300px;
width: 100px;
background: #444;
border-left: 3px solid green;
position: absolute;
right: -20px;
}
<div id="sample">
<div id="overlay">
</div>
</div>
Can I make such an structure using CSS alone ?

You need not use an overlay div. You can use an :after element to achieve the same.
Use overflow:hidden on parent and rotate the after element.
Shadow can be used for double border.
Here is a working example.
#sample {
height: 200px;
width: 300px;
background: url(https://placeholdit.imgix.net/~text?txtsize=28&bg=0099ff&txtclr=ffffff&txt=300%C3%97300&w=300&h=300&fm=png);
position: relative;
overflow: hidden;
}
#sample:after {
height: 300px;
width: 100px;
content: " ";
background: #444;
border-left: 3px solid green;
position: absolute;
right: -20px;
transform: rotate(25deg);
-webkit-box-shadow: -6px 0px 0px 0px rgba(68, 68, 68, 1);
-moz-box-shadow: -6px 0px 0px 0px rgba(68, 68, 68, 1);
box-shadow: -4px 0px 0px 0px rgba(68, 68, 68, 1);
}
<div id="sample">
</div>

To achieve the result parent div need to be set relative and then set it overflow hidden. To let rest of the child div will be invisible.
After that your child div use transform to rotate the element.
HTML
<div id="sample">
<div id="overlay">
</div>
</div>
CSS
#sample {
height: 200px;
width: 300px;
background: url(https://placeholdit.imgix.net/~text?txtsize=28&bg=0099ff&txtclr=ffffff&txt=300%C3%97300&w=300&h=300&fm=png);
position: relative;
overflow: hidden;
}
#overlay {
height: 300px;
width: 100px;
background: #444;
border-left: 3px solid green;
position: absolute;
right: -20px;
transform: rotate(25deg);
}
DEMO

Related

Crop div to sibling div

I have the following overlapping divs:
#circle {
width: 150px;
height: 150px;
background-color: rgba(0, 0, 0, .3);
position: absolute;
border-radius: 100%;
margin-top: 30px;
}
#rect {
margin-left: 20px;
width: 100px;
height: 100px;
border-radius: 5px;
background-color: lightblue;
display: inline-block;
}
<div id='wrapper'>
<div id='circle'></div>
<div id='rect'></div>
</div>
I want to make the circle div only appear inside of the rectangle div, but I cannot put one inside the other and use overflow. How can this be achieved?
If it's only about visual, use the circle as background of the div:
#rect {
margin-left: 20px;
width: 100px;
height: 100px;
border-radius: 5px;
background:radial-gradient(circle 75px at 55px 105px, rgba(0, 0, 0, .3) 99%,transparent);
background-color: lightblue;
display: inline-block;
}
<div id='wrapper'>
<div id='rect'></div>
</div>
This isn't very practical, but the only way to do this without changing the markup is to crop it with the parent wrapper using position: relative and overflow: hidden on the parent. Adjust the location of the circle with top: 30px and left: -20px.
The parent would also need to set the rounded corners with
border-radius: 5px.
Of course if this is just a background, then it should be set with a background radial gradient on the rectangle.
Example
#wrapper {
position: relative;
display: inline-block;
margin: 30px;
border-radius: 5px;
overflow: hidden;
}
#circle {
width: 150px;
height: 150px;
background-color: rgba(0, 0, 0, .3);
position: absolute;
top: 30px;
left: -20px;
border-radius: 100%;
}
#rect {
width: 100px;
height: 100px;
background-color: lightblue;
}
<div id="wrapper">
<div id="circle"></div>
<div id="rect"></div>
</div>

Trigger CSS :hover only when hovering over border box

I am creating a rectangular outline with a 5px thin border box around an empty <div>. When the user hovers over the border I want the border to change colour. That's all working fine, but I don't want the border to remain changed when the user's mouse is inside the <div> because it's no longer actually on the border.
See an example here:
https://jsfiddle.net/qbcc1trt/
.outer {
position: relative;
overflow: hidden;
display: inline-block;
}
.myborder {
content: '';
position: absolute;
bottom: 5%;
left: 20%;
width: 40%;
height: 50%;
box-shadow: inset 0px 0px 0px 5px rgba(0, 0, 0, 0.6);
}
.myborder:hover {
content: '';
position: absolute;
bottom: 5%;
left: 20%;
width: 40%;
height: 50%;
box-shadow: inset 0px 0px 0px 5px rgba(100, 200, 100, 0.6);
}
<div class="outer">
<img src="https://s-media-cache-ak0.pinimg.com/736x/ff/00/5e/ff005e0fa600c51c5e36f6059bbe6053.jpg">
<div class="myborder"></div>
</div>
Any way to accomplish this?
:hover events only work on the top most element (and the elements inside). So you can achieve this effect by making another div the same size as your myborder but subtracting the size of the border. Then place it directly above myborder.
This way, the hover event will trigger while over the border (box shadow in your case) but no the inside. See the demo below
.outer {
position: relative;
overflow: hidden;
display: inline-block;
}
.myborder {
position: absolute;
bottom: 5%;
left: 20%;
width: 40%;
height: 50%;
box-shadow: inset 0px 0px 0px 5px rgba(0, 0, 0, 0.6);
}
.hover-cover {
position: absolute;
bottom: calc(5% + 5px);
left: calc(20% + 5px);
box-shadow: none;
z-index: 1;
width: calc( 40% - 10px);
height: calc( 50% - 10px);
}
.myborder:hover {
box-shadow: inset 0px 0px 0px 5px rgba(100, 200, 100, 0.6);
}
<div class="outer">
<img src="https://s-media-cache-ak0.pinimg.com/736x/ff/00/5e/ff005e0fa600c51c5e36f6059bbe6053.jpg">
<div class="hover-cover"></div>
<div class="myborder"></div>
</div>
I know the answer has been marked as answered but I found a solution that doesn't use calc but nth-child instead which has better compatibility table than calc.
.outer {
position: relative;
overflow: hidden;
display: inline-block;
}
.myborder {
content: '';
position: absolute;
bottom: 5%;
left: 20%;
width: 40%;
height: 50%;
}
.myborder div:nth-child(1) {
box-shadow: inset 0px 0px 0px 5px rgba(0, 0, 0, 0.6);
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.myborder div:nth-child(1):hover {
box-shadow: inset 0px 0px 0px 5px rgba(100, 200, 100, 0.6);
}
.myborder div:nth-child(2) {
position: absolute;
top: 5px;
right: 5px;
bottom: 5px;
left: 5px;
}
<div class="outer"><img src="https://s-media-cache-ak0.pinimg.com/736x/ff/00/5e/ff005e0fa600c51c5e36f6059bbe6053.jpg">
<div class="myborder">
<div></div>
<div></div>
</div>
</div>
It's almost the same solution as the one provided by #Kevin:
https://jsfiddle.net/qbcc1trt/1/
The idea is to put two elements, one (B) above the other one (A), so when the user will :hover element B he will actually not :hover element A.
You need to make sure the element B is not inside element A
.outer {
position: relative;
overflow: hidden;
display: inline-block;
}
.borderContainer {
position: absolute;
bottom: 5%;
left: 20%;
width: 40%;
height: 50%;
}
.myborder {
content: '';
box-shadow: inset 0px 0px 0px 5px rgba(0, 0, 0, 0.6);
width: 100%;
height: 100%;
}
.inner {
position: absolute;
width: calc(100% - 5px * 2);
height: calc(100% - 5px * 2);
top: 5px;
left: 5px;
z-index: 100;
}
.myborder:hover {
content: '';
box-shadow: inset 0px 0px 0px 5px rgba(100, 200, 100, 0.6);
width: 100%;
height: 100%;
}
<div class="outer"><img src="https://s-media-cache-ak0.pinimg.com/736x/ff/00/5e/ff005e0fa600c51c5e36f6059bbe6053.jpg">
<div class="borderContainer">
<div class="myborder">
</div>
<div class="inner">
</div>
</div>
</div>
Note the I used here a parent container (which might be easier, depending on your solution).

Box-shadow of div over inner div

I have an outer div with box-shadow and I want this to appear over an inner div. But it always appears under it. The jsfiddle is here.
My HTML is:
<div class="wrapper">
<div class="inner">
</div>
</div>
And CSS:
.wrapper {
width: 200px;
height: 100px;
border: 1px grey solid;
box-shadow: inset 40px 0 10px -10px #bbbbbb;
}
.inner{
width: 180px;
height: 80px;
margin: 10px;
background-color: lightblue;
}
Is it possible to get it so that the box-shadow appears over the inner blue div? The semantics of the HTML cannot change.
Set the position of the child to relative and the z-index to -1:
.wrapper {
width: 200px;
height: 100px;
border: 1px grey solid;
box-shadow: inset 40px 0 10px -10px #bbbbbb;
}
.inner {
width: 180px;
height: 80px;
margin: 10px;
background-color: lightblue;
position:relative;
z-index:-1;
}
<div class="wrapper">
<div class="inner">
</div>
</div>
update the styles of inner class with position absolute and give z-index: -1;;
.inner {
width: 180px;
height: 80px;
margin: 10px;
background-color: lightblue;
position:relative;
z-index:-1;
}
Here is the updated jsFiddle
You can do what you are wanting without the inner container as well.
http://codepen.io/creativenauts/pen/rLWZqp
* {
box-sizing: border-box;
}
.wrapper {
width: 200px;
height: 100px;
border: 20px solid #fff;
background-color: lightblue;
box-shadow: 0px 0px 1px rgba(#000, 0.5);
position: relative;
&:before {
position: absolute;
content: '';
width: 100%;
height: 100px;
top: -20px;
left: -20px;
box-shadow: inset 40px 0 10px -10px #bbbbbb;
}
}

Creating box having css arrow using css3

.box {
position: relative;
margin: 18px;
width: 8em;
height: 6em;
border: 1px solid rgb(77, 77, 77);
color: #FF1919;
background-color: pink;
}
.box:hover {
width: 8em;
margin: 18px;
}
.box:before {
content: '';
position: relative;
width: 30%;
left: 18px;
right: 80%;
height: 40px;
top: 30%;
background: rgba(0, 0, 0, 0.1);
display: inline-block;
background-color: blue;
}
.box:after {
content: '';
position: absolute;
left: 43%;
top: 30%;
margin-top: -18px;
border-style: solid;
border-width: 40px;
border-color: transparent transparent transparent rgba(0, 0, 0, 0.1);
}
<div class="box"></div>
I have created one arrow and in that I want to highlight the arrow head with blue colour which is grey.
I also want to use this total arrow as a button to navigate to next scene page with html extension.
For that I am using:
<div style="position: absolute; right: 40px; bottom: 70px;">
<form action="abc.html" align="right" style="margin-right:100px ; display:inline">
<input type="submit" class="box"></input>
</form>
</div>
but it is taking a single part of that css object(rectangle) box and leaving other portions.
Ye u can simply using pseudo elemnts.
.arrow {
height: 50px;
width: 50px;
background: #0000ff;
margin: 20px;
position: relative;
}
.arrow:after {
content: '';
position: absolute;
top: -15px;
right: -80px;
width: 0;
height: 0;
border-top: 40px solid transparent;
border-left: 80px solid #0000ff;
border-bottom: 40px solid transparent;
}
.box {
width: 165px;
padding: 20px;
border: 1px solid #222;
background: #eee;
}
<a href="abc.html">
<div class="box">
<div class="arrow"></div>
</div>
</a>
Maybe you could use an HTML special character arrow sign like this ➧ ➧
This way you could play with the color, size etc. the way you like
Here is the code:
<div class="box">➧</div> this is for a separate div
And this is for an input. Please note that the type was changed to button
<div style="position: absolute; right: 40px; bottom: 70px;">
<form action="abc.html" align="right" style="margin-right:100px ; display:inline">
<input type="button" class="box" value="➧"></input>
</form>
And the CSS for both is
.box {
width:100px;
height:100px;
background-color:pink;
color:blue;
text-align:center;
font-size:100px;
line-height:100px;
}
You just need to change the property for the :after pseudo-element that represent the head
border-color: transparent transparent transparent rgba(0, 0, 255, 1);
.box {
position: relative;
margin: 18px;
width: 8em;
height: 6em;
border: 1px solid rgb(77, 77, 77);
color: #FF1919;
background-color: pink;
position: relative;
}
.box:before {
content: '';
position: absolute;
width: 30%;
left: 20%;
height: 40px;
top: 50%;
transform: translateY(-50%);
background: rgba(0, 0, 0, 0.1);
background-color: blue;
}
.box:after {
content: '';
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 50%;
/* before width 30% + before left position 20% */
border-style: solid;
border-width: 40px;
border-color: transparent transparent transparent rgba(0, 0, 255, 1);
}
<div class="box"></div>
For navigation you can add <a> tag in your html page and for color of the class .box:after change the border color as below:
HTML:
<div class="box"></div>
CSS:
.box:after {
content: '';
position: absolute;
left: 43%;
top: 30%;
margin-top: -18px;
border-style: solid;
border-width: 40px;
border-color: transparent transparent transparent **rgba(7, 17, 241, 1);** }
FIDDLE

How to get adaptive diagonal inside div? - CSS

I am trying to achieve this;
There is an inner div and outer div. Inner div is rotated 45deg. But I want inner div to transform according to outer div. That is, I can give fixed attributes to outer div only, and inner has to form a ^ according to outer div. How can I do this?
here is the html and css;
<div class="diva"><div class="divb"></div></div>
.diva{
height: 200px;
width: 300px;
background: #CCC;
}
.divb {
position: relative;
padding: 100px 0 0;
height: 100%;
width: 100%;
}
.divb:before {
content: '';
display: block;
width: 100%;
height: 100%;
border-left: solid 4px green;
border-top: solid 4px green;
border-bottom: solid 4px transparent;
border-right: solid 4px transparent;
transform: rotate(45deg);
}
here is the fiddle.
This is a tricky problem, but it is possible. Here is my code:
HMTL:
<div id="a"></div>
CSS:
#a {
position: relative;
background: #ffffff;
position:absolute;
top:50px;
left:50px;
}
#a:after, #a:before {
bottom: 100%;
left: 50%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
#a:after {
border-color: rgba(255, 255, 255, 0);
border-bottom-color: #ffffff;
border-width: 30px;
margin-left: -30px;
}
#a:before {
border-color: rgba(0, 255, 0, 0);
border-bottom-color: #00ff00;
border-width: 36px;
margin-left: -36px;
}
FIDDLE
I hope this works for you. Good luck!