How to add two lines in the center of a button - html

There is a button with a border: 3px solid #E82929; what technology can be used to add additional lines like in the photo?
.btn {
position: relative;
width: 362px;
height: 71px;
color: #FFFFFF;
background-color: #000000;
border: 3px solid #E82929;
font-family: 'Flamenco';
font-style: normal;
font-weight: 400;
font-size: 24px;
line-height: 25px;
text-align: center;
}
<button class="btn">Забронировать столик</button>

Use gradient
.btn {
position: relative;
padding: 20px 50px;
color: #FFFFFF;
border: 3px solid #E82929;
font-family: 'Flamenco';
font-style: normal;
font-weight: 400;
font-size: 24px;
line-height: 25px;
text-align: center;
background: linear-gradient(90deg, #E82929 40px,#0000 0 calc(100% - 40px), #E82929 0) 50%/100% 3px no-repeat;
background-color: #000000;
}
<button class="btn">Забронировать столик</button>

You do not need extra markup, because it can be done with the ::before and ::after pseudo elements.
Assuming your 2 lines at the left and right should have a width of 30px and a left and right padding of 10px, you could add this to your already existing CSS:
.btn {
position: relative;
width: 362px;
height: 71px;
color: #FFFFFF;
background-color: #000000;
border: 3px solid #E82929;
font-family: 'Flamenco';
font-style: normal;
font-weight: 400;
font-size: 24px;
line-height: 25px;
text-align: center;
}
/* extra code comes here */
.btn {
padding: 0 40px; /* 30px line width + 10px padding */
}
.btn::before,
.btn::after {
background-color: #E82929; /* border color */
content: ''; /* content is mandatory for the element to show up */
height: 3px; /* 3px border width */
position: absolute;
top: 50%; /* 50% from the top */
transform: translateY(-50%); /* half of its height back to the top */
width: 30px; /* 30px line width */
}
.btn::before {
left: 0;
}
.btn::after {
right: 0;
}
<button class="btn">Забронировать столик</button>
Change the width and padding according to your needs.
What it does: It adds the ::before and ::after pseudo elements with no text content on the left and right and positions them vertically centered.
If you have any questions regarding details, feel free to ask.

Related

Css :after and :before pseudo element not working properly in IOS

I am trying to dash after border in H tag using :after and :before it's working fine on desktop & android devices but create issue in IOS devices
border made using :after and :before but text of h element doesn't display
below is a demo of other devices
below is a demo of IOS devices
h2.service-heading {
font-size: 36px;
color: #762d2f;
text-transform: uppercase;
position: relative;
display: table;
margin-left: auto;
margin-right: auto;
max-width: calc(100% - 36px);
position: relative;
}
h2.service-heading::after {
content: '';
position: absolute;
width: calc(100% - 5px);
display: block;
height: 6px;
border-bottom: 6px solid #762d2f;
z-index: 9999;
clear: both;
left: 0;
bottom: 0px;
}
h2.service-heading::before {
content: '';
position: absolute;
width: 10px;
display: block;
height: 6px;
border-bottom: 6px solid #762d2f;
z-index: 9999;
clear: both;
bottom: 0px;
right: -10px
}
<h2 class="service-heading" align="center"> Our Services</h2>
Can anyone help with this
Thanks in advance
You don't need to pseudo element for that. Can be made easily with only background.
h2.service-heading {
font-size: 36px;
color: #762d2f;
text-transform: uppercase;
display: table;
margin-left: auto;
margin-right: auto;
max-width: calc(100% - 36px);
padding-right: 15px;
background: linear-gradient(#762d2f, #762d2f) 0 100% / calc(100% - 15px) 6px no-repeat,
linear-gradient(#762d2f, #762d2f) 100% 100% / 10px 6px no-repeat;
}
<h2 class="service-heading" align="center"> Our Services</h2>
Also can be used some CSS variables to control everything easily.
h2.service-heading {
--border-height: 6px;
--second-border-width: 20px;
--border-gap: 10px;
font-size: 36px;
color: #762d2f;
text-transform: uppercase;
display: table;
margin-left: auto;
margin-right: auto;
max-width: calc(100% - 36px);
padding-bottom: 5px; /* bottom distance of border */
padding-right: calc(var(--second-border-width) + var(--border-gap));
background: linear-gradient(#762d2f, #762d2f) 0 100% / calc(100% - (var(--second-border-width) + var(--border-gap))) var(--border-height) no-repeat,
linear-gradient(#762d2f, #762d2f) 100% 100% / var(--second-border-width) var(--border-height) no-repeat;
}
<h2 class="service-heading" align="center"> Our Services</h2>
I had the similar problem: dropdown-arrow for menu item performed as pseudoclass ::after didn't work for IOS. enter image description here
Next code snippet I utilized for SASS:
.nav-link {
border-top: 1px solid var(--color-white);
color: var(--color-white);
font-size: 18px;
line-height: 22px;
font-weight: 400;
text-decoration: none;
padding: 10px 15px 10px 0;
&::after {
content: " ";
border: none;
background-image: var(--arrow-down);
background-position: center center;
background-repeat: no-repeat;
width: 40px;
height: 20px;
}
}
so the solution was to remove arrows from pseudoclass ::after and perform it as a background image for menu item, like next:
.nav-link {
display: block;
border-top: 1px solid var(--color-white);
color: var(--color-white);
font-size: 18px;
line-height: 22px;
font-weight: 400;
text-decoration: none;
padding: 10px 15px 10px 0;
background-image: var(--arrow-down);
background-position: 98%;
background-repeat: no-repeat;
background: var(--arrow-down) no-repeat 98%;
&::after {
display: none;
}
}
I've noticed that IOS14.4 and lower doesn't support background-image, and older versions IOS are needed only full form background not just background-image:
background: var(--arrow-down) no-repeat 98%;

Best way to use a right pointing arrow in CSS animation

I'm trying to create a continue button that shows a right pointing arrow in a hover state. I also want the arrow to be centered.
I've tried adding .icon-arrow-right:before {content: "&rarr";}
body {
background: #00b894;
}
.btn {
font-size: 14px;
background: none;
padding: 25px 80px;
display: inline-block;
margin: 15px 30px;
position: relative;
border: 3px solid #fff;
color: #fff;
overflow: hidden;
transition: all 0.3s;
}
.btn:before {
position: absolute;
height: 100%;
font-size: 125%;
line-height: 3.5;
color: #fff;
transition: all 0.3s;
left: 130%;
top: 0;
}
.icon-arrow-right:before {
content: "#";
}
.btn:hover:before {
left: 80%;
}
<button class="btn icon-arrow-right">Continue</button>
I would like the arrow to be to the right of the button text in a hover state. I would also like the arrow to be centered with the button text.
Make your pseudo element into the triangle you desire:
.icon-arrow-right:before {
margin-top: 21px;
content: "";
width: 0;
height: 0;
border-top: 7px solid transparent;
border-left: 14px solid white;
border-bottom: 7px solid transparent;
}
This uses the awesome transparent border trick to make the element box appear as a triangle. Change the border widths to alter the size of the triangle, notice the border with color is twice as wide as the transparent sides. You can play with these values to nuance the triangle how you like.
I also changed how you are positioning the text in the button:
.btn {
padding: 0 80px; /* padding on sides only */
height: 64px; /* height of the button you want */
line-height: 58px; /* same as height minus the border-top and border-bottom */
border: 3px solid #fff;
}
By using line-height this way you can guarantee your text will be vertically centered in the button at any font-size.
Check out the full working example:
body {
background: #00b894;
}
.btn {
font-size: 14px;
background: none;
padding: 0 80px; /* padding on sides only */
height: 64px; /* height of the button you want */
line-height: 58px; /* same as height minus the border-top and border-bottom */
display: inline-block;
margin: 15px 30px;
position: relative;
border: 3px solid #fff;
color: #fff;
overflow: hidden;
transition: all 0.3s;
cursor: pointer;
}
.btn:before {
position: absolute;
height: 100%;
font-size: 125%;
line-height: 3.5;
color: #fff;
transition: all 0.3s;
left: 130%;
top: 0;
}
.icon-arrow-right:before {
margin-top: 21px;
content: "";
width: 0;
height: 0;
border-top: 7px solid transparent;
border-left: 14px solid white;
border-bottom: 7px solid transparent;
}
.btn:hover:before {
left: 80%;
}
<button class="btn icon-arrow-right">Continue</button>
I have vertically centered the arrow with top:50%;transform:translateY(-50%);. I removed the line-height and height CSS from the .btn pseudo element because they weren't needed. I have just used > for the arrow, but you can use something like fontawesome to get a nice icon.
body {
background: #00b894;
}
.btn {
font-size: 14px;
background: none;
padding: 25px 80px;
display: inline-block;
margin: 15px 30px;
position: relative;
border: 3px solid #fff;
color: #fff;
overflow: hidden;
transition: all 0.3s;
}
.btn:before {
position: absolute;
font-size: 125%;
color: #fff;
transition: all 0.3s;
left: 130%;
top:50%;
transform:translateY(-50%);
}
.icon-arrow-right:before {
content: ">";
}
.btn:hover:before {
left: 80%;
}
<button class="btn icon-arrow-right">Continue</button>
Just expanding on #BugsArePeopleToo 's answer, using borders ans transforms to keep the ">" shape the OP wanted.
body {
background: #00b894;
}
.btn {
font-size: 14px;
background: none;
padding: 0 80px; /* padding on sides only */
height: 64px; /* height of the button you want */
line-height: 58px; /* same as height minus the border-top and border-bottom */
display: inline-block;
margin: 15px 30px;
position: relative;
border: 3px solid #fff;
color: #fff;
overflow: hidden;
transition: all 0.3s;
cursor: pointer;
}
.btn:before {
position: absolute;
height: 100%;
font-size: 125%;
line-height: 3.5;
color: #fff;
transition: all 0.3s;
left: 130%;
top: 0;
}
.icon-arrow-right:before {
content: "";
width: 0.5em;
height: 0.5em;
position:absolute;
top:50%;
border-top:2px solid #fff;
border-right:2px solid #fff;
transform:translateY(-50%) rotate(45deg);
}
.btn:hover:before {
left: 80%;
}
<button class="btn icon-arrow-right">Continue</button>

How to attach an image into a bottom middle of a div?

I am trying to achieve the following:
And I largely have. The only missing piece is the Svg of the downward arrow. I need it to be in the middle of the div (the green part) irregardless of how wide the div is. I've tried setting .listing-price:after.left to 50% but I don't think it does what it should. I also want the arrow to attach to the bottom of the main div, but I got it there by hardwiring the .listing-price:after.top property.
How do I get the arrow to be in the middle?
Is there a better way of attaching the arrow to the bottom of the div than hardwiring the .top property?
Here is what I have so far:
body {
background-color: salmon;
transform: scale(3.0);
transform-origin: 0 0;
}
.listing-price {
border-radius: 2px;
border-style: solid;
border-width: 1px;
color: white;
cursor: pointer;
display: inline-block;
font-family: "museo_sans_rounded", Helvetica, Arial, sans-serif;
font-size: 13px;
font-weight: 500;
line-height: 15px;
padding-left: 5px;
padding-right: 5px;
position: relative;
text-align: center;
user-select: none;
background-color: #009934;
border-color: #F2F5F3;
}
/* Favorite Marker */
.listing-price:before {
content: url(https://rgelb.github.io/public/misc/heart_icon.svg);
display: inline-block;
position: absolute;
right: -7.8px;
top: -6px;
}
/* Downward arrow */
.listing-price:after {
content: url(https://rgelb.github.io/public/misc/arrow_border.svg);
display: inline-block;
position: absolute;
left: 50%;
top: 10px;
}
.listing-price-open-new-house {
background-color: #586371;
border-color: white;
border-radius: 2px;
border-spacing: 1px;
border-style: solid;
border-width: 1px;
color: white;
display: block;
font-family: "museo_sans_rounded", Helvetica, Arial, sans-serif;
font-size: 9px;
font-style: normal;
font-weight: 700;
left: -1px;
line-height: 10px;
position: absolute;
text-align: center;
text-transform: uppercase;
top: -11px;
width: 30px;
}
<div style="height: 25px;margin-top: 40px;">
<div class="listing-price">
<i class="listing-price-open-new-house">Open</i>
$258K
</div>
<div class="listing-price">
<i class="listing-price-open-new-house">Open</i>
$9M
</div>
</div>
You're lucky, it works just by setting left:0;width:100%; for the arrow:
body {
background-color: salmon;
transform: scale(3.0);
transform-origin: 0 0;
}
.listing-price {
border-radius: 2px;
border-style: solid;
border-width: 1px;
color: white;
cursor: pointer;
display: inline-block;
font-family: "museo_sans_rounded", Helvetica, Arial, sans-serif;
font-size: 13px;
font-weight: 500;
line-height: 15px;
padding-left: 5px;
padding-right: 5px;
position: relative;
text-align: center;
user-select: none;
background-color: #009934;
border-color: #F2F5F3;
}
/* Favorite Marker */
.listing-price:before {
content: url(https://rgelb.github.io/public/misc/heart_icon.svg);
display: inline-block;
position: absolute;
right: -7.8px;
top: -6px;
}
/* Downward arrow */
.listing-price:after {
content: url(https://rgelb.github.io/public/misc/arrow_border.svg);
display: inline-block;
position: absolute;
top: 8.9px; /* a bit of fine-tuning */
left: 0;
width: 100%;
}
.listing-price-open-new-house {
background-color: #586371;
border-color: white;
border-radius: 2px;
border-spacing: 1px;
border-style: solid;
border-width: 1px;
color: white;
display: block;
font-family: "museo_sans_rounded", Helvetica, Arial, sans-serif;
font-size: 9px;
font-style: normal;
font-weight: 700;
left: -1px;
line-height: 10px;
position: absolute;
text-align: center;
text-transform: uppercase;
top: -11px;
width: 30px;
}
<div style="height: 25px;margin-top: 40px;">
<div class="listing-price">
<i class="listing-price-open-new-house">Open</i>
$258K
</div>
<div class="listing-price">
<i class="listing-price-open-new-house">Open</i>
$9M
</div>
</div>
The reason why this works lies in the nature of SVGs: if the top-level <svg> element contains a viewBox attribute defining the area to draw, and there are a width and height defined for the element where the aspect ratio does not fit that of the viewBox, the viewBox content will be scaled and positioned such that it is fitted at the largest possible size into the middle of the box defined by the svg element.
So, by setting width to the width of the div, you get the positioning in the middle for free - provided the SVG has a viewBox attribute (which it has), and no preserveAspectRatio attribute changing this behavior (which it hasn't).

How center the text between the limits of the picture

I'm doing a tool to help in a game. The original game looks like this:
I was able to do the elixir number on the purple drop on the top-left. The transparent label to show the Level. (still need to work with the right colors based in card rarity).
But cant make the label center on the bottom and if possible looks like inside the border instead of above the whole picture.
I was trying following this question CSS center text (horizontally and vertically) inside a div block but haven't be able to make it work.
.elixir {
position: absolute;
top: 5px;
left: 15px;
color: white;
font-weight: bold;
font-size: 50px;
}
.level {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
text-align: center;
}
#header {
position: relative;
background: yellow;
width: 200px;
}
#header-content {
position: absolute;
bottom: 0;
color: Violet ;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
/* width: 100%; */
line-height: 40px;
}
<div id="header">
<img src="https://vignette.wikia.nocookie.net/clashroyale/images/4/46/DarkPrinceCard.png/revision/latest?cb=20160702201038" />
<span class="elixir"> 4 </span>
<span id="header-content"> Level 2 </span>
</div>
There are a few things you need to take into consideration.
Centralising this element
To address your issue of centralising this element with a couple of methods:
Option 1.
You can make the entire span width 100% and center the text within it by adding this to #header-content:
width: 100%;
display: block;
text-align:center;
As shown here: https://codepen.io/anon/pen/RjmMjQ
Option 2.
You can remove the absolute positioning, use display:inline-block, and, adding text-align:center; on the parent element like so:
https://codepen.io/anon/pen/wPbmrQ
Option 3.
If the element is position:absolute; you can also use:
left: 50%;
transform: translateX(-50%);
Positioning the element relative to an image:
You also said you would like this element to be positioned inside the border. Because this border is set on the image itself, you will need to position your element so it is relative to the image.
To make sure everything lines up correctly with padding we need to set the following, otherwise padding & css borders are not included in any width you set.:
*{
box-sizing: border-box;
}
Then you need to get the exact position right for aligning you element with the image, these seem to work right:
width: 170px;
bottom: 18px;
left:50%;
transform: translateX(-50%);
border-radius: 0 0 12px 12px;
This is done for you here:
https://codepen.io/anon/pen/YEbMYB
First you need to make the image max-width:100% to avoid overflow, then simply adjust left/right/bottom values since your element is absolute position and add text-align:center :
.elixir {
position: absolute;
top: 5px;
left: 15px;
color: white;
font-weight: bold;
font-size: 50px;
}
.level {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
text-align: center;
}
#header {
position: relative;
background: yellow;
width: 200px;
}
#header img {
max-width:100%;
}
#header-content {
position: absolute;
bottom: 5px;
left:5px;
right:5px;
text-align:center;
color: Violet ;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
/* width: 100%; */
line-height: 40px;
}
<div id="header">
<img src="https://vignette.wikia.nocookie.net/clashroyale/images/4/46/DarkPrinceCard.png/revision/latest?cb=20160702201038" />
<span class="elixir"> 4 </span>
<span id="header-content"> Level 2 </span>
</div>
By using left:0; right:0; and appropirate margin value, you should be able to center it. You could also set the width of the #header-content and set margin:0 auto;, it would achieve the same effect.
I also fit the image inside parent and added a curve to the label, you can see everything commented in css.
Working snippet:
.elixir {
position: absolute;
top: 5px;
left: 15px;
color: white;
font-weight: bold;
font-size: 50px;
}
.level {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
text-align: center;
}
#header {
position: relative;
background: yellow;
width: 200px;
}
#header img {width:100%; /* sets image to fit parent */}
#header-content {
position: absolute;
bottom: 0;
color: Violet ;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(0, 0, 0, 0.7);
padding: 10px;
/* width: 100%; */
line-height: 40px;
right:0; left:0; /*center*/
margin:0 18px 24px 18px; /* set margin to appropriate values top right bottom left*/
border-bottom-left-radius:13px; border-bottom-right-radius:13px; /* curved edges */
}
<div id="header">
<img src="https://vignette.wikia.nocookie.net/clashroyale/images/4/46/DarkPrinceCard.png/revision/latest?cb=20160702201038" />
<span class="elixir"> 4 </span>
<span id="header-content"> Level 2 </span>
</div>
Not too sure, but looks like you are just missing coordonates and text-align.
update example for #header-content:
bottom: 30px;
left:24px;
right:24px;
text-align:center;
and eventually
border-radius:0 0 10px 10px;
text-shadow:1px 1px white;
Demo below:
.elixir {
position: absolute;
top: 5px;
left: 15px;
color: white;
font-weight: bold;
font-size: 50px;
}
.level {
color: white;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(218, 21, 225);
padding: 10px;
text-align: center;
}
#header {
position: relative;
background: yellow;
width: 200px;
}
#header-content {
position: absolute;
bottom: 30px;
left:24px;
right:24px;
text-align:center;
border-radius:0 0 10px 10px;
text-shadow:2px 2px black, -1px -1px black;;
color: Violet ;
font: bold 24px/45px Helvetica, Sans-Serif;
letter-spacing: -1px;
background: rgb(0, 0, 0);
/* fallback color */
background: rgba(218, 21, 225,0.5);
/* padding:10px;
width: 100%; */
line-height: 40px;
}
<div id="header">
<img src="https://vignette.wikia.nocookie.net/clashroyale/images/4/46/DarkPrinceCard.png/revision/latest?cb=20160702201038" />
<span class="elixir"> 4 </span>
<span id="header-content"> Level 2 </span>
</div>

how to add button inside input in joomla

This is how my input and button looks like. The CSS code looks like this:
button._searchfrontpage
{
margin: 0 auto;
background: #333;
height: 53px;
width: 70px;
border-radius: 6px;
line-height: normal;
color: #eee;
font-weight: 400;
letter-spacing: 2px;
border: 0px;
display: block;
font-size: 18px;
}
.sp-module_searchfrontpage input[type="text"] {
background: #f0dbc5;
height: 53px;
width: 50%;
margin: 0 auto;
border-radius: 6px;
margin-bottom: 40px;
line-height: normal;
color: #444;
font-weight: 400;
letter-spacing: 2px;
border: 0px;
display: block;
}
I dont seem to figure out a way to drag the grey button into the right side of my input box. Are there someone who can figure me an idea to work from?
EDIT: after implementing the code #Jai gave me, it looks fine, but when i make the browser smaller, it gets out of its place and looks like this:
Obviously its like that, because the input width is 50%. are there any solutions for that?
For your div:
.sp-module_searchfrontpage{
/* other CSS as is*/
position: relative;
}
Now the button:
button._searchfrontpage {
background: #333;
height: 53px;
width: 70px;
border-radius: 6px;
line-height: normal;
color: #eee;
font-weight: 400;
letter-spacing: 2px;
border: 0px;
display: block;
font-size: 18px;
/* add these properties */
position: absolute;
top:0;
right:0;
z-index:100; /* <=====choose the correct value*/
}
But you have to make sure that the parent div has same height as the input and button does and relatively positioned.
If it is not possible then you can wrap them into another div or better with label and style it with same height property of the input and button but the div still needs the relative position and button should be absolutely positioned. I would do it with label:
<label>
<input type="text" />
<button>search</button>
</label>
Then in the CSS:
.sp-module_searchfrontpage label{
width: 100%;
height: 53px;
position: relative;
}
button._searchfrontpage {
background: #333;
height: 53px;
width: 70px;
border-radius: 6px;
line-height: normal;
color: #eee;
font-weight: 400;
letter-spacing: 2px;
border: 0px;
display: block;
font-size: 18px;
/* add these properties */
position: absolute;
top:0;
right:0;
z-index:100; /* <=====choose the correct value*/
}