I want to render a box on another box's border, like shown in this image:
Expected Output
I tried doing this using flexbox, but couldn't come up with any solution.
How can I approach this design? Any help would be appreciated!
This is a reproduction as close as possible to that picture you showed.
The positioning is obtained using position:relative for the card container and position:absolute for its inner parts.
.card{
position:relative;
width: 400px;
height: 200px;
border: solid 2px gray;
border-radius: 15px;
padding: 5px 5px 5px 5px;
text-align: center;
background: linear-gradient(white 50%, #F1FAFF 50%);
margin-top: 100px;
}
.inner{
border: solid 1px lightgray;
border-top: none;
height: 80%;
width: calc(100% - 20px);
box-shadow: 0px 2px 2px lightgray;
position: absolute;
bottom: 10px;
left: 10px;
background: white;
}
.label{
position: absolute;
top: -15px;
left: 25px;
background: #F5F5F5;
padding: 5px 10px;
font-family: sans-serif;
font-weight: 600;
border-radius: 5px;
}
<div class="card">
<div class="label">13 Mar - 12 Apr</div>
<div class="inner">
</div>
</div>
That can be achieved using legend. If you want custom style, then use postiion: relative on parent div (what you call the box with border), use position: absolute on the child div and adjust top, left, margins or translate values.
You can use two div do to it.
first div with border
second div for shadow box
.outer{
border:2px solid #333;
width:200px;
height:150px;
border-radius:20px;
}
.inner{
-webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
width:180px;
height:130px;
margin:10px;
}
<div class="outer">
<div class="inner">
</div>
</div>
Related
Currently, I am playing with HTML and CSS and I wanted to make a icon from this image
the image is somewhat like that. I tried adding different shapes of ovals and circles inside the bigger circle but it did not work. For the shaded part, I used a box-shadow in styling it. There are already too many divs in my sample icon. I just want to have it simple and readable.
Here is my HTML structure:
<link rel="stylesheet" href="style.css">
<div class="cont">
<div class="icon2">
<div class="inner-circle"></div>
</div>
</div>
and here is my CSS:
.cont {
width: 190px;
height: 190px;
padding: 20px;
}
.icon2 {
position: relative;
border: 2px solid #353332;
width: 187px;
height: 184px;
border-radius: 50%;
background-color: #fff;
box-shadow: inset 20px 35px #1CAEE3;
transform: rotate(177deg);
}
.inner-circle {
border: 7px solid #353332;
width: 120px;
height: 183px;
background-color: #fff;
border-radius: 50% 50% 50% 49% / 60% 52% 40% 40%;
transform: rotate(240deg);
display: block;
margin: 6px 0px 4px 35px;
border-top: 0;
border-bottom: 0;
border-left: 0;
}
Can you explain me this and how can I come up with a solution to my problem? I'm stuck for hours and I just wanted to try it with pure HTML and CSS and not using photoshop.
You can easily do this with one element and radial-gradient. Simply adjust the percentage used inside the gradient to control the shape:
.box {
width:150px;
height:150px;
border-radius:50%;
border:4px solid;
background:
radial-gradient(circle at top left,transparent 59.4%,black 60% calc(60% + 4px),orange calc(60% + 5px));
}
<div class="box"></div>
You can also use box-shadow ;)
https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow
The box-shadow CSS property adds shadow effects around an element's frame. You can set multiple effects separated by commas. A box shadow is described by X and Y offsets relative to the element, blur and spread radii, and color.
demo aside your image:
div {
border: solid 6px;
display: inline-flex;
height: 200px;
width: 200px;
border-radius: 50%;
box-shadow: inset -50px -70px 1px -30px rgb(255, 127, 39), inset -56px -77px 1px -33px;
}
code {
font-size: 30px;
color: green;
margin: auto;
font-weight: bold;
}
div,
img {
vertical-align: middle;
}
<img src="https://i.stack.imgur.com/HRpQY.png">
<div><code>box-shadow</code></div>
another example :
div {
float:left;
height: 180px;
width: 180px;
margin: 1em;
box-sizing: border-box;
padding: 25px;
background: #F4E5D9;
box-shadow: inset -40px -40px 3px -20px #C5824D, inset 40px 40px 3px -20px #EABD9A, inset 0 0 2px 30px #AD6026, inset 0 0 0px 32px #705642, inset 0 -55px 3px 10px #705B4B, inset 0 55px 3px 10px #705B4B, 0 0 3px 2px #705B4B, 0 0 3px 4px #665447, 0 0 3px 7px #3F332A, 0 0 3px 9px #705642, 88px 90px 1px -86px gray, 87px 85px 2px -82px #F2C232, 85px 95px 2px -82px #A30700, 92px 92px 2px -82px #C5824D, 88px 90px 10px -70px white;
border-radius:50%;
display:flex;
flex-direction:column;
justify-content:center;text-align:center;
}
div + div {border-radius:4em /50%;
<div>
<p>inset shadow </p>
<p>border-radius </p>
<p>decreased shadow </p>
</div>
<div>
<p>inset shadow </p>
<p>border-radius </p>
<p>decreased shadow </p>
</div>
you may also draw citrus slices https://codepen.io/gcyrillus/pen/wutEK .
but SVG would be at best here ;)
You could make use of a pseudo element and have an overflow:hidden to hide the rest of the pseudo element's parts that fall outside of the div's 'outer circle'
div {
height: 200px;
width: 200px;
overflow: hidden;
border: 5px solid black;
background:orange;
border-radius: 50%;
position: relative;
}
div:after {
content: "";
position: absolute;
height: 100%;
width: 200%;
border: inherit;
border-radius: 50%;
background: white;
top: -20%;
left: -100%;
}
<div></div>
I want to make a background image to be seen over div. Anything that I've tried with z-index didn't helped me. Image itself has not standard shape and glowing border. As image ends ideally "logo2" should imitate that "glowing" by box-shadow parameter. But anything I've tried "logo2" always over "logo" crosses the image. This is how I want it to be like site.com/logo2.png
.logo {
background: url(site.com/logo.png) no-repeat;
height: 200px;
z-index:100;
position:relative;
}
.logo2 {
width: 100%;
height: 50px;
background-color: #000;
padding: 10px 0px 10px 0px;
border-radius: 10px;
border: 1px solid #7b0000;
box-shadow: 0px 0px 2px 2px #d09d00;
position:relative;
z-index:10;
<div class="logo">
<div class="logo2"></div>
</div>
I guess this is what you want. You can adjust width of .logo2 accordingly
.logo {
background: url(http://homeworld.su/logo.png) no-repeat;
height: 200px;
z-index:100;
position:relative;
}
.logo2 {
width: 20%;
height: 40px;
background-color: #000;
padding: 10px 0px 10px 0px;
border-radius: 10px;
border: 1px solid #7b0000;
box-shadow: 0px 0px 2px 2px #d09d00;
position:absolute;
top:10px;
left:495px;
<div class="logo">
<div class="logo2"></div>
</div>
Hello i have a problem with my styling have two divs witch height is auto for both but the thing is when the first div (.filter) height is changed the second div (.posts) goes down as much as height was changed (.filter height +50 , .post down +50px):
my css :
.fp {
position: relative;
width: 1050px;
height: auto;
background-color: red;
left: 170px;
}
.filter {
background-color: white;
position: relative;
width: 250px;
min-height: 300px;
height: auto;
top: 20px;
border-radius: 4px;
border: 1px solid #1a171a;
-webkit-box-shadow: 3px 3px 5px 0px rgba(0,0,0,0.6);
-moz-box-shadow: 3px 3px 5px 0px rgba(0,0,0,0.6);
box-shadow: 3px 3px 5px 0px rgba(0,0,0,0.6);
}
.posts {
background-color: white;
position: relative;
width: 750px;
height: auto;
float: right;
margin-top: -280px;
border-radius: 4px;
border: 1px solid #1a171a;
-webkit-box-shadow: 3px 3px 5px 0px rgba(0,0,0,0.6);
-moz-box-shadow: 3px 3px 5px 0px rgba(0,0,0,0.6);
box-shadow: 3px 3px 5px 0px rgba(0,0,0,0.6);
}
html :
<div class="fp">
<div class="filter">
</div>
<div class="posts">
</div>
</div>
Always prefer display: inline-block instead float. Floating breaks the normal flow of elements. Also, negative margin isn't a good practice. The declarations position: relative or position: absolute should be used only on specific cases, not to align all blocks.
https://jsfiddle.net/alexndreazevedo/vg9bajrL/
Add float: left to .filter, erase the negative margin-top from .posts and add overflow: hidden to .fp to have the container really covering both elements.
After all the comments, I've set up a complete solution for you here: http://codepen.io/anon/pen/ZWNXEN
It adds margins where necessary or desireable, defines both elements as float (left/right) and lets the container cover the child elements (overflow: hidden). Apart from that I removed position: relative, which is of no use in this context.
I want to apply a border radius to a box-shadow but not the div itself, so the end result will be a rounded box shadow on the left side with 90 degree angle div.
.div-to-style {
-webkit-box-shadow: -20px 0px 0px 0px blue;
-moz-box-shadow: -20px 0px 0px 0px blue;
box-shadow: -20px 0px 0px 0px blue;
border-radius: 8px 8px 8px 8px;
background-color: red;
width: 200px;
height: 50px;
margin-left:40px;
}
<div class="div-to-style">
</div>
<p>
Want the red section to have a straight border on the left
</p>
https://jsfiddle.net/alair016/vdcohttk/
The problem with this CSS is that the border-radius is applied to the box-shadow as well as the div on the left side.
The box shadow is not an element. You can't add border-radius to an effect.
Try a pseudo-element instead:
.div-to-style {
border-radius: 0 8px 8px 0;
background-color: red;
width: 200px;
height: 50px;
margin-left: 40px;
position: relative;
}
.div-to-style::before {
content: '';
position: absolute;
left: -20px;
width: 20px;
height: 100%;
background: blue;
z-index: -1;
border-radius: 8px 0 0 8px;
}
<div class="div-to-style">
</div>
Bonus Option: No pseudo-element - Gradient background
.div-to-style {
border-radius: 8px;
background: linear-gradient(to right, blue, blue 20px, red 20px);
width: 200px;
padding-left: 20px;
height: 50px;
margin-left: 40px;
position: relative;
}
<div class="div-to-style">
</div>
You can use a pseudo-element to create the shadow, and apply the border-radius to that pseudo-element.
Working Example:
.div-to-style {
background-color: red;
width: 200px;
height: 50px;
margin-left:40px;
}
.div-to-style:before {
content: '';
display: block;
width: 100%;
height: 100%;
position: relative;
z-index: -1;
-webkit-box-shadow: -20px 0px 0px 0px blue;
-moz-box-shadow: -20px 0px 0px 0px blue;
box-shadow: -20px 0px 0px 0px blue;
border-radius: 8px 8px 8px 8px;
}
<div class="div-to-style">
</div>
<p>
Want the red section to have a straight border on the left
</p>
The gist is, you need 2 divs. Add the box shadow and radius to the outer div, and the other background or border styles to the inner div.
.div-to-style {
-webkit-box-shadow: -20px 0px 0px 0px blue;
-moz-box-shadow: -20px 0px 0px 0px blue;
box-shadow: -20px 0px 0px 0px blue;
border-radius: 8px 8px 8px 8px;
margin-left: 40px;
}
.inner-style {
background-color: red;
width: 200px;
height: 50px;
}
<div class="div-to-style">
<div class="inner-style">
</div>
</div>
<p>
Want the red section to have a straight border on the left
</p>
Here is a code example:
https://jsfiddle.net/vdcohttk/2/
== Edit
If you're going to downvote, please write a comment explaining why. Thanks!
I have a few nested div blocks and my problem is that the last one left_navigation_container doesn't have a 7px spacing at the bottom margin and I'm not sure why (jsfiddle).
HTML:
<div class="left_navigation_outer">
<div class="left_navigation_header_outer">
<div class="left_navigation_header_logo">
<strong>Title</strong>
</div>
</div>
<div class="left_navigation_container">
</div>
</div>
CSS:
div.left_navigation_outer {
background: green;
background-repeat: repeat;
margin:10px;
-moz-box-shadow: 0px 0px 5px #ababab;
-webkit-box-shadow: 0px 0px 5px #ababab;
box-shadow: 0px 0px 5px #ababab;
}
div.left_navigation_header_outer {
background: blue;
background-repeat: repeat;
height: 50px;
border-top: 4px solid black;
}
div.left_navigation_header_logo {
line-height:50px;
color: #efefef;
text-shadow: 0 -1px #000;
text-align: center;
text-transform: uppercase;
}
div.left_navigation_container {
background: red;
background-repeat: repeat;
height: 50px;
margin: 7px;
}
Your problem is caused by the way of calculating margin for this element - it refers to the its siblings', not parent's position.
You can set margin for other div containing "TITLE" text and see same issue with margin-top.
EDIT: You can add <div style="width: 100%; height: 1px;"></div> after <div class="left_navigation_container"></div> to trigger bottom margin and make it visible.
You can fix that by giving div.left_navigation_outer a padding-bottom
Weird... not sure why but if you add a padding-bottom 1px to div.left_navigation_outer it fixes it - here's my fork of your fiddle
div.left_navigation_outer {
background: green;
background-repeat: repeat;
margin:10px;
-moz-box-shadow: 0px 0px 5px #ababab;
-webkit-box-shadow: 0px 0px 5px #ababab;
box-shadow: 0px 0px 5px #ababab;
padding-bottom:1px; /* tricky hack to get the bottom spacing */
}