我试图为我的投资组合网站做一个主页,有一个响应式的css背景矩形和一个并排的英雄,左边是文本,右边是图像,比如网站模板here。我不知道我在HTML或CSS中做错了什么,使得背景css矩形没有扩展到屏幕的整个宽度。我是新来的,所以我很感激你的帮助。
@charset "utf-8";
/* CSS Document */
@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@500&display=swap');
/*Variable*/
:root {
--primary-color: #0d081a;
--secondary-blue: #eaf0f9;
--secondary-gray: #48463b;
--body-bg: ffffff;
}
/*Global Styles*/
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
html {
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
scroll-behavior: smooth;
}
body {
background-color: var(--body-bg);
font-family: Arial, Helvetica, sans-serif;
line-height: 1.6;
margin: 0;
min-height: 100vh;
}
img {
width: 100%;
height: 100%;
}
a {
color: black;
text-decoration: none;
}
section {
display: flex;
align-items: center;
justify-content: center;
}
.background {
border: 0;
padding: 0;
width: max-content;
background-color: var(--secondary-blue);
}
.container {
width: 90%;
height: 100%;
margin: 0 auto;
}
.primary-btn {
display: inline-block;
background-color: var(--primary-color);
color: white;
font-size: 1.8rem;
padding: 0.6em 1.6em;
border-radius: 50px;
}
.buttons {
margin-top: 3rem;
display: flex;
align-items: center;
justify-content: flex-start;
gap: 2rem;
}
/*nav*/
#navigation {
position: fixed;
right: 50px;
height: auto;
top: 20px;
z-index: 100;
}
/*hero section*/
#hero {
height: 100vh;
width: 100%;
padding-top: 10rem;
}
#hero .container {
display: flex;
align-items: center;
justify-content: center;
}
#hero .container .left {
flex: 6;
}
#hero .container .right {
flex: 8;
}
#hero .left .subheading {
font-size: 1.8rem;
font-weight: 500;
text-transform: uppercase;
color: var(--primary-color);
}
#hero .left .heading {
font-size: 6rem;
font-family: 'Times New Roman', Times, serif;
font-weight: 600;
}
#hero .left .desc {
margin-top: 2.5rem;
max-width: 400px;
font-size: 1.5 rem;
color: var(--secondary-blue);
}
#hero .right {
text-align: right;
}
#hero .right img {
width: 100%;
max-width: 450px;
height: 600px;
object-fit: cover;
object-position: 50% 30%;
border-radius: 12px;
}
@media only screen and (max-width: 768px) {
html {
font-size: 9px;
}
#hero .container {
flex-direction: column-reverse;
}
#hero .container .right {
text-align: center;
flex: 1;
margin-bottom: 2rem;
}
#hero .container .left {
text-align: center;
padding-right: 0;
flex: 1;
height: fit-content;
}
#hero .left .buttons {
justify-content: center;
}
#hero .left .heading {
font-size: 4rem;
margin: 0 auto;
}
#hero .container .left .desc {
margin: 0 auto;
margin-top: 2rem;
}
#hero .right img {
width: 100%;
height: 400px;
}
}
@media only screen and (max-width: 1200px) {
#hero .container .right {
flex: 6;
}
}
/* End Hero Section*/
/*Navbar*/
ul {
margin: 0;
padding: 0;
list-style: none;
}
a {
text-decoration: none;
}
.main-nav {
margin-top: 5px;
}
.logo a,
.main-nav a {
padding: 10px 15px;
text-transform: uppercase;
text-align: center;
display: block;
}
.main-nav a {
color: #34495e;
font-size: 1.5em;
}
.main-nav a:hover {
color: #718daa;
}
.header {
padding-top: 1em;
padding-bottom: 1em;
}
/* Nav Media Queries*/
@media (min-width: 769px) {
.header,
.main-nav {
display: flex;
}
.header {
flex-direction: column;
align-items: flex-end;
.header {
width: 80%;
margin: 0 auto;
max-width: 1150px;
}
}
}
@media (min-width: 1025px) {
.header {
flex-direction: row;
justify-content: flex-end;
}
}
<body>
<!--nav section-->
<header class="nav">
<ul class="main-nav">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Contact</a></li>
</ul>
</header>
<!--end nav section-->
<!--hero section-->
<section id="hero">
<div class="background">
<div class="container">
<div class="left">
<p class="subheading"></p>
<h2 class="heading">
<div class="wrapper"><span>Hello, nice </span></div>
<div class="wrapper"><span>to"meet" you!</span></div>
</h2>
<p class="desc">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<div class="buttons">
<a href="#" class="primary-btn">Contact Me</a>
</div>
</div>
<div class="right">
<img src="/linkedinheadshot.png" alt="picture">
</div>
</div>
</div>
</section>
<!--End hero section-->
</body>
我试过调整@mediaquery中的填充、边距和宽度,研究google和堆栈溢出的解决方案。
1条答案
按热度按时间dsekswqp1#
我检查了您问题,如果您使用
它会解决你的问题,我也是一个新的网络开发人员,现在学习javascript,如果它帮助你喜欢这个,如果你还有任何问题,张贴你的问题