css link automatic margin to bigger link - html

I've the following problem:
The a tags automatically align to the bottom of the bigger a tag.
I would like to know why and what i can do against it.
Here is my code:
body {
margin: 0;
font-family: 'Ubuntu', sans-serif;
}
#navigation {
background-color: #760209;
width: 100%;
height: 55px;
}
#navigation a {
text-decoration: none;
color: #FFF;
/*line-height: 55px;*/
}
#navigation .logo {
font-size: 28px;
font-weight: bold;
}
<div id="navigation">
<div class="container_12">
<a class="logo" href="#">test1</a>
<a class="btn" href="#">Mein Profil</a>
<a class="btn" href="#">Fragen</a>
</div>
</div>

Do a vertical-align to your <a>
#navigation a {
text-decoration: none;
color: #FFF;
/*line-height: 55px;*/
vertical-align:middle; //This line over here
}

You need the vertical-align css property.
You can either use vertical-align: middle; or vertical-align: top;
body {
margin: 0;
font-family: 'Ubuntu', sans-serif;
}
#navigation {
background-color: #760209;
width: 100%;
height: 55px;
}
#navigation a {
text-decoration: none;
color: #FFF;
vertical-align: middle; /* <------- */
}
#navigation .logo {
font-size: 28px;
font-weight: bold;
}
<div id="navigation">
<div class="container_12">
<a class="logo" href="#">test1</a>
<a class="btn" href="#">Mein Profil</a>
<a class="btn" href="#">Fragen</a>
</div>
</div>

You can add:
.btn{
vertical-align:top;
}
if you need to align them to the top.
The default value of vertical align is baseline, which means that the element will be aligned to the baseline of the parent element.
That's why in your case the other 2 links seems aligned to the bottom comparing to the first element, just because of different font-size.

Related

How to make make a margin-bottom in the headline?

The following code snippet shows my wished position for my headline in the footer.
* {
box-sizing: border-box;
}
/*HEADER*/
.header{
overflow: hidden;
height: 91px;
background-color: #000000;
width: 100%;
}
.header a {
color: #34E034;
text-decoration: none;
}
.header a.logo {
font-family: Wiz;
font-size: 55px;
font-weight: bold;
}
html, body {
margin:0;
padding:0;
}
<div class = "header">
<div class="header-row">
<div class="left-main-header">
<div class="header-box">
<div class="new-header">Techwizards</div>
<a class="logo"><b>Techwizards</b></a>
</div>
</div>
</div>
</div>
If I now wanna add a font style for the headline. This one:
#font-face {
src: url("fonts/MagicSchoolTwo.ttf");
font-family: wiz;
}
I don't have margin to the bottom like in this picture.
I tried everything - margin, padding but I don't get the space to the bottom. How can I fix that?
Fixed Your Code:
You had an absolute height on your header. Then an "a" tag can't have a margin on default, you have to set it on display block to render the margin. I also added display flex to your header as suggested in the comments.
Codepen
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
}
/*HEADER*/
.header {
background-color: #000000;
width: 100%;
display: flex;
}
.header a {
color: #34e034;
text-decoration: none;
}
.header a.logo {
font-family: Wiz;
font-size: 55px;
font-weight: bold;
display: block;
margin-bottom: 40px;
}
<div class="header">
<div class="header-row">
<div class="left-main-header">
<div class="header-box">
<div class="new-header">Techwizards</div>
<a class="logo"><b>Techwizards</b></a>
</div>
</div>
</div>
</div>

How I can add centered horizontal line behind the link using css?

