html - 图像位置推出元素
问题描述
我的代码有一点小问题。基本上,我正在挑战从该网站重新创建登录页面
https://www.frontendmentor.io/challenges
这是我正在重新创建的页面。
正如您在使用键盘的图像中看到的那样,图像完全位于屏幕右侧。
我在这里的代码中实现了相同的外观......
但是当我检查我的元素时,我可以看到它把我的 div 推到了左边。
我知道,在更远的地方,这会影响其他元素,因为它会在右侧显示太多的边距,而不是除了看起来居中的图像之外的所有内容。我试过使用绝对位置,但没有解决问题。我希望有人可以帮助我看看我可以在哪里改进我的代码,以便图像位于它的位置,而不会将其他元素推到左侧。
这是代码...
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" sizes="32x32" href="./assets/favicon-32x32.png">
<!-- style sheet -->
<link rel="stylesheet" href="./styles.css">
<!-- Google font -->
<link rel="preconnect" href="https://fonts.gstatic.com">
<link
href="https://fonts.googleapis.com/css2?family=Barlow:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
rel="stylesheet">
<title>Frontend Mentor | Typemaster pre-launch landing page</title>
</head>
<body>
<!-- header section -->
<header>
<img src="./assets/shared/logo.svg" alt="logo">
<button class="pre-order">pre-order now</button>
</header>
<!-- main section -->
<div class="container">
<div class="info__section">
<h1 class="main__title">Typemaster keyboard</h1>
<p class="main__info">Improve your productivity and gaming without breaking the bank. Upgrade to a high quality
mechanical typing experience.</p>
<div class="date__info">
<button class="pre-order__org">Pre-order now</button>
<p class="release__date">Release on 5/27</p>
</div>
</div>
<img class="keyboard__img" src="https://i.stack.imgur.com/0GVAu.jpg" alt="keyboard">
</div>
</body>
</html>
CSS
:root {
--off-blue: #e7eff2;
--orange: #ef6718;
--lg-grey: #7b8bad;
--dr-blue: #192843;
--white: #FFFFFF;
}
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
/* End of reset */
body {
font-family: 'Barlow', sans-serif;
}
/* header section styles */
header {
margin: 0 auto;
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px;
}
.pre-order {
width: 160px;
height: 50px;
font-size: 1em;
border-radius: 10px;
text-transform: uppercase;
border: none;
background-color: var(--off-blue);
font-weight: 700;
color: var(--dr-blue);
line-height: 1.625rem;
transition: 300ms ease-in-out;
}
.pre-order:hover {
background-color: var(--dr-blue);
color: var(--off-blue);
}
/* end of header section styles */
/* main section styles */
.container {
margin: 0 auto;
padding: 20px;
}
.main__title {
font-size: 12vw;
font-weight: 900;
text-transform: uppercase;
color: var(--dr-blue);
margin-top: 20px;
}
.main__info {
color: var(--lg-grey);
margin-top: 30px;
line-height: 1.5em;
}
.date__info {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
margin-top: 30px;
}
.pre-order__org {
width: 160px;
height: 50px;
font-size: 1em;
border-radius: 10px;
text-transform: uppercase;
border: none;
background-color: var(--orange);
font-weight: 700;
color: var(--white);
line-height: 1.625rem;
transition: 300ms ease-in-out;
}
.release__date {
align-self: center;
margin-right: 30px;
color: var(--lg-grey);
}
.keyboard__img {
position: absolute;
background-size: cover;
margin-top: 60px;
height: 88vw;
border-top-left-radius: 1.25em;
border-bottom-left-radius: 1.25em;
}
/* end of main section styles */
@media screen and (min-width: 768px) {
}
@media screen and (min-width: 900px) {
header {
max-width: 1200px;
}
.container {
max-width: 1200px;
}
}
解决方案
推荐阅读
- arrays - 没有 $0 的 Swift 数组映射(高阶函数)
- javascript - 在 Javascript Rhino 上生成 docx
- python - Sympy 无法计算积分
- java - 在 heroku 上部署 Java Maven 电报机器人
- mysql - 如何使用mysql显示平局?
- linux - gperftools/tcmalloc 2.8 - 内存不足
- bash - bash 使用两个变量创建一个变量,它们之间有一个空格?
- php - xdebug_info 未在 MAMP 上运行
- ruby-on-rails - 使用纯 Ruby 发送电子邮件
- php - React native IOS App使用RNFetchBlob上传图片后会关闭