Aligning a button link within a container div - html

I've created a button but I'd like to align it within a container div so it looks like:
My code is:
body {
background-color: black;
}
.buttoncontainer {
background-color: white;
border-radius: 5px;
padding: 5px 5px 5px 5px;
width: 285px;
height: 55px;
}
#button2:hover {
background-color: #feb73b;
}
#button2 {
border: 1px solid black;
border-radius: 7px;
color: #fff;
text-decoration: none;
background-color: #fea710;
display: inline-block;
text-transform: uppercase;
font-size: 20px;
padding: 12px 32px;
font-family: arial;
letter-spacing: .5px;
font-weight: 400;
margin-top: 20px;
}
HTML
<div class="buttoncontainer">
start a free trial
</div>
Link to Fiddle
Any advice?
Apologies for not posting the links as pictures, I do not have enough reputation yet.

Remove margin-top: 20px; from your #button2 CSS
See the fiddle
Thus the CSS would be like
#button2 {
border: 1px solid black;
border-radius: 7px;
color: #fff;
text-decoration: none;
background-color: #fea710;
display: inline-block;
text-transform: uppercase;
font-size: 20px;
padding: 12px 32px;
font-family: arial;
letter-spacing: .5px;
font-weight: 400;
/* margin-top: 20px; */
}
UPDATE
See the updated fiddle
I've changed the padding in the css as padding: 14px 32px;. So it gets centered.

In button2' style :
Remove margin-top
Set display as block
Then :
width:100%;
height:100%;
box-sizing: border-box;
Fiddle : http://jsfiddle.net/by3pe47d/7/

So what I did was swap the id's and class and I added the button 2 class to the html.
I added a position: relative; attribute to the container so the insides would stay inside.
Also if you want to change the position of it like left, right, etc. you can.
I also changed the top margain to 2px instead of 20px
http://jsfiddle.net/by3pe47d/10/
Html-
<div id="buttoncontainer">
<div class="button2">
start a free trial
</div>
</div>
Css-
body {
background-color: black;
}
#buttoncontainer {
position: relative;
background-color: white;
border-radius: 5px;
padding: 5px 5px 5px 5px;
width: 285px;
height: 55px;
}
.button2 {
border: 1px solid black;
border-radius: 7px;
color: #fff;
text-decoration: none;
background-color: #fea710;
display: inline-block;
text-transform: uppercase;
font-size: 20px;
padding: 12px 32px;
font-family: arial;
letter-spacing: .5px;
font-weight: 400;
margin-top: 2px;
}
.button2:hover {
background-color: #feb73b;
}
Large Update
Saw the image that was removed and made a thing that mimics it. It will stay formatted even if you use the left, right, etc. attributes.
http://jsfiddle.net/by3pe47d/11/

Related

Problem with vertical alignment in some custom <li> and <span> tag

