CSS hamburger menu icon with different line widths - html

I've created a simple hamburger menu icon where I want the middle line to be slightly shorter than the other two. Can this be done without creating multiple divs? My current solution is done by multiple box-shadows, see my working example.
This is what I have vs what I want to achieve:
My CSS:
.menu-button:before {
content: "";
position: absolute;
left: 20px;
top: 20px;
width: 24px;
height: 4px;
background: #0e3c89;
box-shadow: 0 8px 0 0 #0e3c89, 0 16px 0 0 #0e3c89;
}
Thanks!

Yes, this can be done without extra markup. Here is one way you could do it:
.menu-button {
width: 20px;
height: 4px;
background: #0e3c89;
margin: 20px 0 0 20px;
}
.menu-button:before {
display: block;
content: "";
width: 28px;
height: 4px;
box-shadow: 0 -8px 0 0 #0e3c89, 0 8px 0 0 #0e3c89;
}
<div class="menu-button"></div>

Here is a way to make this shape with minimum possible markup:
Create a element with specific width / height having top / bottom borders.
Use linear-gradient() to draw the central bar and control its size with background-size and position with .background-position css properties.
Necessary HTML:
Only single element (Possibly having a class):
<div class="menu-button"></div>
Necessary CSS:
.menu-button {
// draws the central bar
background: linear-gradient(to right, #0e3c89, #0e3c89) no-repeat;
background-position: center left;
background-size: 85% 4px;
// draws the top / bottom bars
border: solid #0e3c89;
border-width: 4px 0;
height: 24px;
width: 28px;
}
Screenshot:
* {box-sizing: border-box;}
.menu-button {
background: linear-gradient(to right, #0e3c89, #0e3c89) no-repeat;
background-position: center left;
background-size: 85% 4px;
border: solid #0e3c89;
border-width: 4px 0;
height: 24px;
width: 28px;
}
<div class="menu-button"></div>

My suggestion (using flexbox):
.hamburger {
display: flex;
align-items: center;
width: 40px;
height: 23px;
cursor: pointer;
border-top: 6px solid #0e3c89;
border-bottom: 6px solid #0e3c89;
}
.hamburger::before {
content: "";
width: 70%;
border-bottom: 6px solid #0e3c89;
}
<span class="hamburger"></span>

Related

Need mirror css shadow

.hr-line {
margin: -30px auto 10px;
padding: 0;
height: 50px;
border: none;
border-bottom: 1px solid;
box-shadow: 0 20px 20px -20px;
width: 95%;
}
this is this line (highlighted in the screenshot)
you need to make the shadow up, as in the photo, just the opposite.
Please help, im newbie :DDDD
I'm sure there are other options, but makes sense to rotate it 180 degrees.
.hr-line {
margin: 30px auto -30px;
padding: 0;
height: 50px;
border: none;
border-bottom: 1px solid;
box-shadow: 0 20px 20px -20px;
width: 95%;
transform: rotate(180deg);
background: transparent;
}
text before
<div class="hr-line"></div>
text after, play with the margin: 30px auto -30px;

How to make an input text field like the one on the Tesla Cybertruck order website?

I want to make an input text field, like the one on https://www.tesla.com/en_gb/cybertruck/design#battery (it appears after clicking 'buy now') but I am unsure how to approach this.
I have tried adding border-radius but of course that only rounds the corners.
Below is my current code:
<style>
body {
background-color: black;
}
label {
color: white;
}
input {
width: 300px;
height: 40px;
border: solid white 1px;
background: transparent;
color: white;
font-family: 'Consolas';
font-size: 0.9em;
font-weight: bold;
padding: 10px 10px 10px 10px;
transition: border 0.3s ease-in-out;
box-sizing: border-box;
outline-width: 0;
border-radius: 10px 10px 10px 10px;
border-style: none;
border-width: 0 0 3px;
padding: 3px 10px;
}
input:focus {
border: solid white 3.5px;
}
</style>
<label>Test field</label>
<br>
<input type = "text">
I would like this to be responsive if possible, thanks in advance.
They are using clip-path and polygon to do this. See this page for details: https://css-tricks.com/notched-boxes/
As already mentioned, by looking at the source you can see that it's a clip path.
In particular the clip path is applied to a wrapper div as ::before pseudo element as opposed to on the input element. Here's a simple example using the exact same clip path on the website.
body,
html {
padding: 0;
margin: 0;
background-color: #333;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
}
.wrapper {
width: 200px;
height: 40px;
position: relative;
display: block;
}
.wrapper::before {
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: blue;
clip-path: polygon(0px 0px, 100% 0px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0px 100%, 0px 1.5px, 1.5px 1.5px, 1.5px calc(100% - 1.5px), calc(100% - 11.5px) calc(100% - 1.5px), calc(100% - 1.5px) calc(100% - 11.5px), calc(100% - 1.5px) 1.5px, 0px 1.5px);
}
input {
background: transparent;
border-color: transparent;
border-radius: 0;
color: white;
width : 100%;
height: 100%;
outline: none;
}
<div class="wrapper">
<input type="text" />
</div>
The clip path is kind of too complicated to explain bit-by-bit, but it essentially cuts out the middle of a solid rectangle as well as a little corner. So in this case, the background color is what controls the "border color". In order to animate on hover, it probably changes some elements of the clipping path if I were to guess.

How to implement complicated button style using CSS

I faced a little problem. I'm implementing the web-site design and need to implement a bit complicated button style (attached here). I have no idea how to make that using only CSS.
It's gonna be a few button styles and one of its must be with transparent background and must get background color from element where this button is placed. I implemented button with custom background that can be set using CSS. But it's not flexibly to use. If I want to use it on the different backgrounds you should add new style like "btn-customColor" etc. Now I have styles for transparent background and it looks:
The point is that I can't cut or hide the part of bottom block under top block with transparent background. I can set color and it will be like first image. But it restricts usages of buttons. I could use btn-transparent instead btn-blue, btn-green, btn-white, etc.
I had another idea to draw buttons in photoshop, but it's not really good approach and there are a lot of "no" here. Maybe is it possible to implement using canvases or smth. like that? If it's, would be great if you shared a few links for articles and so on.
There are staff that is available to use: HTML, CSS, JS (jQuery).
I hope I explained what the problem is.
Any ideas and help is appreciated.
Thank you for your time.
.btn-base {
padding: 0;
margin: 0;
height: 30px;
outline: none;
border-radius: 3px;
background: transparent;
border: 2px solid #fff;
font-size: 12px;
transition: 0.5s;
}
.btn-base>div {
position: relative;
width: 101%;
left: 3px;
bottom: 8px;
padding: 5px 15px;
outline: none;
border-radius: 3px;
background: #e4645d;
/* hardcoded code, must be transparent */
border: 2px solid #fff;
font-size: 12px;
}
<button type="submit" class="btn-base btn-transparent">
<div>Button example</div>
</button>
Consider using pseudo-elements as an alternative solution.
This method is demonstrated against x3 varying background colours in the code snippet embedded below.
Code Snippet Demonstration:
.row {
padding: 20px;
}
.row:nth-child(1) {
background: #e4645d;
}
.row:nth-child(2) {
background: #5dace4;
}
.row:nth-child(3) {
background: #5fe45d;
}
.btn-base {
padding: 0;
margin: 0;
height: 30px;
outline: none;
border-radius: 3px;
background: transparent;
border: 2px solid #fff;
font-size: 12px;
transition: 0.5s;
/* added */
position: relative; /* required for absolutely positioned pseudo-elements */
padding: 0px 10px;
}
/* Additional */
.btn-base:before {
content: "";
position: absolute;
width: 7px;
height: 30px;
border: 2px solid #fff;
border-right: 0;
right: 100%;
bottom: -5px;
top: 5px;
border-top-left-radius: 3px;
border-bottom-left-radius: 3px;
box-sizing: border-box;
}
.btn-base:after {
content: "";
position: absolute;
border: 2px solid #fff;
height: 9px;
border-top: 0;
border-left: 0;
right: 5px;
left: 0;
bottom: -9px;
border-bottom-right-radius: 3px;
box-sizing: border-box;
}
<div class="row">
<button type="submit" class="btn-base btn-transparent">Button example</button>
</div>
<div class="row">
<button type="submit" class="btn-base btn-transparent">Button example</button>
</div>
<div class="row">
<button type="submit" class="btn-base btn-transparent">Button example</button>
</div>
You could do that with only, box shadow property
body{
background:#e4645d;
text-align:center;
}
.btn-base {
padding: 10px;
margin: 0;
outline: none;
border-radius: 3px;
background: transparent;
border: 2px solid #fff;
font-size: 12px;
transition: 0.5s
color:white;
box-shadow: -10px 10px 0 -2px #e4645d, -10px 10px 0 0px white;
}
<button type="submit" class="btn-base btn-transparent">
Button example
</button>
Here's how I'd do it. Please note I changed the markup, making them siblings of a common wrapper. I used background-color: inerhit. Proof of concept:
.btn-base {
padding: 0;
margin: 0;
height: 30px;
outline: none;
border-radius: 3px;
background: transparent;
border: 2px solid #fff;
font-size: 12px;
transition: 0.5s;
color: white;
position: absolute;
width: 100%;
}
.button-holder>div {
color: white;
position: relative;
width: calc(100% + 2px);
left: 5px;
bottom: 8px;
padding: 5px 15px;
outline: none;
border-radius: 3px;
background-color: inherit;
border: 2px solid #fff;
font-size: 12px;
box-sizing: border-box;
}
body {
background-color: teal;
}
.button-holder {
background-color: inherit;
display: inline-block;
position: relative;
}
<div class="button-holder">
<button type="submit" class="btn-base btn-transparent"></button>
<div>Button example</div>
</div>
For modern browsers (except IE/Edge) you can use the clip-path css property and create a polygon to clip the element on the back to only show the parts you want.
This will make it truly transparent, in the sense that it can appear even over images.
body{background:url('https://placeimg.com/640/480/animals') no-repeat;}
.btn-base {
margin: 0;
height: 30px;
outline: none;
border-radius: 3px;
border: 2px solid currentColor;
font-size: 12px;
transition: 0.5s;
padding: 5px 15px;
font-size: 12px;
position:relative;
background:transparent;
color:#fff;
cursor:pointer;
}
.btn-base:before {
content:'';
position: absolute;
width: 100%;
height:100%;
left: -7px;
bottom: -10px;
border-radius: 3px;
/* hardcoded code, must be transparent */
border: 2px solid currentColor;
cursor:pointer;
-webkit-clip-path: polygon(0 0, 5% 0, 5% 88%, 100% 88%, 100% 100%, 0 100%);
clip-path: polygon(0 0, 5% 0, 5% 70%, 100% 70%, 100% 100%, 0 100%);
}
<button type="submit" class="btn-base">
Button example
</button>
You can imitate borders using box-shadow to create a multi-border look.
Example:
button {
border: 0;
background: #666;
box-shadow: -8px 8px 0 -4px #FFF,
-8px 8px 0 0px #666;
}
<button>Sample</button>

Shadow with CSS Trapezoid Shape button

I have used this question to create buttons. But when I try to create a bottom left shadow to the button the white area will appear as:
.btn {
height: 40px;
background: red;
width: 128px;
margin: 15px 5px 15px 5px;
cursor: hand;
text-align: center;
vertical-align: middle;
line-height: 40px;
-webkit-box-shadow: 2px 3px 3px #666666;
-moz-box-shadow: 2px 3px 3px #666666;
box-shadow: 2px 3px 3px #666666;
}
.btn:before {
width: 0px;
height: 20px;
border-left: 20px solid red;
border-top: 20px solid white;
float:right;
content:"";
}
.btn:hover{
-webkit-box-shadow: 1px 1px 1px #666666;
-moz-box-shadow: 1px 1px 1px #666666;
box-shadow: 1px 1px 1px #666666;
}
.userNave{
width: 140px;
}
<nav class="userNave">
<div class="btn"
onClick="alert('Hi')"
style="">Click Me Me</div>
<div class="btn"
onClick="alert('Hello')"
style="">No Click Me </div>
</nav>
Is there any workaround for this. Or even better. Is there any way to create a true Trapezoid button so that it will work with the shadow and there will be no problem with the background matching.
This is the best I could come up with, using the pseudo elements as the background.
.btn {
position: relative;
height: 40px;
width: 128px;
margin: 15px 5px 15px 5px;
padding: 0 10px 5px 0;
cursor: hand;
text-align: center;
vertical-align: middle;
line-height: 40px;
overflow: hidden;
}
.btn:before {
position: absolute;
left: -23px; top: 0;
width: calc(100% - 5px);
height: 50%;
background: red;
content: "";
z-index: -1;
transform: skewX(45deg);
transform-origin: left top;
box-shadow: 0px 1px 3px 1px #666666;
}
.btn:after {
position: absolute;
left: 0; top: 50%;
width: calc(100% - 5px);
height: calc(50% - 5px);
background: red;
content: "";
z-index: -1;
box-shadow: 2px 2px 4px #666666;
}
.userNave {
width: 140px;
}
<nav class="userNave">
<div class="btn" onClick="alert('Hi')" style="">Click Me Me</div>
<div class="btn" onClick="alert('Hello')" style="">No Click Me</div>
</nav>
A SVG image would most likely be the better choice though.
.btn {
position: relative;
height: 40px;
width: 128px;
margin: 15px 5px 15px 5px;
padding: 0 0 5px 0;
cursor: hand;
text-align: center;
vertical-align: middle;
line-height: 40px;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' id='trapezoid' viewbox='0 0 118 45' preserveAspectRatio='none'%3E %3Cfilter id='dropshadow' height='130%25'%3E %3CfeGaussianBlur in='SourceAlpha' stdDeviation='3'/%3E %3C!-- stdDeviation is how much to blur --%3E %3CfeOffset dx='2' dy='2' result='offsetblur'/%3E %3C!-- how much to offset --%3E %3CfeMerge%3E %3CfeMergeNode/%3E %3C!-- this contains the offset blurred image --%3E %3CfeMergeNode in='SourceGraphic'/%3E %3C!-- this contains the element that the filter is applied to --%3E %3C/feMerge%3E %3C/filter%3E %3Cpath d='M0,0 L100,0 L120,20 L120,40 L0,40z' fill='red' style='filter:url(%23dropshadow)'%3E%3C/path%3E %3C/svg%3E");
}
.userNave {
width: 140px;
}
<nav class="userNave">
<div class="btn" onClick="alert('Hi')" style="">Click Me Me</div>
<div class="btn" onClick="alert('Hello')" style="">No Click Me</div>
</nav>
In your example, you can't add a proper box-shadow without having these white parts on each side. That is because the CSS border colouring the grey shaped trapeziod DIV.
In the example above, they are using an .SVG file (image), since it is an image, the original shape of it is a trapezoid, not a rectangle with white side like yours.
You will need to draw an .svg in the shape and color you want, and then add a shadow to the element itself.
Here are more informations about SVG.
I hope it helps.

Create double round border for image

I want the double round border around my image that is actually square image.
I tried creating. here is the js fiddle . The exact that i want is this
Here is the code
CSS
.home_boxes {
background: none repeat scroll 0 0 #f1917b;
color: #ffffff;
padding: 40px 0;
text-align: center;
}
img {
border: 5px solid #ffffff;
border-radius: 50%;
margin: 20px;
outline: 2px solid #ffffff;
outline-offset: 9px;
}
img:before {
border: 5px double #ff0000;
border-radius: 50%;
bottom: 10px;
content: "";
left: 10px;
position: relative;
right: 10px;
top: 10px;
}
HTML
<div class="home_boxes">
<div class="col-md-4">
<img src="http://placehold.it/310x311">
</div>
</div>
Please any help is really appreciated.
Use box-shadow. It can have several values:
img {
/* first white ring */
border: 5px solid #ffffff;
/* background 5px ring + ring link border */
box-shadow: 0 0 0 5px #f1917b, 0 0 0 10px #fff;
border-radius: 50%;
margin: 20px;
}
Fiddle with double circle border.
if the image is not transparent PNG. you can use padding and background , just like below;
img {
border: 5px solid #ffffff;
padding:5px; background:blue;
border-radius: 50%;
margin: 20px;
}
demo here ----> FIDDLE