Reputation: 85
I have a simple page created using html and css, when I shrink the browser the button small-button
goes outside of the div and I don't know why, I want to keep it in the div no matter how much I shrink the browser so that it is responsive. How can I do that?
here is my code:
* {
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
.nav {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 50%;
}
.header {
height: 8%;
}
.nav-h1 {
text-align: center;
margin-top: 27px;
font-size: 40px;
}
a {
display: inline-block;
margin: 10px;
font-family: 'Segoe UI',sans-serif;
font-family: SegoeUI;
font-size: 16px;
font-weight: bold;
color: black;
font-weight: bold;
}
.a-container {
margin-left: 10%;
margin-top: 27px;
}
.footer {
background-color: #e8e8e8;
height: 288px;
width: 100%;
}
.alignleft {
float: left;
margin-left: 8%;
font-family: SegoeUI;
font-size: 18px;
font-weight: 900;
color: #000000;
}
.alignright {
float: right;
margin-right: 8%;
display: flex;
flex-direction: row;
}
.logo-section {
margin-top: 1.3%;
margin-left: 2%;
}
.logo-img {
padding: 6px;
}
.first-section {
width: 100%;
height: 800px;
background-image: url("/assets/images/first-image.png");
background-repeat: no-repeat;
background-size: contain;
position: relative;
float: left;
}
.first-section-p {
width: 400px;
height: 314px;
margin-left: 10%;
padding-top: 10%;
font-family: SegoeUI;
font-weight: 900;
font-size: 4vh;
font-weight: 900;
text-align: center;
color: #262262;
}
.small-button {
width: 331px;
height: 92px;
margin-left: 12%;
background-color: #e7af17;
font-family: SegoeUI;
font-size: 18px;
font-weight: 900;
color: white;
border: none;
}
.second-section-text {
color: #e8e8e8;
font-weight: 900;
font-size: 70px;
line-height: 0.7;
font-family: SegoeUI;
margin-left: 12%;
}
@media (min-width: 1281px) {
.first-section {
width: 100%;
height: 800px;
background-image: url("/assets/images/first-image.png");
background-repeat: no-repeat;
background-size: cover;
}
.small-button {
width: 331px;
height: 92px;
margin-top: 8%;
margin-left: 12%;
background-color: #e7af17;
font-family: SegoeUI;
font-size: 18px;
font-weight: 900;
color: white;
border: none;
}
}
<div class="main-container">
<div class="headers">
<div class="nav">
<h1 class="nav-h1">Logo</h1>
<div class="a-container">
<a>About</a>
<a>Vision</a>
<a>Solutions</a>
<a>Technology</a>
<a>Contact</a>
</div>
<div class="logo-section">
<img class="logo-img" src="/assets/images/facebook.png" alt="facebook logo">
<img class="logo-img" src="/assets/images/linkedin.png" alt="linkedin logo">
</div>
</div>
</div>
<div class="content">
<div class="content-inside">
<div class="first-section">
<p class="first-section-p">Turnkey platforms <br> for businesses looking to rule the online market
</p>
<button class="small-button">LEARN MORE</button>
</div>
<div class="second-section">
<p class="second-section-text">WHAT</p>
<p class="second-section-text">WHE DO</p>
<p class="second-section-text">BEST</p>
</div>
</div>
</div>
<div class="footer"></div>
</div>
Upvotes: 3
Views: 427
Reputation: 1
You can use the the @media css rule:
@media only screen and (max-width: 'your device width') {
.element{
//styling rules here
}
}
You can use this rule more than one time to make your website responsive for more device widths.
Upvotes: 0
Reputation: 4101
make you sure that you have this meta in html file <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
and trying to change the sizes and position of the elements that you want to resize but don't define all properties
just define the properties that want to change
* {
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
.nav {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 50%;
}
.header {
height: 8%;
}
.nav-h1 {
text-align: center;
margin-top: 27px;
font-size: 40px;
}
a {
display: inline-block;
margin: 10px;
font-family: 'Segoe UI', sans-serif;
font-family: SegoeUI;
font-size: 16px;
font-weight: bold;
color: black;
font-weight: bold;
}
.a-container {
margin-left: 10%;
margin-top: 27px;
}
.footer {
background-color: #e8e8e8;
height: 288px;
width: 100%;
}
.alignleft {
float: left;
margin-left: 8%;
font-family: SegoeUI;
font-size: 18px;
font-weight: 900;
color: #000000;
}
.alignright {
float: right;
margin-right: 8%;
display: flex;
flex-direction: row;
}
.logo-section {
margin-top: 1.3%;
margin-left: 2%;
}
.logo-img {
padding: 6px;
}
.first-section {
width: 100%;
height: 800px;
background-image: url("/assets/images/first-image.png");
background-repeat: no-repeat;
background-size: contain;
position: relative;
float: left;
}
.first-section-p {
width: 400px;
height: 314px;
margin-left: 10%;
padding-top: 10%;
font-family: SegoeUI;
font-weight: 900;
font-size: 4vh;
font-weight: 900;
text-align: center;
color: #262262;
}
.small-button {
width: 331px;
height: 92px;
margin-left: 12%;
background-color: #e7af17;
font-family: SegoeUI;
font-size: 18px;
font-weight: 900;
color: white;
border: none;
}
.second-section-text {
color: #e8e8e8;
font-weight: 900;
font-size: 70px;
line-height: 0.7;
font-family: SegoeUI;
margin-left: 12%;
}
@media (min-width: 1281px) {
.first-section {
width: 100%;
height: 800px;
background-image: url("/assets/images/first-image.png");
background-repeat: no-repeat;
background-size: cover;
}
.small-button {
width: 321px;
height: 82px;
margin-top: -28%;
margin-left: 12%;
background-color: #e7af17;
font-family: SegoeUI;
font-size: 18px;
font-weight: 900;
color: white;
border: none;
}
}
@media (max-width: 800px) {
.small-button {
margin-top: -30%;
margin-left: 14%;
}
}
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<div class="main-container">
<div class="headers">
<div class="nav">
<h1 class="nav-h1">Logo</h1>
<div class="a-container">
<a>About</a>
<a>Vision</a>
<a>Solutions</a>
<a>Technology</a>
<a>Contact</a>
</div>
<div class="logo-section">
<img class="logo-img" src="/assets/images/facebook.png" alt="facebook logo">
<img class="logo-img" src="/assets/images/linkedin.png" alt="linkedin logo">
</div>
</div>
</div>
<div class="content">
<div class="content-inside">
<div class="first-section">
<p class="first-section-p">Turnkey platforms <br> for businesses looking to rule the online market
</p>
<button class="small-button">LEARN MORE</button>
</div>
<div class="second-section">
<p class="second-section-text">WHAT</p>
<p class="second-section-text">WHE DO</p>
<p class="second-section-text">BEST</p>
</div>
</div>
</div>
<div class="footer"></div>
</div>
Upvotes: 1
Reputation: 292
Try setting the viewport with a meta
tag.
See this resource: https://www.w3schools.com/html/html_responsive.asp
Upvotes: 0