I have a button on my website, and I used resolution independent alignment. I checked two different computer screens with different resolutions and it looks alright, however, once opened on a larger aspect ratio screen or a mobile/tablet device it re-positions. On a larger aspect ratio screen the buttons moves to the left, on the smaller devices, it floats towards the right. I'm not 100% certain what could of gone wrong. Below is my CSS and HTML code.
HTML:
<div class="Welcome">
<h1>Welcome to Beauty Factory Bookings</h1>
<button>Book Appointment</button>
</div>
CSS:
body {
background: url('http://i.imgur.com/4mKmYMb.jpg') no-repeat fixed center center;
background-size: cover;
font-family: Montserrat;
margin: 0;
padding: 0;
.Welcome {
margin-top: 13%;
}
.Welcome h1 {
text-align: center;
font-family: Montserrat;
font-size: 50px;
text-transform: uppercase;
}
.Welcome button {
height: 60px;
width: 340px;
background: #ff656c;
border: 1px solid #e15960;
color: #fff;
font-weight: bold;
text-transform: uppercase;
font-size: 17px;
font-family: Montserrat;
outline: none;
cursor: pointer;
text-align: center;
margin-left: 33%;
margin-top: 3%;
border-radius: 5px;
}
Any idea how to fix this?
You center a html element, which has the standard position and is a block element with margin-left: auto and margin-right: auto.
It is a convention to write the first letter of classes and ids in lowercase.
Example
Just another way to do it:
I wrap your button in div and center the button using text-align:center
Don't forget to take out margin-left: 33%; in your css
HTML
<div class="Welcome">
<h1>Welcome to Beauty Factory Bookings</h1>
<div class="center">
<button>Book Appointment</button>
</div>
</div>
CSS
.Welcome {
margin-top: 13%;
}
.Welcome h1 {
text-align: center;
font-family: Montserrat;
font-size: 50px;
text-transform: uppercase;
}
.center {
text-align: center;
}
.Welcome button {
height: 60px;
width: 340px;
background: #ff656c;
border: 1px solid #e15960;
color: #fff;
font-weight: bold;
text-transform: uppercase;
font-size: 17px;
font-family: Montserrat;
outline: none;
cursor: pointer;
text-align: center;
margin-top: 3%;
border-radius: 5px;
}
Example: http://codepen.io/anon/pen/EPyjXm
create a new CSS property for a tag and set display to flex(takes up 100% of width; and justify content to center.
EDIT
After checking out your site,
there is a margin-left of 15px coming from somewhere. Get rid of it if that is a possibility or else just add margin-left: 0 to the .Welcome a {...}
.Welcome a {
display: flex;
/*set display mode of anchor to flex*/
justify-content: center; /* Justify content center*/
margin-left: 0; /* Add !important in case it is overwritten*/
}
.Welcome {
margin-top: 13%;
}
.Welcome h1 {
text-align: center;
font-family: Montserrat;
font-size: 50px;
text-transform: uppercase;
}
.Welcome a {
display: flex;
/*set display mode of anchor to flex*/
justify-content: center; /* Justify content center*/
}
.Welcome button {
height: 60px;
width: 340px;
background: #ff656c;
border: 1px solid #e15960;
color: #fff;
font-weight: bold;
text-transform: uppercase;
font-size: 17px;
font-family: Montserrat;
outline: none;
cursor: pointer;
text-align: center;
border-radius: 5px;
}
<div class="Welcome">
<h1>Welcome to Beauty Factory Bookings</h1>
<a href="website_link">
<button>Book Appointment</button>
</a>
</div>
Related
I have a relative element within which there is an element with an image background that is absolute, when the parent of the relative element becomes a flex-box I lose the width, only when I bring the relative element static width (width: num px), I do not lose the width but the image does not responsive.
/* -------------------------------- */
/* header */
header {
margin-bottom: 24px;
display:flex;
}
.header-items h1 {
font-weight: 900;
font-size: 48px;
text-transform: uppercase;
line-height: 48px;
margin-bottom: 32px;
}
.header-items p {
margin-bottom: 35px;
font-weight: 500;
}
.pre--order {
display: flex;
align-items: baseline;
margin-bottom: 64px;
}
.pre--order a {
padding: 16px 26px;
background-color: #f16718;
text-transform: uppercase;
border-radius: 8px;
color: #ffffff;
margin-right: 32px;
}
.pre--order p {
font-weight: 700;
text-transform: uppercase;
}
.keyboard--header {
position: relative;
overflow: hidden;
max-width: 100%;
height: 425px;
}
.kh--image {
background-image: url("https://www.beauchamp.com/_wp/wp-content/uploads/2020/12/xIsrael_TelAviv_City_shai-pal1.jpg");
background-repeat: unset;
position: absolute;
width: 100%;
height: 100%;
background-size: 100% 100%;
border-radius: 15px;
top: 0;
left: 24px;
}
<header>
<div class="container">
<section class="header-items">
<h1>Typemaster Keyboard</h1>
<p>
Improve your productivity and gaming without breaking the bank.
Upgrade to a high quality mechanical typing experience.
</p>
<div class="pre--order">
Pre-order now
<p>Release on 5/27</p>
</div>
</div>
</section>
<section>
<div class="keyboard--header">
<div class="kh--image"></div>
</div>
</section>
Here is an example where I've wrapped the flexbox, given the flex child an explicit width&height, and fixed up a bunch of things like margin/padding you should generally base off typography not px
header {
margin-bottom: 1.5em;
display: flex;
flex-flow: row wrap;
}
.header-items h1 {
font-weight: 900;
font-size: 3rem;
text-transform: uppercase;
line-height: 3rem;
margin-bottom: 2rem;
}
.header-items p {
margin-bottom: 2rem;
font-weight: 500;
}
.pre--order {
display: flex;
align-items: baseline;
}
.pre--order a {
padding: 1em 1.5em;
background-color: #f16718;
text-transform: uppercase;
border-radius: 8px;
color: #fff;
margin-right: 2em;
}
.pre--order p {
font-weight: 700;
text-transform: uppercase;
}
.keyboard--header {
width: 100%;
height: 200px;
}
.kh--image {
background-image: url("https://www.beauchamp.com/_wp/wp-content/uploads/2020/12/xIsrael_TelAviv_City_shai-pal1.jpg");
background-clip: cover;
background-size: 100%;
width: 100%;
height: 100%;
border-radius: 15px;
}
<header>
<div class="container">
<section class="header-items">
<h1>Typemaster Keyboard</h1>
<p>
Improve your productivity and gaming without breaking the bank. Upgrade to a high quality mechanical typing experience.
</p>
<div class="pre--order">
Pre-order now
<p>Release on 5/27</p>
</div>
</section>
</div>
<div class="keyboard--header">
<div class="kh--image"></div>
</div>
</header>
I am trying to get 2 div tags to be inline with each other. When I did use display: inline-block it doesn't format correctly.
What I am trying to achieve see image
Code:
.packaging_details {
display: block;
border: solid 1px #000;
padding: 10px;
width: 95%;
margin-left: auto;
margin-right: auto;
margin-top: 30px;
margin-bottom: 30px;
}
.heading_texts {
text-transform: uppercase;
font-weight: bold;
font-size: 14px;
text-align: center;
display:inline-block;
}
.Subheading2 {
text-align: center;
font-size: 14px;
text-transform: uppercase;
}
.Subheading1 {
font-weight: bold;
text-transform: uppercase;
text-align: right;
display:inline-block;
}
<div class="packaging_details">
<div class="heading_texts">Company Name</div>
<div class="Subheading1">LABEL</div>
<div class="Subheading2">
<span class="logids">Name:</span> ###
</div>
</div>
It is always good to wrap parts that are supposed to look differently into seperat containers so you can position them differently. Your Problem here is most likely, that "heading_texts", "Subheading1" and "Subheading2" are on the same Layer / in the same position so they will behave similar in the parent Container.
I can offer you one solution: CSS Flex.
The code for that:
.packaging_details {
display: block;
border: solid 1px #000;
padding: 10px;
width: 95%;
margin-left: auto;
margin-right: auto;
margin-top: 30px;
margin-bottom: 30px;
}
.heading_texts {
text-transform: uppercase;
font-weight: bold;
font-size: 14px;
text-align: end;
width: 55%;
}
.Subheading2 {
text-align: center;
font-size: 14px;
text-transform: uppercase;
}
.Subheading1 {
font-weight: bold;
text-transform: uppercase;
text-align: end;
width: 45%;
}
.inline-container{
display: flex;
flex-direction: row;
text-align: center;
justify-content: center;
}
<div class="packaging_details">
<div class="inline-container">
<div class="heading_texts">Company Name</div>
<div class="Subheading1">LABEL</div>
</div>
<div class="Subheading2">
<span class="logids">Name:</span> ###
</div>
</div>
The Only thing you have to be aware of, is that you position the content of the Line by defining the widths of the 2 containers here, so if you want the logo to be more centered you need to play around with the with of both containers, they always need to sum up to 100% width!
You can use flex box as below.
The only challenge by doing it this way is to center align the Subheading2 below heading_text, one way is to set flex-basis 100% of the box width - the width of the Subheading1 element.
This solution is for the case when you don't have access or not able to change html structure but if you can change the html structure that can be easily styled with flex-box.
.packaging_details {
display: flex;
flex-wrap: wrap;
border: solid 1px #000;
padding: 10px;
width: 95%;
margin-left: auto;
margin-right: auto;
margin-top: 30px;
margin-bottom: 30px;
}
.heading_texts {
flex: 1;
text-transform: uppercase;
font-weight: bold;
font-size: 14px;
text-align: center;
}
.Subheading2 {
flex-basis: calc(100% - 55px);
text-align: center;
font-size: 14px;
text-transform: uppercase;
}
.Subheading1 {
font-weight: bold;
text-transform: uppercase;
text-align: right;
}
<div class="packaging_details">
<div class="heading_texts">Company Name</div>
<div class="Subheading1">LABEL</div>
<div class="Subheading2">
<span class="logids">Name:</span> ###
</div>
</div>
I am trying to put a button under a heading, but the button is being pushed to the side. I assume it has to do with absolute position or something, but I am not too sure. I also want to make the button responsive like the text, so that the size of the button changes in different windows.
HTML:
body{
font-family: sans-serif;
margin:0px;
}
.splash{
background-color: #faead3;
height: fill;
padding: 0;
margin:0;
display: flex;
justify-content: left; /* align horizontal */
align-items: center; /* align vertical */
height: 100vh;
}
.splash h1{
margin:0px;
font-size: 4.5vw;
color: #08aabe;
margin-left: 2.5em;
padding-bottom: 3.5em;
}
.button {
background-color: #08aabe;
border: none;
color: #faead3;
padding: 1em 2em;
text-align: center;
text-decoration: none;
font-size: 1w;
}
<div class="splash">
<h1>Random Text.</h1>
<a class="button"href="#">Button Link</a>
</div>
https://codepen.io/anon/pen/qQraNB
Any help is appreciated, thanks!
You use display:flex whats make them be in same line so:
1.Remove display:flex from .splash
2.font-size: 1w; in .button {} is invalid change it to font-size: 2.5vw;
you can use margin-left: 4.5em; to button
See code in fiddle:
body{
font-family: sans-serif;
margin:0px;
}
.splash{
background-color: #faead3;
height: fill;
padding: 0;
margin:0;
height: 100vh;
}
.splash h1{
margin:0px;
font-size: 4.5vw;
color: #08aabe;
margin-left: 2.5em;
padding-bottom: 3.5em;
}
.button {
background-color: #08aabe;
border: none;
color: #faead3;
padding: 1em 2em;
text-decoration: none;
font-size: 2.5vw;
margin-left: 4.5em;
}
<div class="splash">
<h1>Random Text.</h1>
<a class="button"href="#">Button Link</a>
</div>
There's a padding-bottom: 3.5em; set on the heading title, which is pushing the heading up, if you take that the padding bottom off, the button should align the same vertically on both of them.
I am trying to make a full width hero image with an h1 header, boxed text with 2 sizes of text inside plus a button. I have been wrestling with this all day and it just doesnt seem to work the way i'd like it to. Any help would be really appreciated.
thanks
Images:
How it looks at the moment with code
If you notice it is not going full width (gap on the left).
This is how i would like it to look or close enough
//css//
.hero-image {
background-image: url("image.jpg");
background-position: 100%;
background-repeat: no-repeat;
background-size: cover;
width: 100%;
padding: 50px;
}
.hero-text {
position: relative;
color: #154774;
}
.hero-text button {
border-radius: 5px;
padding: 10px 20px;
color: white;
background-color: #00adee;
text-align: center;
cursor: pointer;
font-size: 20px;
font-weight: bold;
bottom: 50px;
}
.hero-text button:hover {
background-color: #0597c4;
color: white;
}
.herotext2 {
border-radius: 5px;
padding: 10px 10px 10px 10px;
color: white;
background-color: red;
font-size: 20px;
width: 200px;
line-height: 1.4;
}
</style>
//html//
<div class="hero-image">
<div class="hero-text">
<h1 style="font-size:40px">IT support for<br>your business<br>as easy as<br>child’s play</h1>
<p class="herotext2">All inclusive IT GDPR service packages from £33 p/m</p>
<button>Try it for free today</button>
</div>
</div>
Updated image:
Updated image
.hero-image {
background-image: url("https://beerdeluxe.com.au/hawthorn/wp-content/uploads/sites/4/2017/05/hero-placeholder.png");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
padding: 50px;
}
.hero-text {
position: relative;
color: #154774;
text-align:right;
}
.hero-text h1 {
font-size:40px;
margin-right:15%;
}
.hero-text h1 .italic {
font-style: italic;
}
.hero-text button {
border-radius: 5px;
padding: 10px 20px;
color: white;
background-color: #00adee;
text-align: center;
cursor: pointer;
font-size: 20px;
font-weight: bold;
bottom: 50px;
max-width: 150px;
margin-top: 25px;
}
.hero-text button:hover {
background-color: #0597c4;
color: white;
}
.herotext2 {
position:relative;
border-radius: 5px;
padding: 10px 10px 10px 10px;
color: white;
background-color: red;
font-size: 20px;
width: 200px;
line-height: 1.4;
margin: 0 0 0 auto;
text-align:left;
}
.herotext2 .no {
font-size: 135px;
line-height: 130px;
font-weight: 600;
}
.herotext2 .tag {
position: absolute;
bottom: 26px;
right: 30px;
font-size: 12px;
color: red;
}
<div class="hero-image">
<div class="hero-text">
<h1>IT support for your<br> business - <span class="italic">as easy as<br>child’s play</span></h1>
<p class="herotext2">All inclusive IT GDPR service packages from <span class="no">£33</span><span class="tag">p/m</span></p>
<button>Try it for free today</button>
</div>
</div>
https://jsfiddle.net/Sampath_Madhuranga/pwxf73z8/16/
I have updated your html format and added new styles..Now it appears as your design but you need to apply relevant font family.
It works nice. Let me know if there is any issue.
Thanks.
You are missing absolute positioning the elements inside the hero image. This way, you can force them to stay at certain point inside it, by setting top, right, bottom and left of each one.
Don't forget to set parent hero div to position: relative.
I'm playing around with html and css and have a question about the text-align functions.
I'm trying to build my own website and want the text-align set to start, but centred in the middle of the page. I've got it so that the content is centred, but when only text-align is set to centre. Is there a way to obtain centred text content but with text-align set to start? I don't particularly want to use padding (if it can be helped), as i've used it within this context and have had some responsive problems (which have had to be rectified with many media screen commands).
Sorry for the pretty noobie question.
HTML
.Container1 {
height: 100%;
width: 100%;
background: #e8eaed;
background-size: cover;
display: table;
margin: auto;
display: table;
top: 0;
}
.About {
font-family: 'Lato';
font-weight: 300;
margin: 0 auto;
display: table-cell;
vertical-align: middle;
max-width: none;
}
.Content2 {
margin: 0 auto;
text-align: center;
}
.About h2 {
font-size: 40px;
letter-spacing: 4px;
line-height: 10px;
font-style: italic;
color: #70a1af;
text-shadow: 2px 2px white;
text-align: center;
}
.About p {
font-size: 18px;
letter-spacing: 4px;
line-height: 20px;
color: #70a1af;
}
<section class="Container1">
<div class="About">
<div class="Content2">
<h2> ABOUT ME.</h2>
<p> Computer Science // British Born // Wannabe Australian </p>
</div>
</div>
</section>
This is how i want the text to be aligned, but to be centred in the middle of the page...
Try to use Flexbox. Use align-item:center to center flex item vertically.
Stack Snippet
.Container1 {
height: 400px;
background: #e8eaed;
display: flex;
align-items: center;
}
.About {
font-family: 'Lato';
font-weight: 300;
}
.About h2 {
font-size: 40px;
letter-spacing: 4px;
line-height: 10px;
font-style: italic;
color: #70a1af;
text-shadow: 2px 2px white;
}
.About p {
font-size: 18px;
letter-spacing: 4px;
line-height: 20px;
color: #70a1af;
}
<section class="Container1">
<div class="About">
<div class="Content2">
<h2> ABOUT ME.</h2>
<p> Computer Science // British Born // Wannabe Australian </p>
</div>
</div>
</section>
fixed the width and then set margin: 0 auto