我是前端新手,我在处理布局和响应式方面遇到了一些问题。
到目前为止,这是我的代码:
body {
margin: 0;
background-color: #353535;
}
.header {
color: white;
text-align: center;
font-size: 20px;
margin: auto;
font-family: 'Inter', serif;
font-weight: bold;
width: 700px;
height: 150px;
background-color: #3C6E71;
border-radius: 25px;
}
.header h1{
margin: 3px;
}
.content {
margin: auto;
width: 50%;
padding: 5px;
text-align: center;
}
.content img {
object-fit: cover;
width: 500px;
height: 400px;
border: 3px solid white;
}
.content p{
margin-left: 15px;
display: block;
margin: 2px 0 0 0;
color: white;
font-family: 'Inter', serif;
font-weight: bold;
}
.button {
background-color: #D9D9D9;
border: none;
color: #D00000;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 13px;
margin: 4px 2px;
cursor: pointer;
font-family:'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
}
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="header">
<h1>We found trip that suits you</h1>
<h1>Kieve Summer Camp</h1>
<h1>Nobleboro, USA</h1>
</div>
<div class="content">
<p>
位于缅因州达马里斯科塔湖畔的Kieve自1926年以来一直致力于培养男孩的品格和教授他们野外技能。除了重点放在远足活动上——通常只有一半的营员在营地,另一半在常规露营和半日冒险中探索——活动还包括广泛的绳索课程、曲棍球、棒球、木工、射击、钓鱼、游泳、划桨板、风帆、帆船、网球、足球和摄影。这是一个更传统的营地,每个男孩都有一个职责,并参加日常活动,如升旗仪式和晚祷,鼓励营员尝试新的活动,拓宽他们的舒适区域。湖对面的姐妹营地——Wavus女孩营地——以类似的理念运作,教导勇气、适应能力和对大自然的尊重。
</p>
<img src="https://images.pexels.com/photos/7772721/pexels-photo-7772721.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" alt="Italian Trulli">
</div>
<button class="button">Save</button>
<button class="button">Randomize again</button>
</body>
</html>
你可以看到我迄今为止的尝试,这是我想要实现的效果:https://www.figma.com/file/lqy0NTOiakaxeG5HoJk50f/Untitled?node-id=0%3A1。
我知道这很基础,但无论我尝试什么,总是会出现其他问题。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我会使用css grid将图像和按钮放在文本旁边。
还要将按钮和图像一起包装在一个div中(我给它一个类名为right-col):
.content { display: grid; grid-template-columns: repeat(2, 50%); gap: 1em; } .right-col { justify-self: start; }你可能还想将所有代码包装在一个具有最大宽度的包装器中,并使标题和内容都为100%。