I try to create an element similar to the "chip" element presents in the Angular Material library (https://material.angular.io/components/chips/overview).
The element I want to build has a li tag that acts as a container, inside this element, I insert two span tags, one that contains the text and the other that contains the "x" that enable the user to delete the whole chip.
I have a small x (font-size: 10px) that is inline with text.
I would like to make the x bigger (around 18px or 20 px), but when I try to enlarge it, I am no more able to align it with the text ( the text drop down )
Here is my code:
.selection-choice {
float: left;
padding: 0px 15px 0px 5px;
background-color: rgb(102, 0, 204);
color: white;
height: 28px;
border-radius: 14px;
font-size: 13px;
box-sizing: border-box;
display: list-item;
list-style: none;
line-height: 15px;
font-family: sans-serif;
}
.selection-choice-remove {
border: 1px white solid;
margin: 4px 5px 0px 0px;
padding: 2px 5px 0px 6px;
height: 75%;
color: white;
width: 20px;
border-radius: 14px;
cursor: pointer;
display: inline-block;
font-weight: bold;
box-sizing: border-box;
font-family: sans-serif;
font-size: 10px;
}
<li class="selection-choice" title="EXAMPLE">
<span class="selection-choice-remove" role="presentation">×</span>
<span>EXAMPLE</span>
</li>
Thanks a lot to who can help me.
When you use padding to position the X, it's not going to scale properly if you change any sizings (whether that be the sizing of the font or the sizing of any parent/child elements). Try changing the last value (padding-left) depending on the size of the font you assign to the X. In this case, change padding: 2px 5px 0px 6px to padding: 2px 5px 0px 4px. You can also add a class to the text and give it position: relative and position it accordingly.
.selection-choice {
float: left;
padding: 0px 15px 0px 5px;
background-color: rgb(102, 0, 204);
color: white;
height: 28px;
border-radius: 14px;
font-size: 13px;
box-sizing: border-box;
display: list-item;
list-style: none;
line-height: 15px;
font-family: sans-serif;
}
.text {
position: relative;
bottom: 1px;
}
.selection-choice-remove {
border: 1px white solid;
margin: 4px 5px 0px 0px;
padding: 2px 5px 0px 4px;
height: 75%;
color: white;
width: 20px;
border-radius: 14px;
cursor: pointer;
display: inline-block;
font-weight: bold;
box-sizing: border-box;
font-family: sans-serif;
font-size: 17px;
}
<li class="selection-choice" title="EXAMPLE">
<span class="selection-choice-remove" role="presentation">×</span>
<span class="text">EXAMPLE</span>
</li>
You can try display:flex for the 'selection-choice' it will keep the x icon and the text are same line and middle in vertical.
About the x icon, I have removed the padding and margin; you just use text-align:center and line-height to make it in the middle
.selection-choice {
float: left;
padding: 0 5px;
background-color: rgb(102, 0, 204);
color: white;
height: 28px;
border-radius: 14px;
font-size: 13px;
box-sizing: border-box;
display: list-item;
list-style: none;
line-height: 15px;
font-family: sans-serif;
display: flex;
justify-content: space-between;
align-items: center;
}
.selection-choice-remove {
border: 1px white solid;
margin: 0;
padding: 0;
height: 20px;
width: 20px;
color: white;
border-radius: 50%;
cursor: pointer;
display: inline-block;
font-weight: bold;
box-sizing: border-box;
font-family: sans-serif;
font-size: 18px;
text-align: center;
line-height: 16px;
}
.selection-choice .text{
padding:5px 7px
}
<li class="selection-choice" title="EXAMPLE">
<span class="selection-choice-remove" role="presentation">×</span>
<span class="text">EXAMPLE</span>
</li>
Maybe it useful to you.
now its font-size is equal to 18px;
.selection-choice {
float: left;
padding: 0px 15px 5px 5px;
background-color: rgb(102, 0, 204);
color: white;
height: 28px;
border-radius: 14px;
font-size: 13px;
box-sizing: border-box;
display: list-item;
list-style: none;
line-height: 15px;
font-family: sans-serif;
}
.selection-choice-remove {
text-align: center;
border: 1px white solid;
margin: 4px 5px 0px 0px;
padding: 2px auto 0px ;
color: white;
width: 20px;
height: 20px;
line-height: 18px;
border-radius: 100%;
cursor: pointer;
display: inline-block;
font-weight: bold;
box-sizing: border-box;
font-family: sans-serif;
font-size: 18px;
}
<li class="selection-choice" title="EXAMPLE">
<span class="selection-choice-remove" role="presentation">×</span>
<span>EXAMPLE</span>
</li>

vertical position of an a-element and button-element

I want to style a <button> and <a> element both into the same format. I use the following code:
button,
a {
border: solid 1px black;
background-color: white;
color: black;
font-family: 'Arial';
padding: 0 15px;
font-size: 13px;
height: 35px;
line-height: 35px;
display: inline-block;
}
#dummy-block {
background-color: black;
padding: 0;
margin: 0;
height: 20px;
}
<div id="dummy-block"></div>
<button>My Button</button>
<a>My Link</a>
But the <button> element seems to ignore the height and my <a> element does not touch the edge of the black dummy <div> above:
You can test the code in my fiddle: http://jsfiddle.net/gyrrcrqc/1/
Try this:-
button, a {
background-color: white;
border: medium none;
box-shadow: 0 0 1px #000 inset;
color: black;
display: inline-block;
font-family: "Arial";
font-size: 13px;
height: 35px;
line-height: 35px;
padding: 0 15px;
vertical-align: top;
}
Or:-
button, a {
background-color: white;
border: medium none;
vertical-align:top;
color: black;
display: inline-block;
font-family: "Arial";
font-size: 13px;
height: 35px;
line-height: 35px;
padding: 0 15px;
border:1px solid #000;
box-sizing:border-box
}
DEMO2
DEMO
Apparently the default box-sizing method for button is border-box while that for inline-block is content-box. So:
35px height means the <a> is actually 37px tall (border adds 2px)
35px height means the <button> tag is 35px tall (35px includes the border)
Set the box-sizing: border-box on both elements.
button,
a {
border: solid 1px black;
background-color: white;
color: black;
font-family: 'Arial';
padding: 0 15px;
font-size: 13px;
height: 35px;
line-height: 35px;
display: inline-block;
box-sizing: border-box;
}
#dummy-block {
background-color: black;
padding: 0;
margin: 0;
height: 20px;
}
<div id="dummy-block"></div>
<button>My Button</button>
<a>My Link</a>
try adding vertical-align: bottom to button, a selector
button, a
{
border: solid 1px black;
background-color: white;
color: black;
font-family: 'Arial';
padding: 0 15px;
font-size: 13px;
height: 35px;
line-height: 35px;
display: inline-block;
vertical-align: top;
}
#dummy-block
{
background-color: black;
padding: 0;
margin: 0;
height: 20px;
}
<div id="dummy-block"></div>
<button>Okay</button>
<a>Edit</a>
a
{
padding:1px 15px;
}
button,a
{
border: solid 1px black;
background-color: white;
color: black;
font-family: 'Arial';
font-size: 13px;
height: 35px;
line-height: 35px;
display: inline-block;
}
button
{
padding: 0 15px;
}

