How to align text center in a responsive css button? - html

I have an image that has two buttons inside it. I want these buttons to be responsive and the text to be centered all the time and resize if the image gets resized. The text inside these buttons is not centered and gets even worse when resizing the browser or when browsing on a mobile device. What am I missing? Below is the CSS code for the image and the buttons:
.container {
position: relative;
width: 100%;
max-width: 2400px;
}
.container img {
width: 150%;
opacity: 0.85;
height: auto;
}
.container .btn {
width: 30%;
height: 10%;
opacity: 0.8;
filter: alpha(opacity=80);
position: absolute;
top: 80%;
left: 70%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #555;
color: white;
font-size: 1.5vw;
padding: 12px 24px;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
text-decoration: none;
vertical-align: middle;
line-height: 100%;
}
.container .btns {
width: 30%;
height: 10%;
opacity: 0.8;
filter: alpha(opacity=80);
position: absolute;
top: 80%;
left: 30%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #555;
color: white;
font-size: 2vw;
padding: 12px 24px;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
text-decoration: none;
vertical-align: middle;
line-height: 100%;
}
<div class="container">
<img img="" src="" alt="">
Registracija Kaune
Registracija Vilniuje
</div>
Below are the images of how it looks:
This is how it looks on desktop:
This is how it looks on mobile/resized browser:

I got rid of your width and height on the buttons and changed your padding to a % so it is responsive and the text will always appear centered when resized.
.container {
position: relative;
width: 100%;
max-width: 2400px;
}
.container img {
width: 150%;
opacity: 0.85;
height: auto;
}
.container .btn {
opacity: 0.8;
filter: alpha(opacity=80);
position: absolute;
top: 80%;
left: 70%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #555;
color: white;
font-size: 1.5vw;
padding: 1% 5%;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
text-decoration: none;
vertical-align: middle;
line-height: 100%;
}
.container .btns {
opacity: 0.8;
filter: alpha(opacity=80);
position: absolute;
top: 80%;
left: 30%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #555;
color: white;
font-size: 2vw;
padding: 1% 5%;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
text-decoration: none;
vertical-align: middle;
line-height: 100%;
}
<div class="container">
<img img="" src="" alt="">
Registracija Kaune
Registracija Vilniuje
</div>

I modified your code. Try this
.container {
position: relative;
width: 100%;
height:100vh;
}
.btn-container{
display:flex;
justify-content: center;
align-items: center;
height:100%;
width:100%;
}
.container img {
width: 150%;
opacity: 0.85;
height: auto;
}
.container .btn {
opacity: 0.8;
filter: alpha(opacity=80);
background-color: #555;
color: white;
font-size: 1.5em;
padding: 12px 24px;
cursor: pointer;
border-radius: 5px;
text-align: center;
text-decoration: none;
line-height: 100%;
margin: 0 30px;
}
I added a div with a classname of btn-container that holds your buttons and positioned in the center
<div class="container">
<img img="" src="" alt="">
<div class="btn-container">
Registracija Kaune
Registracija Vilniuje
</div>
</div>

Try remove height: 10%; from .container .btn Because you added padding for that
.container {
position: relative;
width: 100%;
max-width: 2400px;
}
.container img {
width: 150%;
opacity: 0.85;
height: auto;
}
.container .btn {
width: 30%;
/* height: 10%; */ /* Remove this height */
opacity: 0.8;
filter: alpha(opacity=80);
position: absolute;
top: 80%;
left: 70%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #555;
color: white;
font-size: 2vw;
padding: 12px 24px;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
text-decoration: none;
vertical-align: middle;
line-height: 100%;
}
.container .btns {
width: 30%;
/* height: 10%; */ /* Remove this height */
opacity: 0.8;
filter: alpha(opacity=80);
position: absolute;
top: 80%;
left: 30%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
background-color: #555;
color: white;
font-size: 2vw;
padding: 12px 24px;
border: none;
cursor: pointer;
border-radius: 5px;
text-align: center;
text-decoration: none;
vertical-align: middle;
line-height: 100%;
}
<div class="container">
<img img="" src="" alt="">
Registracija Kaune
Registracija Vilniuje
</div>

