CSS : corner cut div , filled and border - html

I trying to create this two corner cut div, one is filled , another is border, both with shadow.
However I facing an issue, which is for border shape corner, I unable to create border with corner cut.
I appreciate with any other idea to create this kind of filled shape and border shape.
.buttongroup {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
}
.buttongroup .gap {
width: 30px;
-webkit-box-flex: 0;
-ms-flex: none;
flex: none;
}
.neonbutton {
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex;
width: 100%;
position: relative;
}
.neonbutton .l {
width: 100%;
height: auto;
background-color: #37E8FC;
}
.neonbutton .r {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-align: start;
-ms-flex-align: start;
align-items: flex-start;
width: 30px;
-webkit-box-flex: 0;
-ms-flex: none;
flex: none;
}
.neonbutton .corner {
width: 0;
height: 0;
border-style: solid;
border-width: 25px 0 0 30px;
border-color: transparent transparent transparent #37E8FC;
}
.neonbutton .square {
height: 30px;
width: 30px;
background-color: #37E8FC;
}
.neonbutton .value {
position: absolute;
width: 100%;
height: 100%;
text-align: center;
color: #000;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
font-size: 17px;
font-weight: bold;
}
.neonbutton.outline .l {
background-color: transparent;
border: 2px solid #37E8FC;
border-right: none;
}
.neonbutton.outline .corner {
background-color: transparent;
}
.neonbutton.outline .square {
background-color: transparent;
border-right: 2px solid #37E8FC;
border-bottom: 2px solid #37E8FC;
}
<div class="buttongroup">
<div class="neonbutton">
<div class="l"></div>
<div class="r">
<div class="corner"></div>
<div class="square"></div>
</div>
<div class="value">Lorem</div>
</div>
<div class="gap"></div>
<div class="neonbutton outline">
<div class="l"></div>
<div class="r">
<div class="corner"></div>
<div class="line"></div>
<div class="square"></div>
</div>
<div class="value">Lorem</div>
</div>
</div>