Button background not filling completely on Firefox

So I have a button, but here's the issue. On Firefox only does it not completely fill up. As seen here
This is what it should look like
I'm not really sure what to do. Here's the CSS
.button-panel .button {
-webkit-appearance: none;
border: none;
cursor: pointer;
height: 55px;
font-size: 27px;
letter-spacing: 0.05em;
text-align: center;
width: 100%;
font-family: 'Avenir Next';
display: inline-block;
font-weight: 300;
background-color: #6699FF;
outline: 3px solid #6699FF;
line-height: 59px;
}
And a demo http://jsfiddle.net/h7PXe/
Reason why it showing up is that you use line-height bigger than height of element.
Here you can see how box model is woking and were are outlines:
http://i.stack.imgur.com/Q6J6n.png
You can achieve the same look without using basic properties (then it will work in every browser)
.button-panel .button {
display: inline-block;
padding: 7px 0 5px;
border: 3px solid #6699FF;
width: 100%;
font-family: 'Avenir Next';
font-size: 27px;
font-weight: 300;
letter-spacing: 0.05em;
text-align: center;
background-color: #6699FF;
cursor: pointer;
}
http://jsfiddle.net/h7PXe/1/
Do height: 100%. You need to do this or else the browser won't know what to set the height to.
.button-panel .button {
-webkit-appearance: none;
border: none;
cursor: pointer;
height: 55px;
font-size: 27px;
letter-spacing: 0.05em;
text-align: center;
width: 100%;
font-family: 'Avenir Next';
display: inline-block;
font-weight: 300;
background-color: #6699FF;
outline: 3px solid #6699FF;
line-height: 59px;
height: 100%
}
And a demo.

Issue with getting text into the centre of div