many solution to this
make the image as background-image for the container, then use flexbox
or
make the image position absolute, add margin to the buttons, and use flaxbox like this esample below
.container {
display: flex;
justify-content: space-evenly;
width: 100%;
max-width: 2400px;
position: relative;
overflow: hidden;
}
.container img {
position: absolute;
width: 100%;
opacity: 0.85;
height: auto;
}
.container .btn, .container .btns{
display: flex;
align-items: center;
justify-content: center;
width: 30%;
height: 10%;
min-height: calc(2vw + 24px);
opacity: .8;
background-color: #555;
color: white;
border: none;
cursor: pointer;
border-radius: 5px;
text-decoration: none;
margin: 40% 0;
}
.container .btn {
left: 70%;
font-size: 1.5vw;
}
.container .btns {
left: 30%;
font-size: 2vw;
}
<div class="container">
<img src="https://data.whicdn.com/images/50959200/original.jpg" alt="">
Registracija Vilniuje
Registracija Kaune
</div>

Just Add bootstrap class into button your tag
class="text-center";

Related

Card title disappear despite z-index?

I'm trying to make a card with a title and description but when I set a background image on that image, my card title disappeared but not my description. It happens even if I do the same code for both of them.
I know I don't have to write here animation codes too but I really don't have any idea why this is happening.
Image:
z-index doesn't work I guess.
.index {
width: 400px;
height: 400px;
background-color: white;
float: left;
margin-right: 30px;
border-radius: 10px;
overflow: hidden;
position: relative;
color: white;
cursor: pointer;
}
.index_img {
width: 100%;
height: 100%;
z-index: -1;
}
.index_html {
background-image: url(web_image_html.jpeg);
background-position: center;
background-size: cover;
z-index: -1;
}
.index a {
color: #fff;
text-decoration: none;
}
.index_title {
text-align: center;
font-family: 'Roboto', sans-serif;
font-size: 30px;
}
.index_description {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
font-family: 'Inter', sans-serif;
width: 100%;
font-size: 18px;
}
.index_title,
.index_description {
background-color: rgba(82, 81, 81, 0.56);
height: 80px;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
z-index: 1;
}
.index_html:hover {
animation: index-animate 3s ease-in-out;
}
#keyframes index-animate {
0% {
transform: scale(1);
}
100% {
transform: scale(1.3);
}
}
<div class="index">
<a href="">
<div class="index_img index_html"></div>
<h2 class="index_title">HTML</h2>
<p class="index_description">Lorem ipsum dolor sit amet.</p>
</a>
</div>
Remove overflow hidden from the below code
.index {
width: 400px;
height: 400px;
background-color: white;
float: left;
margin-right: 30px;
border-radius: 10px;
position: relative;
color: white;
cursor: pointer;
}
You're on the right track! But you're fumbling a little with the usage of display: flex; and position: absolute;. display: flex; should be used on the parent to see the result on the child(ren), you're using it directly on the children (.index_title and .index_description).
For trying to position 2 elements together with position: absolute; I'd recommend wrapping them together, so you only have to position 1 element!
.index {
width: 400px;
height: 400px;
background-color: white;
float: left;
margin-right: 30px;
border-radius: 10px;
overflow: hidden;
position: relative;
color: white;
cursor: pointer;
}
.index_img {
width: 100%;
height: 100%;
z-index: -1;
}
.index_html {
background: url(web_image_html.jpeg) red;
background-position: center;
background-size: cover;
z-index: -1;
}
.index a {
color: #fff;
text-decoration: none;
}
.index_content {
width: 100%;
height: 80px;
position: absolute;
bottom: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: rgba(82, 81, 81, 0.56);
}
.index_title {
font-family: 'Roboto', sans-serif;
font-size: 30px;
color: #000;
}
.index_description {
font-family: 'Inter', sans-serif;
font-size: 18px;
}
.index_title,
.index_description {
width: 100%;
margin: 0;
text-align: center;
}
.index_html:hover {
animation: index-animate 3s ease-in-out;
}
#keyframes index-animate {
0% {
transform: scale(1);
}
100% {
transform: scale(1.3);
}
}
<div class="index">
<a href="">
<div class="index_img index_html"></div>
<div class="index_content">
<h2 class="index_title">HTML</h2>
<p class="index_description">Lorem ipsum dolor sit amet.</p>
</div>
</a>
</div>

How to I move text to the bottom of in an image overlay for card in CSS/HTML?

