I am making a simple header with text and a button but when I go on mobile everything isn't responsive . I tried using %'s but nothing was working. And my CSS jumps up and down when I scroll on mobile. This is the codepen, https://codepen.io/Religion/pen/ZEQerQZ. Below is the CSS . HTML you can check on the codepen due to the post saying it's mostly code.
CSS:
#media only screen and (max-width: 767px) {
.header1{
padding: 15%;
text-align: center;
background-image: url('https://manchesterdental.org/img/dentalimg/welcomenote.jpg');
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
color: white;
font-size: 30px;
position: relative;
}
.header-text1 h2{
margin-top:20%;
font-size:1.8rem;
width:45vh;
margin-left:-20%;
color:white;
}
.header-text1 p{
font-size:1.1rem;
width:44vh;
margin-left:-20%;
padding-top:40px;
color:white;
font-weight: 500;
}
.header-text{
position: absolute;
bottom:0;
left:0;
width:1px;
}
.button {
background-color: #00aeef; /* Green */
color: black;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
margin-left: 2%;
width:95%;
margin-bottom: 20px;
}
}
#media (min-width:900px) {
.header1{
padding: 60px;
text-align: center;
background-image: url("{% static 'dentist/img/bg-img/header.jpg' %}");
background-position: center center;
background-size: cover;
background-repeat: no-repeat;
color: white;
font-size: 30px;
height:80vh;
}
.header-text1 h2{
margin-top:10%;
color:white;
font-size: 3rem;
}
.header-text1 p{
padding-top:40px;
font-size:1.5rem;
max-width:80%;
margin-left:10%;
color:white;
font-weight: 500;
}
.button {
background-color: #00aeef; /* Green */
color: black;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.4s; /* Safari */
transition-duration: 0.4s;
margin-left: 2%;
width:45%;
font-family: "Comic Sans MS", cursive, sans-serif;
font-weight:800;
}
}
HTML:
<div class="header1">
<div class = "header-text1">
<h2>We Believe Everyone Should Have Easy Access To Great Dental Care</h2>
<p >As a leading industry innovater, * Dental Business* is opening up exciting new opportunities for dental professionals, investors, employees & suppliers. Contact us to find out what we have to offer you.</p>
<br>
<button class="button button1">Contact Us!</button>
</div>
</div>
To keep the text elements centered in the div, you can make use of flexbox. Simply add the following code to the top of your CSS file before the media queries:
.header-text1 {
display: flex;
flex-direction: column;
justify-content: center;
width: 100%;
}
Also, no need to include this with your media queries since flexbox will handle everything regardless of viewport size.
This Codepen had the updated code - also changed the second media query so that the CSS doesn't break between 767px and 900px like it did before.
You are currently setting the margin-top property to 20% of the height of the button itself.
If you want the margin to respond to the width of the viewport, then use something like:
margin-top: 2vw; // 2% of the viewport width
However, for the margin-top property, I suggest using the height of the viewport like so:
margin-top: 1vh; // 1% of the viewport height (1% should be enough)
Related
I tried to use media query for the first time to make a simple section responsive where the font-size gets smaller when the screen is small
but for some reason it didn't work for me please if you see something that i dont infrom me
here is the HTML code that i use for the project
HTML:
<!DOCTYPE html>
<html>
<head>
<title>
EYD
</title>
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" >
</head>
<body>
<main>
<div class="mainco">
<h1>
welcome to <br><span>EYD</span>
</h1>
<h2>best web-developing service on the internet</h2>
<div class="buttons">
<p>ORDER</p>
<p>HOW IT WORKS</p>
</div>
</div>
</main>
<!-- ******************************************************** -->
<section>
</section>
</body>
</html>
here is the CSS code that contains the media query targeting a h1 element in the page
CSS:
/*this is a universal selector to clear the padding and margin*/
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
body{
font-family:Verdana, Geneva, Tahoma, sans-serif;
}
/*-------------------------------------
main
--------------------------------------*/
/*here is the style of the main as a section*/
main{
background: url(code1.jpg) purple;
background-repeat: no-repeat;
background-size:cover ;
width: 100%;
height: 630px;
color: white;
font-family: "alternate gothic";
padding: 20px 0 0 0;
}
/*the style of the main section's text block*/
.mainco{
width: 40%;
max-height: 70%;
text-align: center;
margin: 10% 30px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#media only screen and (max-width: 800px){
.mainco h1{
font-size:20px;
}
}
/*the style of the h1 of the text*/
.mainco h1 {
font-size: 60px;
}
.mainco h1 span{
text-shadow: 3px 3px rgb(167, 119, 119); font-size: 75px;
}
/*the style of h2 of the text*/
main h2{
font-size: 50px;
}
.buttons{
min-width: 400px;
}
/*the style of the two button's text containers*/
.buttons p{
padding: 20px;
background-color: brown;
display: inline-block;
margin: 60px 20px;
}
/*styling the button's text*/
.buttons a{
text-decoration: none;
color: white;
display: block;
width: 100%;
height: 100%;
}
Always put your media queries at the end of your CSS code. That will stop the the other h1 declarations from overriding your media query.
the main problem with your CSS code is the order
Your declaration .mainco h1 overwrite previously declared media query so if you change your CSS to this, it will work.
your media query should be bellow your global CSS
/*here is the style of the main as a section*/
main{
background: url(code1.jpg) purple;
background-repeat: no-repeat;
background-size:cover ;
width: 100%;
height: 630px;
color: white;
font-family: "alternate gothic";
padding: 20px 0 0 0;
}
/*the style of the main section's text block*/
.mainco{
width: 40%;
max-height: 70%;
text-align: center;
margin: 10% 30px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
#media only screen and (max-width: 800px){
.mainco h1{
font-size:20px;
}
}
/*the style of the h1 of the text*/
.mainco h1 {
font-size: 60px;
}
.mainco h1 span{
text-shadow: 3px 3px rgb(167, 119, 119); font-size: 75px;
}
/*the style of h2 of the text*/
main h2{
font-size: 50px;
}
.buttons{
min-width: 400px;
}
/*the style of the two button's text containers*/
.buttons p{
padding: 20px;
background-color: brown;
display: inline-block;
margin: 60px 20px;
}
/*styling the button's text*/
.buttons a{
text-decoration: none;
color: white;
display: block;
width: 100%;
height: 100%;
}
I was trying to have fun by making a joke with some friends and i ended up getting stuck when a button i my website wasn't aligned in the center of the page.
Where is my HTML code:
<body>
<?php include 'navbar.php'; ?>
<br><br>
<div class="content">
<h1> Roderick15's Stuff</h1>
<br><br>
<br><br>
<button onclick="window.location.href='deathnote.php'"
class="btn">Death Note</button>
</body>
And where's my css code:
body {
margin: 0 auto;
font-size: 28px;
font-family: Arial, Helvetica, sans-serif;
}
.btn {
color: white;
text-align: center;
font-size: 15px;
opacity: 1;
transition-duration: 0.3s;
background-color: black;
cursor: pointer;
display: block;
float: left;
margin-right: 5px;
line-height: 50px;
}
.btn:hover {
opacity: 0.5;
color : white;
}
h1{
text-align: center;
}
I hope someone can help me getting rid of this problem.
you should remove the float left
and change the margin to "0 auto" if you want to center the button
.btn {
color: white;
text-align: center;
font-size: 15px;
opacity: 1;
transition-duration: 0.3s;
background-color: black;
cursor: pointer;
display: block;
margin: 0 auto;
line-height: 50px;
}
To be able to center an element horizontally you can use "margin: auto"
This requires the object to have a certain width, (for example "width: 150px;")
In your example, you use "float left", which causes the element to stick to the left of the screen in this case.
Removing "float: left;" and "margin-right: 5px;"
and adding
"width: 150px;"
"margin: auto;"
Should do the trick.
So that the .btn class looks like this;
.btn {
color: white;
text-align: center;
font-size: 15px;
opacity: 1;
transition-duration: 0.3s;
background-color: black;
cursor: pointer;
display: block;
line-height: 50px;
width: 150px;
margin: auto;
}
I recommend W3 schools if you need any more info.
https://www.w3schools.com/css/default.asp
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 recently published a website http://marishomeimprovements.com/
There is a picture in the background on the top of the page and for whatever reason, it won't load through Safari on iPhones.
html:
<section class="home" id="home">
<div class="overlay">
<div class="title">
<p>The Best Remodeling Company</p>
<h1>We Are Maris Home Improvements</h1>
<p>Specializing in Decks, Windows, Siding and More.</p>
<div class="giftCardAd">
<h1 class="heading"><span id="callNow">Call Now!</span></h1>
<h3>$25 gift card with free estimate.</h3>
<h2>636-778-4343</h2>
<h4>We are here for you.</h4>
</div>
</div>
</div>
</section>
css:
.home{
height: 600px;
background-image: url('../images/background.png');
background-attachment: fixed;
background-repeat: no-repeat;
background-position: top;
background-size: cover;
text-align: center center;
overflow: hidden;
}
.home .overlay{
background-color: rgba(0, 0, 0, 0.25);
height: 600px;
padding: 70px 0;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.home .overlay .title h1{
font-size: 45px;
color: #fff;
letter-spacing: 1px;
font-weight: 600;
margin: 0;
}
.home .overlay .title p{
line-height: 1.6em;
color: #ddd;
font-size: 16px;
font-weight: 300;
margin-top: 20px;
}
.home .overlay .title .a-btn{
font-weight: 400;
display: inline-block;
margin-top: 30px;
margin-right: 20px;
background-color: #0060e2;
color: #fff;
}
.home .overlay .title .a-btn:hover{
border: 1px solid #0060e2;
color: #fff;
background-color: transparent;
}
#media screen and (max-width: 480px){
.home .overlay .title .bannerImage{
display:none;
}
.box .item .location{
display:none;
}
.heading{
font-size:30px;
}
}
And then some more:
#media only screen and (max-width: 600px) {
.home div .title{
margin-top:4em;
clear:both;
width:90%;
}
.home div .title h1{
font-size:35px !important;
}
.giftCardAd{
width:95%;
}
#live-chat{
display:none;
}
}
The issue that I have with this is that it doesn't load the picture in or at least it doesn't display it properly to the user on iPhones.
I've tried changing the format of the picture from jpg to png but nothing seems to be working.
I would greatly appreciate the help!
Remove your background-attachment: fixed it's causing the problem
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>