I have made some buttons to link people from my site to social media pages and the text in the Google Plus one is too low and I would like it to go higher in the div but I am struggling to do this, my code is here on JS fiddle.
The buttons aren't complete yet, I just want to know how to get the text higher, cheers
.GooglePlus {
color: black;
font-size: 35px;
border-radius: 100px;
padding: 2px;
font-family: Garamond;
font-weight: bold;
height: 40px;
width: 40px;
background-color: #D8D8D8;
text-align: center;
vertical-align: central;
}
a:hover .GooglePlus {
background-color: #FE2E2E;
color: white;
}
Just add line-height:27px; to adjust g+
Code full class:
.GooglePlus {
color: black;
font-size: 35px;
border-radius: 100px;
padding: 2px;
font-family: Garamond;
font-weight: bold;
height: 40px;
width: 40px;
background-color: #D8D8D8;
text-align: center;
vertical-align: middle;
line-height:27px;
}
If i understand you correctly you are just trying to move the text inside of those circle backgrounds higher.
If this is the case you can cheat it with line height as done in this fiddle
http://jsfiddle.net/9dj9u/2/
Which leaves the resulting CSS affected.
.FaceBook {
color: black;
font-size: 35px;
border-radius: 100px;
padding: 2px;
font-family: Calibri;
font-weight: bold;
height: 40px;
width: 40px;
background-color: #D8D8D8;
text-align: center;
line-height:1.1;
}
.GooglePlus {
color: black;
font-size: 35px;
border-radius: 100px;
padding: 2px;
font-family: Garamond;
font-weight: bold;
height: 40px;
width: 40px;
background-color: #D8D8D8;
text-align: center;
vertical-align: middle;
line-height:0.8;
}
Just adjust line-height in percentage values: line-height: 50%, keep increasing or decreasing till you get there, you might also want to adjust padding, and box-sizing... and remove vertical-align
Remember, this isn't quite exact science, because you do not intend the g and the f to stand next to each other like they do in a sentence, watch this: fg, notice how the g normally is indeed lower than the f.
i included the correct vertical-align value and adjusted the height and width
.FaceBook {
color: black;
font-size: 35px;
border-radius: 100px;
padding: 5px;
font-family: Calibri;
font-weight: bold;
height: 40px;
width: 40px;
background-color: #D8D8D8;
text-align: center;
}
a:hover .FaceBook {
background-color: #4c66a4;
color: white;
}
#footer .FaceBook {
display: inline-block;
}
.GooglePlus {
color: black;
font-size: 35px;
border-radius: 100px;*/
border-bottom: 2px solid black;
padding: 2px;
font-family: garamond;
font-weight: bold;
height: 50px;
width: 50px;
background-color: #D8D8D8;
text-align:center ;
vertical-align: text-bottom;
padding: 0px;
}
a:hover .GooglePlus {
background-color: #FE2E2E;
color: white;
}
#footer .GooglePlus {
display: inline-block;
}
#plus {
font-size: 20px;
padding:0px 0px;
}
a {
text-decoration: none;
}

How can I best accomplish this shape on a div with dynamic text inside it?

http://i.imgur.com/Sc1NnFp.png
I need to create that with CSS. I can use an image if absolutely necessary, but either way it needs to be expandable (probably vertically is best for this one).
http://jsfiddle.net/VR2WF/
<div id="cta">
<div class="callus">Call us today!</div>
<div class="phonenumber">404-555-5555</div>
</div>
#cta {
font-family: Arial, sans-serif;
font-weight: bold;
font-size: 20px;
padding: 10px 20px;
color: #FFF;
text-align: center;
text-transform: uppercase;
background: #232323;
max-width: 400px;
margin: auto;
}
.callus, .phonenumber {
display: inline-block;
}
Here is my solution:
http://codepen.io/Chovanec/pen/temKh
<div class="rib"><div class="text">Call us today</div><div class="arrow"><!-- --></div></div>
.rib .text {
font-family: sans-serif;
color: #fff;
background: #000;
padding: 20px 50px 5px 50px;
width: 500px;
font-size: 20px;
text-transform: uppercase;
font-weight: bold;
text-align: center;
}
.rib .arrow {
display: block;
border-width: 20px 300px 0 300px;
border-color: transparent;
border-top-color: #000;
border-style: solid;
height: 0;
width: 0;
overflow: hidden;
}