I've been trying to change justify-content in the CSS class to "flex-end" and "end" but the text is not moving down to the bottom.
I think we should focus on the img-overlay class, because that's where we position the text on the card.
.overlay.overlay-sm .shape {
filter: brightness(0) invert(1);
opacity: 0.15;
height: 40px;
}
.overlay.overlay-sm .shape.wave {
height: initial;
width: 70px;
}
.overlay.overlay-sm .shape.xshape {
height: 30px;
}
.portfolio .square {
top: 28%;
left: 20%;
}
.portfolio .circle {
top: 8%;
right: 35%;
}
.portfolio .triangle {
top: 10%;
right: 4%;
}
.portfolio .half-circle1 {
bottom: 13%;
left: 5%;
}
.portfolio .half-circle2 {
bottom: 35%;
left: 20%;
}
.portfolio .xshape {
bottom: 10%;
left: 8%;
}
.portfolio .wave {
bottom: 38%;
left: 6%;
}
.grid {
width: 100%;
margin: 1.5rem 0;
}
.grid-item {
width: 33.33%;
padding: 1rem 1.2rem;
display: flex;
justify-content: center;
}
.gallery-image {
position: relative;
overflow: hidden;
border-radius: 16px;
height: 330px;
width: 100%;
cursor: pointer;
/* justify-content: flex-end; */
}
.gallery-image img {
position: absolute;
height: 115%;
width: initial;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transform-origin: center;
/* justify-content: flex-end; */
/* cursor: pointer; */
}
.gallery-image .img-overlay {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
margin: auto;
z-index: 2;
color: var(--light-one);
background-color: rgba(120, 76, 251, 0.55);
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
padding: 2rem 3.2rem;
/* opacity: 0; */ /* I removed this one :: Rickard */
}
.img-overlay .plus {
position: relative;
/* width: 100px; */
/* height: 100px; */
margin: auto 0;
}
.plus:before,
.plus:after {
content: "";
position: absolute;
width: 4.5rem;
height: 3px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: var(--light-one);
border-radius: 3px;
}
.plus:before {
transform: translate(-50%, -50%) rotate(-90deg);
}
.img-description {
width: 100%;
}
.img-overlay h3 {
font-weight: 600;
text-transform: uppercase;
font-size: 1.5rem;
}
.img-overlay h5 {
font-size: 1.15rem;
font-weight: 300;
}
.gallery-image:hover .img-overlay {
opacity: 1;
transition: 0.3s ease;
}
.gallery-image:hover img {
transform: translate(-50%, -50%) scale(1.1);
}
.more-folio {
display: flex;
justify-content: center;
}
<div class="grid-item logo-design">
<div class="gallery-image">
<img src="./img/portfolio/port1.jpg" alt="">
<div class="img-overlay">
<div class="plus">
<div class="img-description">
<h3>Logo Design</h3>
<h5>View Demo</h5>
</div>
</div>
</div>
</div>
</div>
Remove styles of .img-overlay .plus:
.overlay.overlay-sm .shape {
filter: brightness(0) invert(1);
opacity: 0.15;
height: 40px;
}
.overlay.overlay-sm .shape.wave {
height: initial;
width: 70px;
}
.overlay.overlay-sm .shape.xshape {
height: 30px;
}
.portfolio .square {
top: 28%;
left: 20%;
}
.portfolio .circle {
top: 8%;
right: 35%;
}
.portfolio .triangle {
top: 10%;
right: 4%;
}
.portfolio .half-circle1 {
bottom: 13%;
left: 5%;
}
.portfolio .half-circle2 {
bottom: 35%;
left: 20%;
}
.portfolio .xshape {
bottom: 10%;
left: 8%;
}
.portfolio .wave {
bottom: 38%;
left: 6%;
}
.grid {
width: 100%;
margin: 1.5rem 0;
}
.grid-item {
width: 33.33%;
padding: 1rem 1.2rem;
display: flex;
justify-content: center;
}
.gallery-image {
position: relative;
overflow: hidden;
border-radius: 16px;
height: 330px;
width: 100%;
cursor: pointer;
/* justify-content: flex-end; */
}
.gallery-image img {
position: absolute;
height: 115%;
width: initial;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transform-origin: center;
/* justify-content: flex-end; */
/* cursor: pointer; */
}
.gallery-image .img-overlay {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
margin: auto;
z-index: 2;
color: var(--light-one);
background-color: rgba(120, 76, 251, 0.55);
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
padding: 2rem 3.2rem;
/* opacity: 0; */ /* I removed this one :: Rickard */
}
.plus:before,
.plus:after {
content: "";
position: absolute;
width: 4.5rem;
height: 3px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: var(--light-one);
border-radius: 3px;
}
.plus:before {
transform: translate(-50%, -50%) rotate(-90deg);
}
.img-description {
width: 100%;
}
.img-overlay h3 {
font-weight: 600;
text-transform: uppercase;
font-size: 1.5rem;
}
.img-overlay h5 {
font-size: 1.15rem;
font-weight: 300;
}
.gallery-image:hover .img-overlay {
opacity: 1;
transition: 0.3s ease;
}
.gallery-image:hover img {
transform: translate(-50%, -50%) scale(1.1);
}
.more-folio {
display: flex;
justify-content: center;
}
<div class="grid-item logo-design">
<div class="gallery-image">
<img src="https://source.unsplash.com/random/300x200" alt="">
<div class="img-overlay">
<div class="plus">
<div class="img-description">
<h3>Logo Design</h3>
<h5>View Demo</h5>
</div>
</div>
</div>
</div>
</div>
This would be my approach to overlay your text on an image:
.gallery-image {
border-radius: 16px;
min-height: 330px;
cursor: pointer;
background: center / cover no-repeat url("https://source.unsplash.com/random/300x200");
}
.gallery-image .img-overlay {
display: grid;
place-content: end center;
min-height: inherit;
border-radius: inherit;
color: var(--light-one, #fff);
background-color: rgb(120 76 251 / 0.55);
}
.img-overlay h3 {
font-weight: 600;
text-transform: uppercase;
font-size: 1.5rem;
}
.img-overlay h5 {
font-size: 1.15rem;
font-weight: 300;
}
<div class="gallery-image">
<div class="img-overlay">
<h3>Logo Design</h3>
<h5>View Demo</h5>
</div>
</div>

HTML/CSS: Allow For Background Image Hover and Absolute Positioned Text

I'm trying to accomplish the following:
Have a grayscaled image
Have text and a button positioned over the grayscaled image
Allow for a hover-effect on the grayscaled image so that it's colored on hover
The issue I'm running into is that when I'm hovering over the text/button of the absolute-positioned div on top of the image, the hover effect no longer works.
Here's an example:
Here's my HTML & CSS:
<div id="homepage-solutions">
<div class="image-box">
<img src="https://azbigmedia.com/wp-content/uploads/2019/11/metalworking.jpg">
<div class="text-box">
<h3>Metalworking</h3>
Learn More
</div>
</div>
</div>
#homepage-solutions .image-box {
display: inline-block;
position: relative;
overflow: hidden;
min-width: 250px;
min-height: 250px;
max-width: 100%;
max-height: 100%;
text-align: center;
list-style: none;
vertical-align: middle;
}
#homepage-solutions .image-box img {
display: block;
height: 200px;
width: 100%;
filter: gray;
-webkit-filter: grayscale(1);
filter: grayscale(1);
}
#homepage-solutions .image-box img:hover {
-webkit-filter: grayscale(0);
filter: none;
}
#homepage-solutions .text-box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 2em;
text-align: center;
max-width: 500px;
}
#homepage-solutions h3 {
color: #fff;
font-size: 22px;
font-weight: 700;
margin-top: 0;
margin-bottom: 10px;
text-align: center;
}
#homepage-solutions .text-box p {
color: #fff;
font-size: 12px;
font-weight: 400;
margin: 10px 0;
}
#homepage-solutions .text-box a.btn {
display: inline-block;
width: auto;
color: #fff;
background: #fd5f11;
font-size: 13px;
font-weight: 700;
text-decoration: none;
text-transform: uppercase;
padding: 6px 20px;
margin: 5px 0 0;
border-radius: 0;
}
#homepage-solutions .text-box a.btn:hover {
opacity: 0.75;
}
Fiddle Links:
https://jsfiddle.net/mwilk/96p7nkw1/5/ https://jsfiddle.net/mwilk/96p7nkw1/6/#&togetherjs=H2kAkloCwG
Thanks!
Hi,
Just Edit Selector:
#homepage-solutions .image-box img:hover
To
#homepage-solutions .image-box:hover img
See It working
#homepage-solutions .image-box {
display: inline-block;
position: relative;
overflow: hidden;
min-width: 250px;
min-height: 250px;
max-width: 100%;
max-height: 100%;
text-align: center;
list-style: none;
vertical-align: middle;
}
#homepage-solutions .image-box img {
display: block;
height: 200px;
width: 100%;
filter: gray;
-webkit-filter: grayscale(1);
filter: grayscale(1);
}
#homepage-solutions .image-box:hover img {
-webkit-filter: grayscale(0);
filter: none;
}
#homepage-solutions .text-box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
padding: 2em;
text-align: center;
max-width: 500px;
}
#homepage-solutions h3 {
color: #fff;
font-size: 22px;
font-weight: 700;
margin-top: 0;
margin-bottom: 10px;
text-align: center;
}
#homepage-solutions .text-box p {
color: #fff;
font-size: 12px;
font-weight: 400;
margin: 10px 0;
}
#homepage-solutions .text-box a.btn {
display: inline-block;
width: auto;
color: #fff;
background: #fd5f11;
font-size: 13px;
font-weight: 700;
text-decoration: none;
text-transform: uppercase;
padding: 6px 20px;
margin: 5px 0 0;
border-radius: 0;
}
#homepage-solutions .text-box a.btn:hover {
opacity: 0.75;
}
<div id="homepage-solutions">
<div class="image-box">
<img
src="https://azbigmedia.com/wp-content/uploads/2019/11/metalworking.jpg"
/>
<div class="text-box">
<h3>Metalworking</h3>
Learn More
</div>
</div>
</div>

