By responsive I mean that they still look good with slightly longer text and don't have fixed width.
I am trying to make buttons that look exactly like in image below, but I can't get them to be the right width. I thought adding padding on left and right side would do it, but that doesn't work with the "ADD" button. My task is to convert a .psd to html/css pixel perfect which is kind of dumb and results in bad code.
Fiddle: https://jsfiddle.net/emils/9g7cn7eh/
Buttons:
Button:
<div class="btn-container">
<button class="action-btn" type="submit">Add</button>
</div>
Styling:
.btn-container {
position: relative;
padding-bottom: 20px;
}
.action-btn {
padding: 4px 9px 4px 20px;
color: #f5f8f9;
font-size: 0.9375em;
letter-spacing: 0.4px;
text-transform: uppercase;
background-color: #aecacc;
border: 0;
}
.action-btn:before {
content: "";
position: absolute;
width: 0;
height: 0;
top: 0;
margin-left: -20px;
border-top: 14px solid transparent;
border-bottom: 14px solid transparent;
border-left: 7px solid #f4f4f4;
}
.action-btn:after {
content: "";
position: absolute;
width: 0;
height: 0;
top: 0;
margin-left: 8px;
border-top: 13px solid transparent;
border-bottom: 13px solid transparent;
border-left: 15px solid #aecacc;
}
Add position: relative to the buttons, and use right/left to move the pseudo elements.
JSfiddle: link
.btn-container {
position: relative;
padding-bottom: 20px;
}
.action-btn {
padding: 4px 9px 4px 20px;
color: #f5f8f9;
font-size: 0.9375em;
letter-spacing: 0.4px;
text-transform: uppercase;
background-color: #aecacc;
border: 0;
position: relative; /* we need this for the pseudo elements positioning */
}
.action-btn:before {
content: "";
position: absolute;
width: 0;
height: 0;
top: 0;
left: 0;
/*margin-left: -20px;*/
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-left: 7px solid #f4f4f4;
}
.action-btn:after {
content: "";
position: absolute;
width: 0;
height: 0;
top: 0;
right: -15px;
/*margin-left: 8px;*/
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-left: 15px solid #aecacc;
}
<div class="btn-container">
<button class="action-btn" type="submit">Add</button>
</div>
<div class="btn-container">
<button class="action-btn" type="submit">View Basket</button>
</div>
<div class="btn-container">
<button class="action-btn" type="submit">View All (15)</button>
</div>
<div class="btn-container">
<button class="action-btn" type="submit">Checkout</button>
</div>
Related
Hello guys i need your help
I want to do that: Model Botton
The problem is that, when i add a filter
filter: drop-shadow(3px 4px 0px #0000B8);
to my button the result is: My Botton
Can you help me please ?
There are multiple ways of doing it.
Here are some examples:
.button-1 {
position: relative;
color: #ff1800;
background-color: white;
font-size: 1.2em;
font-weight: bold;
border: 2px solid #ff1800;
padding: 15px;
border-radius: 100px;
}
.button-1::before {
content: '';
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
background-color: transparent;
border: 2px solid #ff1800;
border-radius: 100px;
filter: drop-shadow(7px 12px 0px #0000B8);
z-index: -1;
}
.button-2 {
color: #ff1800;
background-color: transparent;
font-size: 1.2em;
font-weight: bold;
border: 2px solid #ff1800;
padding: 15px;
border-radius: 100px;
box-shadow: 5px 10px 0 -2px white,
5px 10px 0 0 #0000B8;
}
.button-3 {
position: relative;
color: #ff1800;
background-color: white;
font-size: 1.2em;
font-weight: bold;
border: 2px solid #ff1800;
padding: 15px;
border-radius: 100px;
}
.button-3::before {
content: '';
position: absolute;
width: 100%;
height: 100%;
left: 4px;
top: 8px;
right: 0;
bottom: 0;
background-color: transparent;
border: 2px solid #0000B8;
border-radius: 100px;
z-index: -1;
}
<button class="button-1">
Become a seller
</button>
<button class="button-2">
Become a seller
</button>
<button class="button-3">
Become a seller
</button>
Sadly, none of the methods can have a complete transparent background.
I would like to create this corner in the top-left of my title:
The problem is that I didn't find the way to decale the title from the corner.
Could you help me pls ?
This is my code:
<h2 class="title_project_details">{project.name}</h2>
.title_project_details{
margin-bottom: 15px;
font-family: Poppins-semi-bold;
font-size: 29px;
color: #210B41;
letter-spacing: 1px;
}
.title_project_details::before{
border-left: 3px solid #310C50;
border-top: 3px solid #310C50;
content: '';
display: inline-block;
height: 30px;
width: 30px;
}
.title_project_details{
margin-bottom: 15px;
font-family: Poppins-semi-bold;
font-size: 29px;
color: #210B41;
letter-spacing: 1px;
}
.title_project_details::before{
border-left: 3px solid #310C50;
border-top: 3px solid #310C50;
content: '';
display: inline-block;
height: 30px;
width: 30px;
}
<h2 class="title_project_details">{project.name}</h2>
My actual result:
Thanks in advance !
Try positioning the elements set relative for the title and set absolute for the ::before
.title_project_details{
margin-bottom: 15px;
font-family: Poppins-semi-bold;
font-size: 29px;
color: #210B41;
letter-spacing: 1px;
position: relative;
padding: 3px 18px
}
.title_project_details::before{
border-left: 2px solid #310C50;
border-top: 2px solid #310C50;
content: '';
display: inline-block;
height: 30px;
position: absolute;
top: 0;
left: 0;
width: 30px;
}
body {margin: 20px;}
<h2 class="title_project_details">project.name</h2>
Add padding if you want space (I saw space in the reference image you showed there)
I tried to use absolute positioning for ::before, for me it looks like your desired result. u might tweak with top and left properties.
.title_project_details{
margin-bottom: 15px;
position:relative;
font-family: Poppins-semi-bold;
font-size: 29px;
color: #210B41;
letter-spacing: 1px;
}
.title_project_details::before{
border-left: 3px solid #310C50;
border-top: 3px solid #310C50;
position: absolute;
left: -6px;
top: -1px;
content: '';
display: inline-block;
height: 30px;
width: 30px;
}
<h2 class="title_project_details">{project.name}</h2>
I have been trying hard without success to add a little triangle under my square to act as a pointer like this:
My code by itself works, but whenever I try to add css to make this triangle nothing will appear. I think it has to do with before-after functions, but I'm not really getting it. Anyone can help me with that?
<div id="slider_outer1">
<div class="slider_segment"><img src="myurl.com" alt="Nature" style="width:100%;"></div>
<div id="slider_marker1"></div>
</div>
<style>
.container {width:400px;}
#slider_outer1 {width: 98%;border: 5px solid #8f89ff; position: relative;display: inline-block; border-radius: 5px;}
.slider_segment {width: 100%; float: left; display: inline;}
#slider_marker1 {
position: absolute;
border: 2px solid #574fff;
height: 30px;
width: 5%;
top: 120px;
left: 57.25%;
text-align: center;
Margin-left: -10%;
padding: 5px 0px;
background: #ffffff;
border-radius: 5px;
}
div#slider_marker1:after {
content: "5";
font-size: 20px;
padding: 5px;
line-height: 30px;
font-family: sans-serif;
}
</style>
edit: code of the triangle
<div class="triangle-down"></div>
<style>
.triangle-down {
width: 0;
height: 0;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
border-top: 20px solid #555;
}
</style>
Generally in CSS triangles are made using borders, not before and after pseudo elements. To create a downward pointing triangle, you would create a top border of n number of pixels, and left and right borders of half that width and also transparent.
Example:
<div id="slider_outer1">
<div class="slider_segment"><img src="myurl.png" alt="Nature" style="width:100%;"></div>
<div id="slider_marker1"><div id='triangle-down'></div></div>
</div>
<style>
.container {width:400px;}
#slider_outer1 {width: 98%;border: 5px solid #8f89ff; position: relative;display: inline-block; border-radius: 5px;}
.slider_segment {width: 100%; float: left; display: inline;}
#slider_marker1 {
position: absolute;
border: 2px solid #574fff;
height: 30px;
width: 5%;
top: 120px;
left: 57.25%;
text-align: center;
Margin-left: -10%;
padding: 5px 0px;
background: #ffffff;
border-radius: 5px;
}
#triangle-down {
position: absolute;
top: 40px;
right: 50%;
transform: translateX(50%);
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 20px solid blue;
}
div#slider_marker1:after {
content: "5";
font-size: 20px;
padding: 5px;
line-height: 30px;
font-family: sans-serif;
}
</style>
See my codepen here: https://codepen.io/anon/pen/bvXOab
You could add another div for the triangle like
<div id='triangle'></div>
Css For the triangle...
#triangle{
width: 0;
height: 0;
border-left: 40px solid transparent;
border-right: 40px solid transparent;
border-top: 80px solid blue;
}
However I feel that your problem is not that it just isnt appearing its that the positioning is messed up so its 'hidden' behind the sliders
I think I understand what you're trying to make. This should add a triangle above the marker. This solution should allow you to also remove anything related to triangle-down as it only requires the slider_marker1 div
#slider_marker1::before {
content: "";
width: 0;
height: 0;
position: absolute;
top: -6px;
left: 0;
right: 0;
margin: auto;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 4px solid green;
z-index: 100;
}
How can draw an up-down arrow with pure CSS?
This is what I get using HTML :
.up-down-arrow {
font-size: 50px;
color: #666;
padding: 0;
margin: 0;
display: inline-block;
}
<div class="up-down-arrow">↕</div>
But the line between the arrows is too short. Can I make it longer?
Ideally, this is what I am after:
Single element solution
You can achieve that with pseudo elements, CSS triangles and some positioning:
.arrow {
width: 2px;
height: 200px; /* <- adjust your height as you need it */
background: black;
margin: 10px;
position: relative;
}
.arrow::before,
.arrow::after {
content: '';
position: absolute;
left: -9px;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
}
.arrow::before {
top: 0;
border-bottom: 15px solid black;
}
.arrow::after {
bottom: 0;
border-top: 15px solid black;
}
<div class="arrow"></div>
Multiple elements solution
To achieve the actual arrow shape, you will need multiple elements. Here the pseudo elements are used to create white triangles, that cut out the black arrow heads:
.arrow {
width: 2px;
height: 200px; /* <- adjust your height as you need it */
background: black;
margin: 10px;
position: relative;
}
.up, .down, .arrow::before, .arrow::after {
position: absolute;
left: -9px;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
}
.up {
top: 0;
border-bottom: 15px solid black;
}
.down {
bottom: 0;
border-top: 15px solid black;
}
.arrow::before, .arrow::after {
content: '';
z-index: 2;
}
.arrow::before {
top: 11px;
border-bottom: 4px solid white;
}
.arrow::after {
bottom: 11px;
border-top: 4px solid white;
}
<div class="arrow">
<div class="up"></div>
<div class="line"></div>
<div class="down"></div>
</div>
Or another variant with a continuous line:
.line {
position: relative;
margin: -15px 0 -15px 9px;
width: 2px;
height: 180px;
background-color: black;
z-index: 5;
}
.up,
.down {
position: relative;
z-index: 3;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
}
.up {
border-bottom: 15px solid black;
}
.down {
border-top: 15px solid black;
}
.down::before, .up::after {
position: absolute;
left: -10px;
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
content: '';
z-index: 4;
}
.down::before {
bottom: 11px;
border-top: 4px solid white;
}
.up::after {
top: 11px;
border-bottom: 4px solid white;
}
<div class="arrow">
<div class="up"></div>
<div class="line"></div>
<div class="down"></div>
</div>
To make the up-down arrows with the line in between the same as your example, I would suggest using SVG. You can use it inline as shown in the following example :
.wrap{
position:relative;
height:70vh;
border-left:1px solid #000;
margin:10vh 50px;
padding:5vh 20px;
}
.arrow {
position:absolute;
left:-5px;
width: 9px;
height: auto;
}
.up{top:-9px;}
.down{bottom:-9px;}
<div class="wrap">
<svg class="arrow up" viewbox="0 0 7 10">
<path d="M3.5 0 L7 10 Q3.5 7 0 10z"/>
</svg>
<svg class="arrow down" viewbox="0 0 7 10">
<path d="M3.5 10 L7 0 Q3.5 3 0 0z"/>
</svg>
Whatever content you need here
</div>
The inline SVG arrows are made with a path element and using one quadratic curve (made with Q3.5 7 0 10 in the up arrow).
The line between the arrows is made with a border left on a container div it expands with the height of this container.
Both arrows are positioned absolutely.
Here is one more solution using arrow char code \027A4 for ::before and ::after content.
Size of these chars has bound to root font size rem and their modification rotate, top and left based on the content font-size.
.arrow {
position: relative;
width: 3px;
height: 150px;
margin: 20px;
background: tomato;
}
.arrow::before,
.arrow::after {
content: '\027A4';
position: absolute;
font-size: 1.5rem;
color: tomato;
}
.arrow::before {
top: -.9em;
left: -.5em;
transform: rotate(-90deg);
}
.arrow::after {
bottom: -.9em;
left: -.32em;
transform: rotate(90deg);
}
<div class="arrow"></div>
To keep it simple, change the height style in mid class to increase the length of line!
.up {
width: 0px;
height: 0px;
border-bottom: 10px solid black;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-top: none;
}
.mid {
margin-left:7px;
width: 2px;
height: 180px;
background-color:black;
}
.down{
width: 0px;
height: 0px;
border-top: 10px solid black;
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: none;
}
<div class='up'></div>
<div class='mid'></div>
<div class='down'></div>
Hope it helps!
I have the following code where I have a Button that has the arrow hack. The only issue is I'd like to have this display the link on the status bar. A button does not achieve. How do I convert this to a a href link and still be able to keep that arrow? Here is my code:
JSFIDDLE
HTML:
<button type="button" class="btn-lg btn-default my-button my-button-active">My Button</button>
CSS:
.my-button {
color: #fff ;
background-color: #444346;
font-size:15px;
padding: 20px 0px;
border:none;
margin-right:20px;
position: relative;
outline:0;
width:31%;
}
.my-button-active:after {
content:'';
position: absolute;
top: 100%;
left: 50%;
margin-left: -10px;
width: 0;
height: 0;
border-top: solid 7px #444346;
border-left: solid 7px transparent;
border-right: solid 7px transparent;
}
.my-button-active:hover:after {
content:'';
position: absolute;
top: 100%;
left: 50%;
margin-left: -10px;
width: 0;
height: 0;
border-top: solid 7px #e6e6e6;
border-left: solid 7px transparent;
border-right: solid 7px transparent;
}
It is very simple. Just convert the button to a and add display: block; or display: inline-block; to the class .my-button.
Fiddle link: http://jsfiddle.net/samirkumardas/60n0ruyj/2/
Change your html to an anchor tag:
<a class="btn-lg btn-default my-button my-button-active" href="">My Button that links to some other page</a>
Replace your .my-button selector with:
.my-button {
display: block;
position: relative;
color: #fff;
background-color: #444346;
font-size:15px;
padding: 20px 0;
text-align: center;
border: none;
margin-right: 20px;
outline: 0;
width: 31%;
}
Just change your button to an anchor and adjust your css.
div {
margin: 30px;
}
a.my-button {
color: #fff ;
background-color: #444346;
font-size:15px;
padding: 20px 0px;
border:none;
margin-right:20px;
position: relative;
outline:0;
width:31%;
display: inline-block;
text-align: center;
}
.my-button:hover {
text-decoration: none;
}
.my-button-active:after {
content:'';
position: absolute;
top: 100%;
left: 50%;
margin-left: -10px;
width: 0;
height: 0;
border-top: solid 7px #444346;
border-left: solid 7px transparent;
border-right: solid 7px transparent;
}
.my-button-active:hover:after {
content:'';
position: absolute;
top: 100%;
left: 50%;
margin-left: -10px;
width: 0;
height: 0;
border-top: solid 7px #e6e6e6;
border-left: solid 7px transparent;
border-right: solid 7px transparent;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"/>
<div>
My Button that links to some other page
</div>
After changing your <button> tag to an <a> tag, the key thing is to have display: block; applied to it, as <a> tags are primarily inline elements and cannot have padding and margin.