Reputation: 436
I want my btn class to be shifted right. I have two button classes eg. btn-full, btn-ghost, I want to shift both of them to the right, if I float it to right then their position changes, I don't know why.
<head>
<link rel="stylesheet" type="text/css" href="vendors/css/normalize.css">
<link rel="stylesheet" type="text/css" href="vendors/css/grid.css">
<link rel="stylesheet" type="text/css" href="resources/css/style.css">
<link href='https://fonts.googleapis.com/css?family=Lato:400,100,300,300italic' rel='stylesheet' type='text/css'>
<title>Musica</title>
</head>
<body>
<header>
<div class="hero-text-box">
<h1>Life is the Song.<br> Love is the Music.</h1>
<a class= "btn btn-full" href="#">Listen </a>
<a class="btn btn-ghost" href="#">Show me more</a>
</div>
</header>
</body>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
html{
background-color: #fff;
color: #555;
font-family: 'Lato','Arial',sans-serif;
font-weight: 300px;
font-size: 20px;
text-rendering: optimizeLegibility;
}
.row{
max-width: 1140px;
margin: 0 auto;
}
header{
background-image:linear-gradient(rgba(0, 0, 0, 0.8),rgba(0, 0, 0, 0.8)),url(img/hero.jpg);
background-size: cover;
background-position: center;
height: 100vh;
}
.hero-text-box{
position: absolute;
width: 1140px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
h1{
float: right;
margin: 0;
margin-bottom: 20px;
color: #fff;
font-size: 240%;
font-weight: 300;
text-transform: uppercase;
letter-spacing: 1px;
word-spacing: 4px;
}
.btn:link,
.btn:visited{
display: inline-block;
padding: 10px 30px;
font-weight: 300;
text-decoration: none;
border-radius: 200px;
color: #fff;
transition: background-color 0.2s, border 0.2s, color 0.2s;
margin-top: 150px;
}
.btn-full:link,
.btn-full:visited{
background-color: #2ecc71;
border: 1px solid #2ecc71;
color: #fff;
margin-right: 15px;
}
.btn-ghost:link,
.btn-ghost:visited{
border: 1px solid #2ecc71;
color: #2ecc71;
}
.btn:hover,
.btn:active{
background-color: #1e874b;
}
.btn-full:hover,
.btn-full:active{
border: 1px solid #1e874b;
}
.btn-ghost:hover,
.btn-ghost:active{
border: 1px solid #1e874b;
color: #fff;
}
I tried everything like float:right, the position:absolute; ;left:-5oo; but it doesnot work. Please help
Upvotes: 1
Views: 60
Reputation: 701
Maybe you want something like this ?
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
html{
background-color: #fff;
color: #555;
font-family: 'Lato','Arial',sans-serif;
font-weight: 300px;
font-size: 20px;
text-rendering: optimizeLegibility;
}
.row{
max-width: 1140px;
margin: 0 auto;
}
header{
background-image:linear-gradient(rgba(0, 0, 0, 0.8),rgba(0, 0, 0, 0.8)),url(img/hero.jpg);
background-size: cover;
background-position: center;
height: 100vh;
}
.hero-text-box{
position: absolute;
width: 1140px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align:right;
}
h1{
margin: 0;
margin-bottom: 20px;
color: #fff;
font-size: 240%;
font-weight: 300;
text-transform: uppercase;
letter-spacing: 1px;
word-spacing: 4px;
}
.btn:link,
.btn:visited{
display: inline-block;
padding: 10px 30px;
font-weight: 300;
text-decoration: none;
border-radius: 200px;
color: #fff;
transition: background-color 0.2s, border 0.2s, color 0.2s;
}
.btn-full:link,
.btn-full:visited{
background-color: #2ecc71;
border: 1px solid #2ecc71;
color: #fff;
margin-right: 15px;
}
.btn-ghost:link,
.btn-ghost:visited{
border: 1px solid #2ecc71;
color: #2ecc71;
}
.btn:hover,
.btn:active{
background-color: #1e874b;
}
.btn-full:hover,
.btn-full:active{
border: 1px solid #1e874b;
}
.btn-ghost:hover,
.btn-ghost:active{
border: 1px solid #1e874b;
color: #fff;
}
</style>
<body>
<header>
<div class="hero-text-box">
<div><h1 style="display:inline-block; text-align:left;">Life is the Song.<br> Love is the Music.</h1></div>
<a class= "btn btn-full" href="#">Listen </a>
<a class="btn btn-ghost" href="#">Show me more</a>
</div>
</header>
</body>
EXP:
.btn:link,
.btn:visited{
display: inline-block;
padding: 10px 30px;
font-weight: 300;
text-decoration: none;
border-radius: 200px;
color: #fff;
transition: background-color 0.2s, border 0.2s, color 0.2s;
margin-top: 150px;
}
margin-top: 150px; //You were trying to manually place the buttons with this line I suggest, you could've get away with it if you adjusted the positioning of the buttons, but this would be a bad practice.
Instead, I just Ordered the div to have its content aligned to the right, and put the H1 inside a div, then align the H1 to the left in order to have a perfectly left aligned text.
Upvotes: 1