How to align two divs horizontally (and the text above it) despite doing float and display

I wanted to align these 2 <a> tags horizontally with a margin between them but then they overlapped on each other. I think it's because of position: absolute but if i were to use position: relative it would be a mess and i want the text above it to move too if i were to zoom in on the page. How do I do that?
.loginsebagai h2 {
font-size: 30px;
text-align: center;
position: absolute;
color: #333333;
top: 28%;
left: 50%;
transform: translate(-50%, -50%);
}
.loginsebagaimurid {
width: 220px;
height: 250px;
border-radius: 5px;
background-color: white;
position: absolute;
top: 55%;
left: 50%;
transform: translate(-50%, -50%);
float: left;
clear: none;
}
.loginsebagaimurid-top {
width: 100%;
height: 175px;
border-radius: 5px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 0px;
background-color: #ffa603;
text-align: center;
line-height: 175px;
vertical-align: middle;
}
.loginsebagaimurid-top i {
width: 100px;
height: 100px;
font-size: 40px;
color: white;
/* aligning */
text-align: center;
line-height: 100px;
vertical-align: middle;
display: inline-block;
/* aligning */
border-radius: 50%;
background-color: #c97a01;
transition-duration: 0.2s;
}
.loginsebagaimurid:hover i {
width: 125px;
height: 125px;
text-align: center;
line-height: 125px;
vertical-align: middle;
display: inline-block;
border-radius: 50%;
}
.loginsebagaimurid-bottom {
width: 100%;
height: 75px;
}
.loginsebagaimurid-bottom h3 {
font-size: 20px;
text-align: center;
line-height: 75px;
vertical-align: middle;
color: black;
transition-duration: 0.2s;
}
.loginsebagaimurid:hover h3 {
background-color: #eb6810;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
color: white;
}
/* loginsebagai.php admin */
.loginsebagaiadmin {
width: 220px;
height: 250px;
border-radius: 5px;
background-color: white;
position: absolute;
top: 55%;
left: 50%;
transform: translate(-50%, -50%);
float: left;
clear: none;
}
.loginsebagaiadmin-top {
width: 100%;
height: 175px;
border-radius: 5px;
border-bottom-right-radius: 0px;
border-bottom-left-radius: 0px;
background-color: #ffa603;
text-align: center;
line-height: 175px;
vertical-align: middle;
}
.loginsebagaiadmin-top i {
width: 100px;
height: 100px;
font-size: 40px;
color: white;
/* aligning */
text-align: center;
line-height: 100px;
vertical-align: middle;
display: inline-block;
/* aligning */
border-radius: 50%;
background-color: #c97a01;
transition-duration: 0.2s;
}
.loginsebagaiadmin:hover i {
width: 125px;
height: 125px;
text-align: center;
line-height: 125px;
vertical-align: middle;
display: inline-block;
border-radius: 50%;
}
.loginsebagaiadmin-bottom {
width: 100%;
height: 75px;
}
.loginsebagaiadmin-bottom h3 {
font-size: 20px;
text-align: center;
line-height: 75px;
vertical-align: middle;
color: black;
transition-duration: 0.2s;
}
.loginsebagaiadmin:hover h3 {
background-color: #eb6810;
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
color: white;
}
<div class="loginsebagai">
<h2>Log Masuk sebagai...</h2>
<a href="index.php" class="loginsebagaimurid">
<div class="loginsebagaimurid-top"><i class="fas fa-user-graduate"></i>
</div>
<div class="loginsebagaimurid-bottom">
<h3>Murid</h3>
</div>
</a>
<a href="indexadmin.php" class="loginsebagaiadmin">
<div class="loginsebagaiadmin-top"><i class="fas fa-user-graduate"></i>
</div>
<div class="loginsebagaiadmin-bottom">
<h3>Murid</h3>
</div>
</a>
</div>
add this at last of your css and check if you wanted the same
.loginsebagai a {
display: flex;
width:100%;
justify-content: space-between;
}

