Tell me, can I set the background to the border formed in the following way?
https://jsfiddle.net/2Lous8vq/1/
.object {
position: relative;
width: 300px;
height: 0px;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid red;
background: transparent;
}
.object:after {
content: '';
position: absolute;
top: 2px;
left: calc(2.45px - 50px);
width: calc(300px - 2 * 1.4px);
height: 0px;
border-left: 49px solid transparent;
border-right: 49px solid transparent;
border-bottom: calc(100px - 2px) solid white;
background: transparent;
}
<div class="object"></div>
It's probably worth using the custom border-image, but it seemed to me that this still does not have enough functionality.
I want instead of a white color on the tab to display the image background (for example, https://cdn.pixabay.com/photo/2016/12/02/17/39/texture-1878273__340.jpg)
You can use multiple background and gradient:
.object {
width: 300px;
height: 100px;
background:
linear-gradient(to bottom left,#fff 49%,red 49%,red 51%,transparent 0) 100% 0/40px 100% no-repeat,
linear-gradient(to bottom right,#fff 49%,red 49%,red 51%,transparent 0) 0 0/40px 100% no-repeat,
linear-gradient(red,red) 0 0/100% 2px no-repeat,
url(https://cdn.pixabay.com/photo/2016/12/02/17/39/texture-1878273__340.jpg)0 0/cover no-repeat;
}
<div class='object'></div>
Another idea with clip-path:
body {
background:yellow;
}
.object {
width: 300px;
height: 100px;
border-bottom:none;
background:
linear-gradient(red,red) 0 0/100% 2px no-repeat,
linear-gradient(to bottom left,red 51%,transparent 51.5%) 100% 0/60px 100% no-repeat,
linear-gradient(to bottom right,red 51%,transparent 51.5%) 0 0/60px 100% no-repeat,
url(https://cdn.pixabay.com/photo/2016/12/02/17/39/texture-1878273__340.jpg)0 0/cover no-repeat;
-webkit-clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
clip-path: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
}
<div class='object'></div>
UPDATE
Another way more supported that rely on more elements:
body {
background:yellow;
}
* {
box-sizing:border-box;
}
.object {
width: 300px;
height: 100px;
border-bottom:none;
font-size:0;
}
.object .left,
.object .right {
width:50%;
display:inline-block;
height:100%;
border-top:2px solid red;
position:relative;
overflow:hidden;
}
.object .left {
border-left:2px solid red;
transform:skew(-20deg);
transform-origin:bottom left;
}
.object .right {
border-right:2px solid red;
transform:skew(20deg);
transform-origin:bottom right;
}
.object .left:before {
content:"";
position:absolute;
top:0;
left:-20px;
bottom:0;
right:-20px;
transform:skew(20deg);
background:url(https://cdn.pixabay.com/photo/2016/12/02/17/39/texture-1878273__340.jpg);
}
.object .right:before {
content:"";
position:absolute;
top:0;
left:-20px;
bottom:0;
right:-20px;
transform:skew(-20deg);
background:url(https://cdn.pixabay.com/photo/2016/12/02/17/39/texture-1878273__340.jpg);
}
<div class='object'>
<div class="left"></div>
<div class="right"></div>
</div>
Related
I'm trying to do this
The main idea is to make the carousel inside this div which will contain images and text.
.background {
height: 657px;
/* background-color: red; */
background-image: linear-gradient(135deg, #D4B8CE 5%, #DEC2D8 100%);
}
.background:before {
content: '';
width: 100%;
height: .3%;
bottom: 20%;
position: absolute;
background-image: linear-gradient(to right, #B59AB0 5%, #CBB2C7 100%);
}
.background:after {
z-index: 9;
content: '';
background-image: linear-gradient(45deg, #D9BDD4 5%, #EBCFE5 100%);
width: 100%;
height: 20%;
position: absolute;
bottom: 0;
}
.listdiv {
z-index: 10;
position: absolute;
height: 80%;
bottom: 12%;
left: 40%;
width: 25%;
background-color: white;
background-image: url(https://i.pinimg.com/originals/93/34/c7/9334c7e1fb00a2b49b8c1d4504ec0a45.jpg);
background-size: contain;
background-position: center;
background-repeat: no-repeat;
box-shadow: 0px 6px 12px -6px #00000066;
}
.listdiv::before {
content: '';
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 404.8px 50px 44px 0;
border-color: transparent #9191913d transparent transparent;
line-height: 0px;
left: -15.5%;
filter: saturate(52);
filter: drop-shadow(-5px 4px 17px black)blur(8px);
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="background w-100 bg-red">
<div class="listdiv">
</div>
</div>
How I can realize this shadow like the above image?
Please run code snippet in full page mode to see the issue.
You can approximate this using pseudo element, gradient and some filter.
Play with the different values until you get what you want:
body {
background:pink;
margin:0;
padding-bottom:100px;
}
.container {
padding:20px;
background:#e4a8b3;
position:relative;
z-index:-1;
}
.box {
background:white;
width:200px;
height:300px;
margin:0 auto -50px;
border:1px solid grey;
position:relative;
}
/* Relevant code start here */
.box:before,
.box:after {
content:"";
position:absolute;
z-index:-1;
right:98%;
width:70px;
filter:blur(4px);
}
.box:before {
bottom:30px;
top:0;
background:
linear-gradient(to bottom right,transparent 45%,rgba(0, 0, 0, 0.4) 70%)
bottom / 100% 115%;
}
.box:after {
height:32px;
bottom:0;
background:
linear-gradient(to top right,transparent 45%,rgba(0, 0, 0, 0.4) 70%)
top / 100% 115%;
}
/**/
<div class="container">
<div class="box"></div>
</div>
You can optimize the code to use only one pseudo element:
body {
background:pink;
margin:0;
padding-bottom:100px;
}
.container {
padding:20px;
background:#e4a8b3;
position:relative;
z-index:-1;
}
.box {
background:white;
width:200px;
height:300px;
margin:0 auto -50px;
border:1px solid grey;
position:relative;
}
/* Relevant code start here */
.box:before {
content:"";
position:absolute;
z-index:-1;
right:98%;
width:70px;
top:0;
bottom:0;
filter:blur(4px);
background:
linear-gradient(to top right,transparent 45%,rgba(0, 0, 0, 0.4) 70%)
bottom -10px center / 100% calc(30px + 10px),
linear-gradient(to bottom right,transparent 45%,rgba(0, 0, 0, 0.4) 70%)
top -20px center / 100% calc(100% - 30px + 20px);
background-repeat:no-repeat;
}
/**/
<div class="container">
<div class="box"></div>
</div>
I have a gradient which I want to start from left top, it's endpoint can be left as is.
Here are my current testing scenario's:
.test-1{
height: 200px;
border: 1px solid red;
}
.test-2{
height: 400px;
border: 1px solid blue;
}
.test-3{
height: 500px;
border: 1px solid red;
}
.test-4{
height: 600px;
border: 1px solid blue;
}
.gradient{
/* height: 100%;
width: 100%; */
padding: 0;
margin: 0;
background:
linear-gradient(190deg, #FFFFFF 22%, transparent 22.1%),
linear-gradient(90deg, #5c9c9b 0%, #8ccdcc 100%);
}
<div class="test-1 gradient"></div>
<div class="test-2 gradient"></div>
<div class="test-3 gradient"></div>
<div class="test-4 gradient"></div>
In .test-1, the div is too small, so its gradient is cutting off at the top. In this case, I would want it to end on the top left corner so it doesn't appear as if it's ending abruptly.
.test-2 is the same.
.test-3 is fine, it's not ending abruptly.
.test-4 is also fine, it not in the top left corner, but it's not cut off.
How can I cater this gradient to accommodate different div sizes?
You can adjust the top gradient to make it a triangular shape:
.test-1{
height: 80vh;
border: 1px solid red;
background:
/* position /width height */
linear-gradient(to bottom left,#fff 49.5%,transparent 50%) top/100% 30% no-repeat,
linear-gradient(90deg, #5c9c9b 0%, #8ccdcc 100%);
}
<div class="test-1 gradient"></div>
And if you want more space at the top add some padding
.test-1{
height: 80vh;
border: 1px solid red;
padding-top: 10vh;
background:
linear-gradient(to bottom left,#fff 49.5%,transparent 50%) top/100% 30% no-repeat,
linear-gradient(90deg, #5c9c9b 0%, #8ccdcc 100%) no-repeat;
background-origin:content-box;
}
<div class="test-1 gradient"></div>
Or add offset to the gradients:
.test-1{
height: 80vh;
border: 1px solid red;
background:
linear-gradient(to bottom left,#fff 49.5%,transparent 50%)left 0 top 20px/100% 30% no-repeat,
linear-gradient(90deg, #5c9c9b 0%, #8ccdcc 100%) left 0 top 20px no-repeat;
}
<div class="test-1 gradient"></div>
Another idea is to consider skew transformation
.test-1{
height: 80vh;
border: 1px solid red;
position:relative;
overflow:hidden;
z-index:0;
}
.test-1:before {
content:"";
position:absolute;
z-index:-1;
top:20px; /* Control the space */
bottom:0;
left:0;
right:0;
background:linear-gradient(90deg, #5c9c9b 0%, #8ccdcc 100%);
transform:skewY(8deg);
transform-origin:left;
}
<div class="test-1 gradient"></div>
In the gradient can use vh instead of %
.test-1{
height: 200px;
border: 1px solid red;
}
.test-2{
height: 400px;
border: 1px solid blue;
}
.test-3{
height: 500px;
border: 1px solid red;
}
.test-4{
height: 600px;
border: 1px solid blue;
}
.gradient{
/* height: 100%;
width: 100%; */
padding: 0;
margin: 0;
background:
linear-gradient(190deg, #FFFFFF 60vh, transparent 34.1vh),
linear-gradient(90deg, #5c9c9b 0, #8ccdcc 100vh);
}
<div class="test-1 gradient"></div>
<div class="test-2 gradient"></div>
<div class="test-3 gradient"></div>
<div class="test-4 gradient"></div>
I am attempting to display an image, and want it to carry into a little triangle under the <div>. I have seen this question which drags the triangle across the whole page. I would like to display a triangle that only takes up a small space (like the image) Instead of the solid colored background, there's a background image.
div {
width: 100%;
background-image: url("https://www.shopmarriott.com/images/products/v2/xlrg/Marriott-platinum-stitch-bed-bedding-set-mar-101-st-gy_xlrg.jpg");
max-height: 200px;
padding: 75px;
position: relative;
background-size:cover;
padding-bottom:100px;
overflow:hidden;
}
div:after {
margin-left:-30px;
left: 50%;
content:'';
margin-left: -30px;
margin-top: 70px;
position:absolute;
border-left:30px solid #fff;
border-right:30px solid #fff;
border-top:30px solid transparent;
}
h1 {
color: white;
font-size: 36px;
text-align: center;
}
<div>
<h1>Sheets</h1>
</div>
You would have to use clip-path if your using a background image.
div {
background-image: url(https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg);
background-repeat: no-repeat;
background-size: cover;
width: 500px;
height: 500px;
-webkit-clip-path: polygon(0% 0%, 100% 0%, 100% 75%, 66% 75%, 50% 99%, 33% 75%, 0% 75%);
clip-path: polygon(0% 0%, 100% 0%, 100% 75%, 66% 75%, 50% 99%, 33% 75%, 0% 75%);
}
<div></div>
To help you create the size and style you want you can use this online Clippy tool (hint: select the "Message" pre-made shape and play with that)
.container {
position:relative;
background-color:#e15915;
height:320px !important;
width:100% !important;
}
.container:after {
content:'';
position: absolute;
top: 100%;
left: 0;
right: 0;
margin: 0 auto;
width: 0;
height: 0;
border-top: solid 50px #e15915;
border-left: solid 50px transparent;
border-right: solid 50px transparent;
}
http://jsfiddle.net/9AbYc/1/
I am looking to achieve this style with css
So far I have done:
.file {
width: 279px;
height: 326px;
background: linear-gradient(-135deg, transparent 66px, #A1A1A4 40px);
position: relative;
}
.file::before,
.file::after {
content: '';
position: absolute;
top: 0;
right: 0;
border-color: transparent;
border-style: solid;
}
.file::before {
border-top: 90px solid transparent;
border-left: 90px solid transparent;
}
.file::after {
margin-top: -2.6px;
width: 0;
height: 0;
border-bottom: 93px solid #281EBE;
border-right: 94px solid transparent;
}
<div class="file">
</div>
And it looks like this
The angle of triangle is not exactly 90deg. And how do I have that transparent spacing between the blue triangle and grey rectangle?
I would go with only linear gradient like this:
body {
background:pink;
}
.file {
width:300px;
height:600px;
background:
linear-gradient(to bottom left,transparent 50%,blue 50%) 100% 0/47px 47px no-repeat,
linear-gradient(grey,grey)0 0/calc(100% - 50px) 100% no-repeat,
linear-gradient(grey,grey)0 50px/100% 100% no-repeat;
}
<div class="file">
</div>
And if you want the border around the grey part you can add more gradient like this:
body {
background:pink;
}
.file {
width:300px;
height:600px;
background:
linear-gradient(to bottom left,transparent 50%,blue 50%) 100% 0/47px 47px no-repeat,
linear-gradient(grey,grey)0 2px/calc(100% - 52px) 100% no-repeat,
linear-gradient(grey,grey)0 52px/calc(100% - 2px) 100% no-repeat,
linear-gradient(#000,#000)0 0/calc(100% - 50px) 100% no-repeat,
linear-gradient(#000,#000)0 50px/100% 100% no-repeat;
border-left:2px solid #000;
border-bottom:2px solid #000;
}
<div class="file">
</div>
And to easily handle the shape you can use CSS variables:
body {
background:pink;
}
.file {
--d:50px;
width:150px;
height:200px;
display:inline-block;
background:
linear-gradient(to bottom left,transparent 50%,blue 50%) 100% 0/calc(var(--d) - 3px) calc(var(--d) - 3px) no-repeat,
linear-gradient(grey,grey)0 2px/calc(100% - var(--d) - 2px) 100% no-repeat,
linear-gradient(grey,grey)0 calc(var(--d) + 2px)/calc(100% - 2px) 100% no-repeat,
linear-gradient(#000,#000)0 0/calc(100% - var(--d)) 100% no-repeat,
linear-gradient(#000,#000)0 var(--d)/100% 100% no-repeat;
border-left:2px solid #000;
border-bottom:2px solid #000;
}
<div class="file">
</div>
<div class="file" style="--d:20px">
</div>
<div class="file" style="--d:110px">
</div>
I don't know if this is duplicated or not, but I searched but couldn't find anything.
I'm trying to do a div with a half circle in the middle of the top border like the picture bellow:
Th black square is a div (intended to be a modal) and in the middle the border is cut with a circle. The red part is the page background (can be anything... images, text...).
How can I do this in html/css? I'm trying to avoid images to do this!!
Thank you
You can try this...
body{
background-color:#333;
passing:0px;
height:0px;
}
#app{
background:#333 url('https://source.unsplash.com/random') no-repeat;
background-size:cover;
width:360px;
height:560px;
position:relative;
overflow:hidden;
}
.app-bar{
width:100%;
height:50px;
position:absolute;
bottom:0px;
left:0;
}
.app-bar .bar{
line-height:50px;
position:relative;
width:100%;
height:50px;
background-image: radial-gradient(circle 35px at 315px 0, transparent 700px, #f44336 50px);
}
.app-bar .bar i{
color:#FFF;
display:block;
line-height:50px;
float:left;
width:50px;
text-align:center;
cursor:pointer;
margin-top:0px;
}
.app-bar .bar i:hover{
background-color:rgba(0,0,0,.1);
}
.app-bar .bar button{
padding:0px;
box-sizing:border;
text-align:center;
margin:0px;
bordeR:0px;
outline:0px;
width:60px;
height:60px;
line-height:60px;
cursor:pointer;
color:#FFFFFF;
display:block;
border-radius:50%;
position:absolute;
top:-30px;
left:100%;
margin-left:-75px;
background-color:#f44336;
transition: all .2s ease;
}
.app-bar .bar button span{
line-height:60px;
font-size:30px;
}
.app-bar .bar button:hover{
transform:rotate(45deg);
transition: all .2s ease;
}
<div id="app">
<div class="app-bar">
<div class="bar">
<i class="material-icons">menu</i>
<i class="material-icons">search</i>
<button class="button">
<span class="material-icons">add</span>
</button>
</div>
</div>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/material-design-icons/3.0.1/iconfont/material-icons.min.css" >
One way of doing it:
* {margin: 0; padding: 0; box-sizing: border-box}
html, body {height: 100%}
body {
display: flex;
justify-content: center;
align-items: center;
background: #f00;
}
.black {
display: flex;
justify-content: center;
width: 200px;
height: 200px;
background: #000;
}
.white {
position: relative;
top: -25px;
width: 50px;
height: 50px;
border: 2px solid #f00;
border-radius: 50%;
background: #fff;
}
<div class="black">
<div class="white"></div>
</div>
And the "starter kit" solution you'd like to have:
* {margin: 0; padding: 0; box-sizing: border-box}
html, body {height: 100%}
body {
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(to bottom left, Navy, Tomato, Skyblue);
background-repeat: no-repeat;
background-attachment: fixed;
}
.outer {
display: flex;
flex-direction: column;
justify-content: space-evenly;
align-items: center;
width: 275px;
height: 550px;
background: linear-gradient(Navy 33.33%, Tomato 66.66%, Skyblue 100%);
box-shadow: 0 15px 15px #000;
}
.outer > span {color:#fff}
.outer > .inner {
display: flex;
flex-direction: column;
justify-content: space-evenly;
align-items: center;
position: relative;
padding-top: 20px;
width: 225px;
height: 275px;
border-radius: 5px;
background: #fff;
box-shadow: 0 10px 10px #000;
}
.outer > .inner > #user {
display: block;
position: absolute;
top: -35px;
width: 70px;
height: 70px;
border: 2px solid #fff;
border-radius: 50%;
background: Navy;
box-shadow: 0 0 0 10px Navy;
}
.outer > .inner > input[type=text],
.outer > .inner > #sign_in {
width: 80%;
padding: 5px;
}
.outer > .inner > #sign_in {
display: block;
padding: 10px 0;
color: #fff;
text-align: center;
text-decoration: none;
text-shadow: 1px 1px 1px #000;
background: Tomato;
box-shadow: 0 5px 5px #000;
}
<div class="outer">
<span>My Account</span>
<div class="inner">
<img src="http://www.ecovadis.com/wp-content/themes/ecovadis/images/Icon-user.png" alt="User" id="user">
<input type="text" placeholder="Username">
<input type="text" placeholder="Password">
Sign in
</div>
<span></span> <!-- just to make things easier -->
</div>
You can go on from here.
Thank you for all the help.
For my problem I found a solution in this post
here
and I adapted.
So for anyone that needs also the solution:
#wrapper {
width: 500px;
height:400px;
background: transparent;
border: 0;
/* Define half of half semi-cicle on the top for all */
background:
radial-gradient(circle at 0 100%, transparent 0, yellow 0) bottom left,
radial-gradient(circle at 100% 100%, transparent 0, yellow 0) bottom right,
radial-gradient(circle at 0 0, transparent 25%, yellow 15px) top right,
radial-gradient(circle at 100% 0, transparent 25%, yellow 15px) top left;
/*Define top half of half circle background for specific Safari 5.1- 6.0*/
background:
-webkit-radial-gradient(circle at 0 100%, transparent 0, yellow 0) bottom left,
-webkit-radial-gradient(circle at 100% 100%, transparent 0, yellow 0) bottom right,
-webkit-radial-gradient(circle at 0 0, transparent 25%, yellow 15px) top right,
-webkit-radial-gradient(circle at 100% 0, transparent 25%, yellow 15px) top left;
/*Define top half of half circle background for specific Opera 11.6-12.0*/
background:
-o-radial-gradient(circle at 0 100%, transparent 0, yellow 0) bottom left,
-o-radial-gradient(circle at 100% 100%, transparent 0, yellow 0) bottom right,
-o-radial-gradient(circle at 0 0, transparent 25%, yellow 15px) top right,
-o-radial-gradient(circle at 100% 0, transparent 25%, yellow 15px) top left;
/*Define top half of half circle background for specific Firefox 3.6-15*/
background:
-moz-radial-gradient(circle at 0 100%, transparent 0, yellow 0) bottom left,
-moz-radial-gradient(circle at 100% 100%, transparent 0, yellow 0) bottom right,
-moz-radial-gradient(circle at 0 0, transparent 25%, yellow 15px) top right,
-moz-radial-gradient(circle at 100% 0, transparent 25%, yellow 15px) top left;
/*repeat half of half circle*/
background-size: 51% 51%;
background-repeat: no-repeat;
border: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#content{
padding-top: 25%;
word-wrap: break-word;
}
<div id="wrapper" class="half-circle">
<div id="content">asdasdasdasdasdasdasdasdasdasdasdasdasdasdsdasdasdasdasdasdasdasdasdasdasdasdasdasdassdasdadasasdasdasdasdasd</div>
</div>