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;
}
Related
I'm trying to put a border in a button, I tried to create 2 div and then do display: inline-block but it doesn't work, here is my code:
`#vid {
position: absolute;
width: 95px;
height: 60px;
background-color: #ffff;
border: #ffff;
font-size: 13px;
font-family: Arial, Helvetica, sans-serif;
display: inline-block;
}
#h5-vid {
border-radius: 25px;
background: #ffff;
border-color: black;
display: inline-block;
}
<button id="vid"><p>Videos</p><div id="h5-vid"><h5 id="h5-text-vid">New!</h5></button></div>`
This is what I want to get:
This is what I got:
Put both elements with text inside the button:
<button id="vid">
<p>Videos</p>
<h5 id="h5-text-vid">NEW</h5>
</button>
Use display: flex; with justify and align center for the button then simply add border to the h5 element using border: solid 1px black;
Here is a working snippet:
#vid {
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
width: 95px;
height: 60px;
background-color: #ffff;
border: none;
font-size: 13px;
font-family: Arial, Helvetica, sans-serif;
}
#h5-text-vid {
border: solid 1px black;
border-radius: 25px;
padding: 3px;
font-size: 6pt;
font-weight: 800;
}
body {
/* Just for demo */
background-color: gray;
}
<button id="vid">
<p>Videos</p>
<h5 id="h5-text-vid">NEW</h5>
</button>
Your code didn't work because p tag is block element.
And also p and h5 tag has margin-block-start and margin-block-end.
So I removed those margins, and set display: inline-block to p tag.
Now, it works.
Note: You set border-color to div#h5-vid, but didn't work because div doesn't have border in default.
So I changed it as border: 1px solid black.
p, h5 {
margin-block-start: 0;
margin-block-end: 0;
display: inline-block;
}
#vid{
position: absolute;
width: 95px;
height: 60px;
background-color: #fff;
border: #fff;
font-size: 13px;
font-family: Arial, Helvetica, sans-serif;
display: inline-block;
}
#h5-vid{
border-radius: 25px;
background: #fff;
border: 1px solid black;
display: inline-block;
margin-left: 5px;
padding: 0 3px;
}
<button id="vid"><p>Videos</p><div id="h5-vid"><h5 id="h5-text-vid">New!</h5></div></button>
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>
* {
margin: 0;
padding: 0;
}
.box {
width: 230px;
border: 1px solid red;
}
input {
width: 30px;
line-height: 20px;
background: #e5e5e5;
border: 0;
text-align: center;
padding: 0 5px;
font-size: 14px;
}
span {
padding: 0 2px;
cursor: pointer;
line-height: 20px;
font-size: 14px;
display: inline-block;
}
<div class="box">
<span>xx</span>
<input type="text" value="322xxx">
I want to know why there is 1px space between bottom of span and bottom of outdiv? can someone help me out?
You need to set vertical-align:top for the display: inline-block span tag
*{
margin: 0;
padding: 0;
}
.box{
width: 230px;
border:1px solid red;
}
input{
width: 30px;
line-height: 20px;
background: #e5e5e5;
border: 0;
text-align: center;
padding: 0 5px;
font-size: 14px;
}
span{
padding: 0 2px;
cursor: pointer;
line-height:20px;
font-size: 14px;
display: inline-block;
vertical-align: top;
}
<div class="box">
<span>xx</span>
<input type="text" value="322xxx">
By default, a span element is an inline level element, which respects the whitespace in the markup. Thats the reason a small space between the input and span. Thanks..
I want the link to be on the left of "info" div, but I can't figure out a way to do it, text-align: left; is not working. I think that maybe the CSS is interfering with the text-align property.
#font-face {
font-family: myFirstFont;
src: url(Minecraftia.ttf);
}
a {
font-family: myFirstFont;
text-decoration: none;
font-size: 13px;
}
div#comment {
border-radius: 4px;
margin: 0 auto;
padding: 0 3px;
width: 600px;
}
input[type=submit] {
background-color: white;
font-size: large;
padding: 14px 20px;
margin: 8px 0;
border: 3px solid green;
border-radius: 10px;
cursor: pointer;
font-family: myFirstFont;
text-align: center;
}
input[type=text], input[type=mail], select {
width: 600px;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #CCC;
border-radius: 4px;
box-sizing: border-box;
background-color: #F8F8F8;
font-family: myFirstFont;
}
textarea {
width: 600px;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #CCC;
border-radius: 4px;
box-sizing: border-box;
background-color: #F8F8F8;
font-family: myFirstFont;
resize: none;
}
p
{
font-family: myFirstFont;
font-size: 13px;
margin: 0 auto;
}
div#info {
border-radius: 4px;
margin: 0 auto;
padding: 0 3px;
width: 600px;
border-bottom: 1px solid green;
}
form {
text-align: center;
}
<div id="info"><p>Pringui - 25 août 2016 - Modifier</p></div><div id="comment"> <p>Hello World.</p></div>
You can use floating to move the link before the other text:
a {
float: left;
}
#font-face {
font-family: myFirstFont;
src: url(Minecraftia.ttf);
}
a {
font-family: myFirstFont;
text-decoration: none;
font-size: 13px;
float: left;
}
a::after {
content: ' - ';
white-space: pre;
}
div#comment {
border-radius: 4px;
margin: 0 auto;
padding: 0 3px;
width: 600px;
}
input[type=submit] {
background-color: white;
font-size: large;
padding: 14px 20px;
margin: 8px 0;
border: 3px solid green;
border-radius: 10px;
cursor: pointer;
font-family: myFirstFont;
text-align: center;
}
input[type=text],
input[type=mail],
select {
width: 600px;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #CCC;
border-radius: 4px;
box-sizing: border-box;
background-color: #F8F8F8;
font-family: myFirstFont;
}
textarea {
width: 600px;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #CCC;
border-radius: 4px;
box-sizing: border-box;
background-color: #F8F8F8;
font-family: myFirstFont;
resize: none;
}
p {
font-family: myFirstFont;
font-size: 13px;
margin: 0 auto;
}
div#info {
border-radius: 4px;
margin: 0 auto;
padding: 0 3px;
width: 600px;
border-bottom: 1px solid green;
}
form {
text-align: center;
}
<div id="info">
<p>Pringui - 25 août 2016 Modifier
</p>
</div>
<div id="comment">
<p>Hello World.</p>
</div>
If I understand what you're wanting correctly, then you don't need to edit the CSS. You can just move the anchor to the left of the content inside that div. Or if you want it before the div completely move it outside of the div. If that's not an option you can float the div right and then float the anchor left. But this is a pretty sloppy solution. It'd be better to simply rearrange the HTML.
#font-face {
font-family: myFirstFont;
src: url(Minecraftia.ttf);
}
a {
font-family: myFirstFont;
text-decoration: none;
font-size: 13px;
}
div#comment {
border-radius: 4px;
margin: 0 auto;
padding: 0 3px;
width: 600px;
}
input[type=submit] {
background-color: white;
font-size: large;
padding: 14px 20px;
margin: 8px 0;
border: 3px solid green;
border-radius: 10px;
cursor: pointer;
font-family: myFirstFont;
text-align: center;
}
input[type=text], input[type=mail], select {
width: 600px;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #CCC;
border-radius: 4px;
box-sizing: border-box;
background-color: #F8F8F8;
font-family: myFirstFont;
}
textarea {
width: 600px;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #CCC;
border-radius: 4px;
box-sizing: border-box;
background-color: #F8F8F8;
font-family: myFirstFont;
resize: none;
}
p
{
font-family: myFirstFont;
font-size: 13px;
margin: 0 auto;
}
div#info {
border-radius: 4px;
margin: 0 auto;
padding: 0 3px;
width: 600px;
border-bottom: 1px solid green;
float: right;
}
#info a {
float: left;
margin-right: 5px;
}
form {
text-align: center;
}
<div id="info"><p>Pringui - 25 août 2016 - Modifier</p></div><div id="comment"> <p>Hello World.</p></div>
How to make this effect (cross-browsed) without using float: left?
I need to center this form so float attribute is wrong for me. Anybody can help?
I've made code as you can see below.
My code:
footer input[type=text] {
border-top: 1px solid #efefef;
border-left: 1px solid #efefef;
border-bottom: 1px solid #efefef;
border-right: 0;
width: 230px;
padding: 0 10px;
font-size: 16px;
line-height: 18px;
height: 35px;
display: inline-block;
float: left;
margin: 0 auto;
}
footer input[type=submit] {
border: 1px solid #df242b;
background: #df242b url('../../../gfx/submit.jpg') no-repeat center center;
color: #fff;
width: 38px;
height: 37px;
font-size: 18px;
line-height: 18px;
cursor: pointer;
display: inline-block;
float: left;
margin: 0 auto;
}
Because you want it cross-browser and without using float:left, you can use inline-block with vertical-align:top
And to center, you need to apply margin:0 auto to footer with some width instead
I made a few tweaks to your code.
*,
*::before,
*::after {
box-sizing: border-box
}
body {
margin: 0;
/* demo */
background: lightgreen
}
footer {
/*fix inlin block gap */
font-size: 0;
margin: 0 auto;
width: 265px; /* 230px + 35px */
}
footer input {
line-height: 18px;
height: 35px;
display: inline-block;
vertical-align: top;
}
footer input[type=text] {
border: solid #efefef;
border-width: 1px 0 1px 1px;
width: 230px;
padding: 0 10px;
font-size: 16px;
}
footer input[type=submit] {
border: 1px solid #df242b;
background: #df242b url('//dummyimage.com/35x35') no-repeat center center;
color: #fff;
width: 35px;
font-size: 18px;
cursor: pointer
}
<footer>
<input type="text">
<input type="submit">
</footer>
Your code without float:left actually works fine. Maybe you experience the line break on small sized screens. If it is the case, just add a piece of CSS for your footer like this example.
footer {
white-space: nowrap;
text-align: center;
}
footer input[type=text] {
border: 1px solid #efefef;
border-right: 0;
width: 230px;
padding: 0 10px;
font-size: 16px;
line-height: 18px;
height: 35px;
display: inline-block;
margin: 0 auto;
}
footer input[type=submit] {
border: 1px solid #df242b;
background: #df242b url('../../../gfx/submit.jpg') no-repeat center center;
color: #fff;
width: 38px;
height: 37px;
font-size: 18px;
line-height: 18px;
cursor: pointer;
display: inline-block;
margin: 0 auto;
}
<footer>
<input type="text" />
<input type="submit" />
</footer>
Use like this
<style>
body{margin:0;}
footer{
width:100%;
background:#ccc;
height:250px;
}
.form{
width:292px;
margin:0 auto;
}
footer input[type=text] {
border-top: 1px solid #efefef;
border-left: 1px solid #efefef;
border-bottom: 1px solid #efefef;
border-right: 0;
width: 230px;
padding: 0 10px;
font-size: 16px;
line-height: 18px;
height: 37px;
display: inline-block;
float: left;
margin: 0 auto;
}
footer input[type=submit] {
border: 1px solid #df242b;
background: #df242b;
color: #fff;
width: 38px;
height: 37px;
font-size: 18px;
line-height: 18px;
cursor: pointer;
display: inline-block;
float: left;
margin: 0 auto;
}
</style>
<footer>
<div class="form">
<input type="text">
<input type="submit" value=">">
</div>
</footer>