Center button and image on browser movement

So i'm trying to center my button and my image so when the page gets smaller it should still be aligned in the middle. Also my button is not centering.
i'm trying to make it look like : https://www.unrealengine.com
Try moving the page around and see what happens.
.header {
width: 100%;
height: auto;
}
.header img {
width: 100%;
height: auto;
z-index: -1;
}
.header h1 {
margin: 0;
height: auto;
width: auto;
position: absolute;
top: 20%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
color: white;
}
.myButton {
display: inline-block;
text-align: center;
position: relative;
height: auto;
background-color: #10b4f5;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
display: inline-block;
cursor: pointer;
color: #ffffff;
font-family: Arial;
font-size: 17px;
padding: 16px 31px;
text-decoration: none;
}
.myButton:hover {
background-color: #008fc7;
}
.myButton:active {
position: relative;
top: 1px;
}
<div class="header">
<img src="images/background2.jpg" alt="background">
</div>
EXPLORE
The easiest way to center something vertical and horizontal is using display flex. With align-items and justify-content this can be done quite easily. For more information see: A Complete Guide to Flexbox
header {
display: flex;
flex-direction: column;
text-align: center;
align-items: center;
justify-content: center;
height: 100vh;
width: 100vw;
}
<header>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<button>CTA Here</button>
</header>
EDIT:
This code snippet is based on OP's own code. There is no need to use a div with a header class when you can use the HTML5 header tag.
header {
background-image: url(images/background2.jpg);
display: flex;
flex-direction: column;
text-align: center;
align-items: center;
justify-content: center;
height: 100vh;
width: 100vw;
}
.myButton {
background-color: #10b4f5;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
cursor: pointer;
color: #ffffff;
font-family: Arial;
font-size: 17px;
padding: 16px 31px;
text-decoration: none;
}
.myButton:hover {
background-color: #008fc7;
}
<header>
<h1>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</h1>
EXPLORE
</header>
Try this code.
HTML
<div class="header-wrap">
<div class="header">
<img src="images/background2.jpg" alt="background">
</div>
EXPLORE
</div>
CSS
.header-wrap {
text-align: center;
}
.header {
width: 100%;
height: auto;
}
.header img {
width: 100%;
height: auto;
z-index: -1;
}
.header h1 {
margin: 0;
height: auto;
width: auto;
position: absolute;
top: 20%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
color: white;
}
.myButton {
display: inline-block;
text-align: center;
position: relative;
height: auto;
background-color: #10b4f5;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
display: inline-block;
cursor: pointer;
color: #ffffff;
font-family: Arial;
font-size: 17px;
padding: 16px 31px;
text-decoration: none;
}
.myButton:hover {
background-color: #008fc7;
}
.myButton:active {
position: relative;
top: 1px;
}
The alignment of text is specified in the element the text is contained in, so in this case you should specify text-align: center;in the element which contains the button. Like so:
<div class="button-container">
EXPLORE
</div>
and in the CSS
.button-container {
text-align:center;
}