I would do the first one like below:
.box {
--c:20px; /* control the cut */
font-size: 25px;
padding: 10px 30px;
display: inline-block;
position: relative;
z-index: 0;
filter: drop-shadow(0 0 5px #37E8FC)
}
.box:before {
content: "";
position: absolute;
z-index: -1;
inset: 0;
background: #37E8FC;
clip-path: polygon(0 0, calc(100% - var(--c)) 0, 100% var(--c), 100% 100%, 0 100%);
}
body {
background: #000;
}
<div class="box">some text</div>
And the second one:
.box {
--b:5px; /* control the border */
--c:20px; /* control the cut */
font-size: 25px;
padding: 10px 30px;
display: inline-block;
position: relative;
color:#fff;
z-index: 0;
filter: drop-shadow(0 0 5px #37E8FC)
}
.box:before {
content: "";
position: absolute;
z-index: -1;
inset: 0;
background: linear-gradient(to bottom left, #37E8FC 50%,#0000 50.5%) 100% 0/calc(var(--c) - 0.3*var(--b)) calc(var(--c) - 0.3*var(--b)) no-repeat;
border:var(--b) solid #37E8FC;
clip-path: polygon(0 0, calc(100% - var(--c)) 0, 100% var(--c), 100% 100%, 0 100%);
}
body {
background: #000;
}
<div class="box">some text</div>

Related

How can I align center (both vertical and horizontal) the triangle in the div#tag?

I am building a drawer with a tag.
When the tag is clicked, the div#mySidenav will be shown.
Here is my code:
.container {
background-color: #ff0000;
/* red*/
display: flex;
flex-direction: row;
flex-grow: 1;
height: 100%;
/* 100% Full-height */
position: fixed;
/* Stay in place */
top: 0;
/* Stay at the top */
left: 0;
width: 100%;
}
.sidenav {
background-color: green;
height: 100%;
margin: 0px;
overflow-x: hidden;
/* Disable horizontal scroll */
width: 1px;
}
.sideNavTag {
align-items: center;
display: flex;
flex-direction: column;
justify-content: center;
margin: 0px;
padding: 0px;
width: 20px;
}
div#tag {
align-content: center;
border: 1px solid yellow;
border-left: none;
border-radius: 0px 5px 5px 0px;
box-sizing: border-box;
cursor: pointer;
display: flex;
font-size: 20px;
justify-content: center;
left: 4.5px;
margin: 0px;
padding: 0px;
position: relative;
width: 20px;
}
div#a {
border-bottom: 1px solid yellow;
border-left: 1px solid yellow;
border-radius: 0px 0px 0px 5px;
box-sizing: border-box;
display: flex;
height: calc(50% - 10px);
margin: 0px;
position: relative;
top: 1px;
width: 20px;
}
div#c {
border-top: 1px solid yellow;
border-left: 1px solid yellow;
border-radius: 5px 0px 0px 0px;
height: calc(50% - 10px);
margin: 0px;
position: relative;
top: -1px;
width: 20px;
}
<div class="container">
<div id="mySidenav" class="sidenav">1</div>
<div class="sideNavTag">
<div id="a"></div>
<div id="tag">
▶
</div>
<div id="c"></div>
</div>
<div>3</div>
</div>
The div#a, div#tag and div#c are used to build the following layout:
How can I align center (both vertical and horizontal) the triangle in the yellow block (i.e. div#tag)?
I have used the display: flex; , align-items: center; and justify-content: center; CSS to align the triangle centre in the yellow block(i.e. div#tag). Unfortunately, it does not work.
How can I fix the problem?

Trying to move a paragraph to the next line under a button using CSS and flex box

Im playing around with buttons and css and I'm wondering if there is a way I can get this paragraph that says (Hover Me) to go under the button using flexbox. Sorry if that's a little too vague or I posted the code wrong, this is my first time. Any pointers or tips for the future are appreciated. Thanks.
/*Makes the background */
#background {
position: absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
z-index: -1;
}
/* Makes the background black when the button is hovered */
#button:hover~#background {
background-color: black;
}
/* Centers the button and the paragraph */
section {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
button {
display: flex;
align-items: center;
justify-content: center;
height: 80px;
width: 40px;
border: 1px solid royalblue;
background-color: skyblue;
transition: 1s;
border-radius: 10px;
margin-right: 15px;
}
button:hover {
background-color: indigo;
color: white;
box-shadow: 3px -4px 10px GREY;
transform: translateY(0.25em);
}
<section>
<button id="button">Lights
<br>Off!</br>
</button>
<p>(Hover Me)</p>
<div id="background"></div>
</section>
Try to add flex-direction: column; in section
/*Makes the background */
#background {
position:absolute;
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
z-index: -1;
}
/* Makes the background black when the button is hovered */
#button:hover ~ #background {
background-color: black;
}
/* Centers the button and the paragraph */
section {
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
button {
display: flex;
align-items: center;
justify-content: center;
height:80px;
width: 40px;
border: 1px solid royalblue;
background-color: skyblue;
transition: 1s;
border-radius: 10px;
margin-right: 15px;
}
button:hover {
background-color: indigo;
color: white;
box-shadow: 3px -4px 10px GREY;
transform: translateY(0.25em);
}
<section>
<button id="button">Lights
<br>Off!</br>
</button>
<p>(Hover Me)</p>
<div id="background"></div>
</section>

Why `Box-shadow` Is not displayed at the bottom in IE11?

I added box-shadow using pseudo selector to a display: flex; flex-flow: row wrap; element it's working in chrome and safari but in IE11 it get floats to the right side not the bottom, I think its because of flex-flow: row wrap;. any thoughts on whats goin on?
.main {
max-width: 1200px;
overflow: hidden;
height: 600px;
}
img {
display: block;
}
.hero-image {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
width: 100%;
position: relative;
}
.hero-image::after {
display: block;
position: absolute;
content: '';
width: 100%;
-webkit-box-shadow: 0 -5px 50px #000;
box-shadow: 0 -5px 50px #000;
height: 100%;
z-index: 99;
}
.div--1 {
flex-basis: 100%;
order: 1;
height: auto;
}
.div--2 {
background-color: #333d47;
padding: 10px 40px;
line-height: 1;
flex-basis: 100%;
text-align: center;
color: #FFF;
order: -1;
}
<div class="main">
<div class="hero-image">
<div class="div--1">
<img src="https://picsum.photos/1200/300?image=0" />
</div>
<div class="div--2">some text here</div>
</div>
</div>
You are just missing a top: 0; on .hero-image::after. Otherwise the shadow will be pulled down by the text and the image.
.main {
max-width: 1200px;
overflow: hidden;
height: 600px;
}
img {
display: block;
}
.hero-image {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
width: 100%;
position: relative;
}
.hero-image::after {
display: block;
position: absolute;
top: 0;
content: '';
width: 100%;
-webkit-box-shadow: 0 -5px 50px #000;
box-shadow: 0 -5px 50px #000;
height: 100%;
z-index: 99;
}
.div--1 {
flex-basis: 100%;
order: 1;
height: auto;
}
.div--2 {
background-color: #333d47;
padding: 10px 40px;
line-height: 1;
flex-basis: 100%;
text-align: center;
color: #FFF;
order: -1;
}
<div class="main">
<div class="hero-image">
<div class="div--1">
<img src="https://picsum.photos/1200/300?image=0" />
</div>
<div class="div--2">some text here</div>
</div>
</div>
The shadow is over the image:
.main {
max-width: 1200px;
overflow: hidden;
height: 600px;
}
img {
display: block;
}
.hero-image {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
width: 100%;
position: relative;
}
.div--1::after {
display: block;
position: relative;
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(0, rgba(0, 0, 0, 0)), to(#000));
background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0, #000 100%);
margin-top: -120px;
height: 120px;
width: 100%;
content: '';
}
.div--1 {
flex-basis: 100%;
order: 1;
height: auto;
}
.div--2 {
background-color: #333d47;
padding: 10px 40px;
line-height: 1;
flex-basis: 100%;
text-align: center;
color: #FFF;
order: -1;
}
<div class="main">
<div class="hero-image">
<div class="div--1">
<img src="https://picsum.photos/1200/300?image=0" />
</div>
<div class="div--2">some text here</div>
</div>
</div>

CSS style effect involving z-index and transparency

I'm trying to achieve a design close to the snippet here. My problem is that I can't find a way to replace the blue background of .title by a simple transparency (so that the container's background stays visible). If I simply remove the blue background, the border becomes visible where .title is.
Also the "title" is generated by JS so I can't reliably predict the length of div as it may slightly vary depending on the situation.
.container {
width: 350px;
height: 250px;
display: flex;
justify-content: center;
align-items: center;
position: relative;
background: url('https://i.pinimg.com/736x/94/90/19/9490199f30fc9db039de091205e73be6--backgrounds-wallpapers-phone-backgrounds.jpg');
}
.zone {
position: relative;
display: flex;
justify-content: center;
align-items: center;
margin: 0 0 20px 0;
text-align: center;
}
.title {
position: relative;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: 10;
}
.title span {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0 10px;
height: 20px;
color: hsla(200, 70%, 20%, 1);
cursor: default;
background: hsla(200, 70%, 55%, 1);
}
.content {
position: relative;
display: flex;
justify-content: center;
align-items: center;
padding: 30px 30px 20px 30px;
width: 200px;
border: 0.1rem solid hsla(200, 70%, 20%, 1);
border-radius: 0rem;
margin-top: 10px;
}
<div class="container">
<div class="zone">
<div class="title">
<span>Text Title</span>
</div>
<div class="content"></div>
</div>
</div>
Does anyone have an idea how to achieve what I'm trying to do ? Please let me know if my explanation is too brief or unclear.
Thank you !
You can achieve that with pseudo elements. Take a look at this:
.container {
width: 350px;
height: 250px;
display: flex;
justify-content: center;
align-items: center;
position: relative;
background: url('https://i.pinimg.com/736x/94/90/19/9490199f30fc9db039de091205e73be6--backgrounds-wallpapers-phone-backgrounds.jpg');
}
.zone {
position: relative;
display: flex;
justify-content: center;
align-items: center;
margin: 0 0 20px 0;
text-align: center;
}
.title {
position: relative;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: 10;
}
.title span {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0 10px;
height: 20px;
color: hsla(200, 70%, 20%, 1);
cursor: default;
}
.title span::before,
.title span::after{
content: "";
height: 2px;
position: absolute;
background: hsla(200, 70%, 20%, 1);
width: calc(50% - 40px);
top: 9px;
}
.title span::before{
left: 0;
}
.title span::after{
right: 0;
}
.content {
position: relative;
display: flex;
justify-content: center;
align-items: center;
padding: 30px 30px 20px 30px;
width: 200px;
border-right: 0.1rem solid hsla(200, 70%, 20%, 1);
border-left: 0.1rem solid hsla(200, 70%, 20%, 1);
border-bottom: 0.1rem solid hsla(200, 70%, 20%, 1);
border-radius: 0rem;
margin-top: 10px;
}
<div class="container">
<div class="zone">
<div class="title">
<span>Text Title</span>
</div>
<div class="content"></div>
</div>
</div>
You could try to use a fieldset with a legend instead of a div:
https://jsfiddle.net/v9p60p6g/1/
<html>
<head>
<style>
.container {
width: 350px;
height: 250px;
display: flex;
justify-content: center;
align-items: center;
position: relative;
background: url('https://i.pinimg.com/736x/94/90/19/9490199f30fc9db039de091205e73be6--backgrounds-wallpapers-phone-backgrounds.jpg');
}
fieldset {
border: solid black 2px;
}
legend {
}
</style>
</head>
<body>
<div class="container">
<fieldset>
<legend>Testtitel</legend>
Content
</fieldset>
</div>
</body>
</html>
You can get the desired effect by adding more elements
.container {
width: 350px;
height: 250px;
display: flex;
justify-content: center;
align-items: center;
position: relative;
background: url('https://i.pinimg.com/736x/94/90/19/9490199f30fc9db039de091205e73be6--backgrounds-wallpapers-phone-backgrounds.jpg');
}
.zone {
position: relative;
display: flex;
justify-content: center;
align-items: center;
margin: 0 0 20px 0;
text-align: center;
}
.title {
position: relative;
display: flex;
justify-content: center;
align-items: center;
position: absolute;
top: 0;
left: 0;
right: 0;
z-index: 10;
}
.title__text {
flex: 0 0 auto;
padding: 0 10px;
height: 20px;
color: hsla(200, 70%, 20%, 1);
cursor: default;
/* background: hsla(200, 70%, 55%, 1); */
}
.title__border {
flex: 1;
border-top: 0.1rem solid hsla(200, 70%, 20%, 1);
}
.content {
position: relative;
display: flex;
justify-content: center;
align-items: center;
padding: 30px 30px 20px 30px;
width: 200px;
border: 0.1rem solid hsla(200, 70%, 20%, 1);
border-top: 0.1rem solid transparent;
border-radius: 0rem;
margin-top: 10px;
}
<div class="container">
<div class="zone">
<div class="title">
<span class='title__border'></span>
<span class='title__text'>Text Title</span>
<span class='title__border'></span>
</div>
<div class="content"></div>
</div>
</div>
And don't use selectors like .title span. They do not target specific element and styles used by them cannot be reused somewhere else, which means excessive code duplication. Element selectors (like .title span) are also likely to cause problems (you are selecting all spans in .title element) whenever you change your code (adding another span with different styles is hard), which means even more duplicated code! Duplicated code = more complex code = code that is harder to maintain!
You should get BEM or SMACSS or any other methodology (you may even create your own).

how to stretch selected menu item to the left edge of the window?

I have a block with several items. When I click on the menu item it is highlighting and extending to the left border of the window.
I did this with the help of an absolutely positioned element, and set the width to 1000px, but this option does not work. This red bar should rest against the edge of the window at any resolution.
html
<div class="flex-menu-area">
<div class="container">
<div class="flex-menu">
<div class="left-flex-column">
<div class="flex-menu-select"><span>item 1</span></div>
<div class="flex-menu-select"><span>item 2</span></div>
<div class="flex-menu-select"><span>item 3</span></div>
</div>
<div class="right-left-column">
<div class="object"><span>item1content</span></div>
<div class="object"><span>item1content</span></div>
<div class="object"><span>item1content</span></div>
<div class="object"><span>item1content</span></div>
<div class="object"><span>item1content</span></div>
</div>
</div>
</div>
</div>
css
.flex-menu-area {
background: #fff;
width: 100%;
height: 512px;
.flex-menu {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
height: 100%;
.left-flex-column {
max-width: 256px;
width: 100%;
outline: 1px solid gray;
height: 512px;
.flex-menu-select {
font-size: 20px;
line-height: 26px;
font-weight: 600;
text-align: left;
color: $text-color;
padding-top: 43px;
padding-bottom: 43px;
max-width: 100%;
border-bottom: 1px solid gray;
position: relative;
&:hover {
background: #ccc;
&:before {
position: absolute;
width: 1000px;
height: 100%;
content: "";
display: block;
top: 0px;
left: -1000px;
background: red;
}
}
}
}
.right-left-column {
outline: 1px solid gray;
height: 512px;
width: 884px;
background: #fff;
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
background: #eee;
.object {
outline: 1px solid red;
font-size: 20px;
line-height: 40px;
}
}
}
}
Solution:
&:before {
position: absolute;
width: 100vw;
right: 0;
height: 100%;
content: "";
display: block;
top: 0px;
background: #fff;
z-index: -1;
}
Set the width and left values of your &:before to:
width: calc((100vw - 100%) /2);
left: calc(0 - ((100vw - 100%) /2));
I think that should help, but I don't have access to a screen large enough to test right now so apologies if my calcs are slightly off.