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>
Related
I created an "a" element that closes a modal when clicked on by taking you to the home page. I made it look like a close button. However, I can't seem to vertically center the "X" in it. I tried enclosing it inside a "button" element but that caused other problems.
Below is the code:
:root {
--main-color: #ffc40c;
--secondary-color: lightyellow;
--main-red: #d9001d;
--secondary-red: #ff033e;
--dark-color: #444;
--light-color: #fafafa;
}
body {
font-family: "Source Code Pro", monospace;
background-color: var(--light-color);
color: var(--dark-color);
margin-top: 50px;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
text-shadow: 1px 1px 5px var(--light-color);
}
a {
text-decoration: none;
}
.close-button {
height: 30px;
width: 30px;
background-color: var(--light-color);
color: var(--main-red);
margin-left: 0.5em;
border: 2px solid var(--main-red);
border-radius: 50%;
font-weight: 700;
text-align: center;
}
.close-modal {
position: fixed;
top: 2.8em;
right: 1.7em;
}
<a class="close-button close-modal" href="#!"> X </a>
How do I vertically center it?
a super easy way to center these things is display: grid; place-items: center;
try adding these attributes to .close-button
Try using flexbox for aligning items.
I added :
display:flex;
justify-content:center;
align-items:center;
to your .close-button class.
Here's the result.
:root {
--main-color: #ffc40c;
--secondary-color: lightyellow;
--main-red: #d9001d;
--secondary-red: #ff033e;
--dark-color: #444;
--light-color: #fafafa;
}
body {
font-family: "Source Code Pro", monospace;
background-color: var(--light-color);
color: var(--dark-color);
margin-top: 50px;
margin-left: 0;
margin-right: 0;
margin-bottom: 0;
text-shadow: 1px 1px 5px var(--light-color);
}
a {
text-decoration: none;
}
.close-button {
display:flex; /*flexbox a.k.a flexible layout */
justify-content:center; /*for horizontally centering*/
align-items:center; /* for vertically centering*/
height: 30px;
width: 30px;
background-color: var(--light-color);
color: var(--main-red);
margin-left: 0.5em;
border: 2px solid var(--main-red);
border-radius: 50%;
font-weight: 700;
text-align: center;
}
.close-modal {
position: fixed;
top: 2.8em;
right: 1.7em;
}
<a class="close-button close-modal" href="#!"> X </a>
You need add padding-top: 10px for your a tag
Need to make two buttons align a few pixels left and right of the centre
I need div left to be 1px to the left of the centre. And right to be 1px right of it.
Any ideas how?
.btn {
font-family: helvetica;
font-weight: bolder;
padding: 10px;
border-radius: 2px;
color: black;
border: 2px solid black;
background-color: white;
width: 100px;
text-decoration: none;
}
.btn2 {
font-family: helvetica;
font-weight: bolder;
padding: 10px;
border-radius: 2px;
color: white;
border: 2px solid white;
background-color: black;
width: 100px;
text-decoration: none;
}
.divleft {
margin: auto 0;
text-align: left;
}
.divright {
margin: auto 0;
text-align: right;
}
<div class="divleft"> Memento </div>
<div class="divright"> Mori </div>
Use flexbox:
.box {
display: flex;
width: 100%;
}
.left,
.right {
width: 100%;
}
.left {
text-align: right;
margin-right: 10px;
}
a {
font-family: helvetica;
font-weight: bolder;
padding: 10px;
border-radius: 2px;
border: 2px solid black;
width: 100px;
text-decoration: none;
}
.btn {
color: black;
background-color: white;
}
.btn2 {
color: white;
background-color: black;
}
<div class="box">
<div class="left">
Memento
</div>
<div class="right">
Mori
</div>
</div>
Codepen: https://codepen.io/manaskhandelwal1/pen/jOMgpbd
I created a CodePen that shows how to make it work: https://codepen.io/kaireidcasey/pen/rNMXrde
The parent element needs display: flex set on it. The children each need an auto margin on one side. I am sure there are other ways to solve this, as well.
Code snippets:
HTML:
<div class="container">
<div class="divleft">
Memento
</div>
<div class="divright">
Mori
</div>
</div>
CSS:
.btn {
font-family: helvetica;
font-weight: bolder;
padding: 10px;
border-radius: 2px;
color: black;
border: 2px solid black;
background-color: white;
width: 100px;
text-decoration: none;
}
.btn2 {
font-family: helvetica;
font-weight: bolder;
padding: 10px;
border-radius: 2px;
color: white;
border: 2px solid white;
background-color: black;
width: 100px;
text-decoration: none;
}
.divleft {
margin-right: 1px;
margin-left: auto;
}
.divright {
margin-left: 1px;
margin-right: auto;
}
.container {
display: flex;
}
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;
}
I'm trying to make a login form with block icons before the input fields.
#import url(http://meyerweb.com/eric/tools/css/reset/reset.css);
#import url(http://weloveiconfonts.com/api/?family=fontawesome);
[class*="fontawesome-"]:before {
font-family: 'FontAwesome', sans-serif;
}
#login {
margin: 50px auto;
width: 300px;
background: #999;
padding: 50px;
}
#login p {
line-height: 50px;
}
#login p span {
display: inline-block;
width: 30px;
height: 30px;
line-height: 30px;
padding: 3px;
text-align: center;
border: 1px solid #ccc;
background: #ccc;
color: #fff;
}
#login p input {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
padding: 3px;
width: 200px;
height: 30px;
line-height: 30px;
border: 1px solid #ccc;
background: #fdfdfd;
}
html
<div id="login">
<p><span class="fontawesome-user"></span><input type="text" placeholder="Username"></p>
<p><span class="fontawesome-lock"></span><input type="password" placeholder="Password"></p>
</div>
Unfortunately, I can not precisely align the block (span) icon with the input field. How could I do this? thanks
Example
You need to vertical-align the inline-block elements, eg :
#login p > * {
vertical-align:middle;
}
Forked Fiddle
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;
}