I need to add centered horizontal line behind the link, so when I change size of the screen this line stays centered behind the link and moves with it. Also I need this line to be on the full width of screen.
On first image is what I have right now:
On the second image is what I need, as yo can see there thin gray line centered behind "V" link:
My html code of this link:
<div class="welcome-content">
<h1 class="welcome-text">Welcome To Kramerica Industries</h1>
<div class="explore-container">
<a class="v-explore-button" href="#about"><i class="fa fa-angle-down fa-lg" aria-hidden="true"></i></a>
<p class="explore-text">Explore</p>
</div>
</div>
My Sass:
.welcome-text {
text-align: center;
font-family: "Droid Sans Bold", "sans-serif";
color: #ffffff;
}
.explore-container {
position: absolute;
top: 147%;
left: 38%;
.v-explore-button {
text-decoration: none;
color: #ffffff;
background-color: #2ecc71;
padding: 15px 20px;
border-radius: 100%;
}
.explore-text {
margin-top: 20px;
color: #ffffff;
}
}
How about to use ::before inline block pseudoelement for button class in pair with transform:translateY(50% of the button width);and 100% width?
body{
background-color: black;
}
.welcome-text {
text-align: center;
font-family: "Droid Sans Bold", "sans-serif";
color: #ffffff;
}
.explore-container {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.v-explore-button {
display: flex;
align-items: center;
position: relative;
text-decoration: none;
color: #ffffff;
background-color: #2ecc71;
padding: 15px 20px;
border-radius: 100%;
}
.explore-text {
margin-top: 20px;
color: #ffffff;
}
.explore-container:before {
content: "";
position: absolute;
top: 1em;
left: 0;
width: 100%;
height: .15em;
background-color: #00bade;
}
.inner-wrap{
margin-right: 38%;
}
<div class="welcome-content">
<h1 class="welcome-text">Welcome To Kramerica Industries</h1>
<div class="explore-container">
<div class="inner-wrap">
<a class="v-explore-button" href="#about"><i class="fa fa-angle-
down fa-lg" aria-hidden="true"></i></a>
<p class="explore-text">Explore</p>
</div>
</div>
</div>
My recommendation would be to use a pseudo-element such as before:
See example for the solution. Let me know if this helps.
You can use the translate property to align elements inside a
container in the middle as demonstrated below without needing to
calculate the approximate % value to align it.
Instead of giving left:38% to your explore-container, set its width to 100% and align the elements using text-align:center as shown below.
I hope this helps.
.welcome-text {
text-align: center;
font-family: "Droid Sans Bold", "sans-serif";
}
.explore-container {
position: absolute;
top: 147%;
margin:0 auto;
width:100%;
text-align:center;
}
.v-explore{
position:relative;
background:yellow;
}
.v-explore-button {
text-decoration: none;
background-color: #2ecc71;
color:#ffffff;
padding: 15px 20px;
border-radius: 100px;
position:absolute;
top:50%;
transform: translate(-50%, -50%);
}
.explore-text {
margin-top: 20px;
}
<div class="welcome-content">
<h1 class="welcome-text">Welcome To Kramerica Industries</h1>
<div class="explore-container">
<div class="v-explore">
<a class="v-explore-button" href="#about">v</a>
<hr>
</div>
<p class="explore-text">Explore</p>
</div>
</div>

How to center link in nav bar vertically

I would like to center my Profile and Skills links in the nav bar. You can take a look at what I have here:
http://rikinkatyal.me/
I have tried many methods and none seem to work.
Thanks in advance.
Instead of messing about with inline styles, clean up your HTML and replace your HTML & CSS for the header in your 'index.css' file with the following CSS and HTML.
CSS for header
#header {
position: fixed;
height: 70px;
width: 100%;
background-image: url(http://rikinkatyal.me/images/header.png);
background-size: 100%;
background-repeat: repeat;
margin: 0px;
z-index: 2;
}
.navBar {
text-align:center;
}
.navBar a {
text-decoration: none;
color: #fff;
font-family:'Source Sans Pro';
font-weight: 300;
-webkit-transition: all 0.5s ease-in-out;
vertical-align: middle;
display:inline-block;
}
.navBar .contactButton {
top: 17px;
right: 10px;
float: right;
position: fixed;
-webkit-border-radius: 28;
-moz-border-radius: 28;
border-radius: 28px;
font-family:'Source Sans Pro';
font-weight: 300;
color: #fff;
font-size: 17px;
padding: 5px 13px 5px 13px;
border: solid #fff 2px;
-webkit-transition: all 0.5s ease-in-out;
}
HTML for header
<div id="header">
<div class="navBar">
PROJECTS
<a href="#main">
<img id="logo" draggable="False" src="http://rikinkatyal.me/images/logo.png" height="70"/></a>
SKILLS
CONTACT
</div>
</div>
Watch this in a demo => http://jsfiddle.net/pxhw53my/
Add display:inline-block; to the image's anchor element container
<div id="header">
<div class="navBar">
PROJECTS
<a href="#main" style="display: inline-block;"> <!-- Add this style attribute here -->
<img class="logo" id="logo" draggable="False" src="images/logo.png" style="display: inline-block;">
</a>
SKILLS
CONTACT
</div>
</div>
Result:
On the navBar div, set the display to table, and on the nested anchors, set the display to table-cell which will allow for vertical alignment.
.navBar {
margin: 0 auto; //text-align center won't work with a table display (in this instance)
display: table;
}
.navBar a {
display: table-cell;
vertical-align: middle;
}
Also, keep in mind that table displays can't use margins, only padding.

How can I get this image done in HTML and CSS?

I have this image that is to be implemented in HTML and CSS.
This is what I have tried.
<span>$</span><span style="font-size: 50px;">99</span><span style="vertical-align: text-top;">00</span>
But this actually doesn't turn out like I want in the image.
For example:
.price {
font-size: 80px;
color: #f60;
}
.price sup {
font-size: 38px;
}
.price sub {
font-size: 28px;
color: #aaa;
position: absolute;
display: inline-block;
margin: 48px 0 0 -40px;
}
<span class="price"><sup>$</sup>99<sup>00</sup><sub>/month</sub></span>
http://jsfiddle.net/1zjuddj8
It sounds like the <sup> tag is your friend here. Any text in the <sup> tags will become superscript.
Example
<sup>$</sup>99<sup>00</sup>
Additional Documentation/Reference from w3.org: http://www.w3.org/TR/html-markup/sup.html
You have a specific tag for make your text appears on the top use <sup></sup> to treat it like an indice and <sub></sub> as a note. To force the alignement you will have to play with vertical-align value in px or in %.
`
<sup style="vertical-align: 10;">$</sup><sub style="font-size: 50px;vertical-align:-10">99</sub><sup style="vertical-align: 10;">00</sup>
You can use sup to make the text superscript and then set the position of the text using position: relative and top:
HTML:
<h1><sup>$</sup>99<sup>00</sup></h1>
CSS:
h1 { font-size: 50px; }
sup { font-size: 15px;
position: relative;
line-height: 0;
vertical-align: baseline;
top: -23px;
}
JS Fiddle
A solution which requires a bit more fine tuning, but has a lot of control, very useful for front-end layouts:
HTML code
<div class="price_tag">
<div class="price"><sup>$</sup><span class="bignum">99</span><sup>00</sup>
</div>
<div class="month">/month</div>
</div>
CSS code
.price_tag {
position:relative;
width:190px;
height:100px;
color:#f90;
font-size:6em;
font-family:helvetica, arial, sans-serif;
}
.price {
position:relative;
width:200px;
height:100px;
font-weight:bold;
}
sup {
position:relative;
font-size:2.5rem;
top:1rem
}
.month {
width:60px;
height:30px;
color:#ccc;
font-size:1rem;
right:0;
bottom:0;
z-index:3;
position:absolute;
}
fiddle here
To duplicate it with accuracy, your code will have to be more involved than that. I've tried to match it as closely as I could here: http://jsfiddle.net/wvcm92ka/
The code is below:
HTML:
<div class="amount">
<div class="amount-parts">
<div class="amount-currency">$</div>
<div class="amount-whole">99</div>
<div style="clear: left;"></div>
</div>
<div class="amount-parts">
<div class="amount-decimal">00</div>
<div class="amount-period">/month</div>
<div style="clear: left;"></div>
</div>
<div style="clear: left;"></div>
</div>
CSS:
.amount-parts{
font-family: verdana, sans-serif;
float: left;
}
.amount-currency, .amount-whole, .amount-decimal, .amount-period{
font-weight: 600;
}
.amount-currency, .amount-whole, .amount-decimal{
color: #ff0000;
}
.amount-currency{
float: left;
font-size: 32pt;
font-weight: bold;
margin-top: 5px;
}
.amount-whole{
font-size: 60pt;
float: left;
}
.amount-decimal{
color: #ff0000;
font-size: 24pt;
font-weight: bold;
margin-top: 15px;
}
.amount-period{
color: #999;
font-size: 10pt;
font-weight: bold;
}
Another solution:
body {
font-size: 20px;
}
.div-table {
display: table;
border-collapse: collapse;
}
.div-table .div-table-row {
display: table-row;
}
.div-table .div-table-cell {
display: table-cell;
text-align: left;
vertical-align: top;
}
.big-number {
font-size: 50px;
}
.padding-top {
padding-top: 5px;
}
<div class="div-table">
<div class="div-table-row">
<div class="div-table-cell padding-top">
$
</div>
<div class="div-table-cell">
<span class="big-number">99</span>
</div>
<div class="div-table-cell padding-top">
<div>00</div>
<div>/month</div>
</div>
</div>
</div>
http://jsfiddle.net/gbx0ogqm/

Why won't my text center here?

I have the following CSS:
.me-header {
display: inline-block;
position: relative;
top: 50px;
left: 10px;
}
.me-header a {
color: #333;
font: 10px "Lucida Grande", Helvetica, sans-serif;
text-decoration: none
}
.resume-header {
display: inline-block;
position: relative;
top: 50px;
left: 100px;
}
.resume-header a {
color: #333;
font: 10px "Lucida Grande", Helvetica, sans-serif;
text-align: center;
text-decoration: none
}
.center-text {
text-align: center;
}
And the following HTML:
<div class="me-header">
<img src="media/me-icon.png" alt="Picture of Christian Selig"><br> <span class="center-text">Contact Me</span>
</div>
<div class="resume-header">
<img src="media/resume-icon.png" alt="Resume icon" title="Click to download resume (PDF)"><br> <span class="center-text">Resume (PDF)</span>
</div>
But my text still comes out left-aligned. Why?
Both a and span are inline elements - so they are only as wide as their contents. So when you center the text, it is centred within the inline element, but the inline element appears on the left.
If you set text-align: center; on the parent block element it will work.
If you want to center the whole block, use an automatic margin.
You could do
.center-text
{
display: table;
margin: 0 auto;
}