你能给我这个图片的示例代码吗
Can you give me a sample code for this image
我一直在尝试仅使用 HTML 和 CSS 重新创建 picture/design,但在定位时我总是卡住。
The image I'm trying to recreate
有人可以告诉我该怎么做吗?
这是我的 CSS 代码。
我知道我搞砸了定位,但我没有任何其他想法
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&family=Lexend+Deca&display=swap');
.main{
width: 1440px;
background-color: hsl(233, 47%, 7%);
transform: translate(0%, 0%);
}
.inner{
width: fit-content;
height: fit-content;
border-radius: 10px;
border: purple 50px;
background-color: #333;
margin: 20%;
margin-top: 30%;
}
.texts{
background-color: hsl(244, 38%, 16%);
font-family: 'Lexend Deca', sans-serif;
width: 47.5%;
transform:translateY(60%);
height: 40%;
}
.mainhead{
color: hsl(0, 0%, 100%);
font-family: 'Inter', sans-serif;
}
.insights{
color: hsl(277, 64%, 61%);
}
.mainparagraph, .stats{
color: hsla(0, 0%, 100%, 0.75);
}
.stathead{
color: hsla(0, 0%, 100%, 0.6);
}
p {
font-size: 15px;
}
.image{
width:fit-content;
height: 40%;
background-color: hsl(277, 98%, 38%);
transform: translate(90%, -40%);
}
img {
opacity: 0.6;
}
<body>
<section class="main">
<section class="inner">
<section class="texts">
<h1 class="mainhead">
Get <span class="insights">insights </span>that help your business grow.
</h1>
<p class="mainparagraph">
Discover the benefits of data analytics and make better decisions regarding revenue, customer experience, and overall efficiency.
</p>
<section class="bottom">
<h1 class="stathead">10k+</h1>
<p class="stats">COMPANIES</p>
</section>
<section class="bottom">
<h1 class="stathead">314</h1>
<p class="stats">TEMPLATES</p>
</section>
<section class="bottom">
<h1 class="stathead">12M+</h1>
<p class="stats">QUERIES</p>
</section>
</section>
<section class="image">
<img src="images/image-header-desktop.jpg" alt="">
</section>
</section>
</section>
</body>
检查下面的这个片段。可以使用 Flexbox 或 CSS 网格进行定位。这里使用前者。我冒昧地修改了 HTML 和 CSS 以使其(紧密)匹配您的图像。
我建议您仔细阅读何时应该使用 HTML 元素,例如 <section>
。先研究 Flexbox,然后查看 CSS Grid,它们对于创建布局很重要,如果掌握了它们,您的生活会轻松很多。
图像是用filter
, an overlay and mix-blend-mode
组合完成的
一定要检查@zohirsalak 发布的关于将设计分解成更小块的链接。这是一个非常好的可视化和一个很好的学习课程。
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&family=Lexend+Deca&display=swap');
*, *::before, *::after {
margin: 0;
box-sizing: inherit;
}
html {
box-sizing: border-box;
}
body {
background-color: black;
padding: 1rem;
}
.insights {
display: flex;
border-radius: 10px;
background-color: hsl(244, 38%, 16%);
width: 1000px;
overflow: hidden;
}
.insights .texts {
flex: 0 0 50%;
background-color: hsl(244, 38%, 16%);
font-family: 'Lexend Deca', sans-serif;
padding: 4rem;
}
.insights h1 {
font-family: 'Inter', sans-serif;
font-size: 2em;
color: #fff;
margin-bottom: 2rem;
}
.insights .highlight {
color: hsl(277, 64%, 61%);
}
.insights p {
font-size: 1em;
line-height: 1.5;
margin: 2rem 0;
color: hsla(0, 0%, 100%, 0.75);
}
.insights .stats {
display: flex;
list-style: none;
padding: 0;
margin: 4rem 0 0;
gap: 1rem;
}
.insights .stats strong {
font-size: 1.5em;
color: #fff;
}
.insights .stats span {
font-size: 0.75em;
color: hsla(0, 0%, 100%, 0.75);
text-transform: uppercase;
letter-spacing: 1px;
}
.insights .image {
flex: 0 0 50%;
position: relative;
}
.insights .image::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: hsl(277, 64%, 61%);
mix-blend-mode: multiply;
}
.insights .image img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
filter: grayscale(100%);
}
<section class="insights">
<div class="texts">
<h1>Get <span class="highlight">insights </span>that help your business grow.
</h1>
<p>
Discover the benefits of data analytics and make better decisions regarding revenue, customer experience, and overall efficiency.
</p>
<ul class="stats">
<li>
<strong>10k+</strong>
<span>Companies</span>
</li>
<li>
<strong>314</strong>
<span>Templates</span>
</li>
<li>
<strong>12M+</strong>
<span>Queries</span>
</li>
</ul>
</div>
<figure class="image">
<img src="https://images.pexels.com/photos/3184357/pexels-photo-3184357.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260" alt="">
</figure>
</section>
我一直在尝试仅使用 HTML 和 CSS 重新创建 picture/design,但在定位时我总是卡住。 The image I'm trying to recreate
有人可以告诉我该怎么做吗?
这是我的 CSS 代码。 我知道我搞砸了定位,但我没有任何其他想法
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&family=Lexend+Deca&display=swap');
.main{
width: 1440px;
background-color: hsl(233, 47%, 7%);
transform: translate(0%, 0%);
}
.inner{
width: fit-content;
height: fit-content;
border-radius: 10px;
border: purple 50px;
background-color: #333;
margin: 20%;
margin-top: 30%;
}
.texts{
background-color: hsl(244, 38%, 16%);
font-family: 'Lexend Deca', sans-serif;
width: 47.5%;
transform:translateY(60%);
height: 40%;
}
.mainhead{
color: hsl(0, 0%, 100%);
font-family: 'Inter', sans-serif;
}
.insights{
color: hsl(277, 64%, 61%);
}
.mainparagraph, .stats{
color: hsla(0, 0%, 100%, 0.75);
}
.stathead{
color: hsla(0, 0%, 100%, 0.6);
}
p {
font-size: 15px;
}
.image{
width:fit-content;
height: 40%;
background-color: hsl(277, 98%, 38%);
transform: translate(90%, -40%);
}
img {
opacity: 0.6;
}
<body>
<section class="main">
<section class="inner">
<section class="texts">
<h1 class="mainhead">
Get <span class="insights">insights </span>that help your business grow.
</h1>
<p class="mainparagraph">
Discover the benefits of data analytics and make better decisions regarding revenue, customer experience, and overall efficiency.
</p>
<section class="bottom">
<h1 class="stathead">10k+</h1>
<p class="stats">COMPANIES</p>
</section>
<section class="bottom">
<h1 class="stathead">314</h1>
<p class="stats">TEMPLATES</p>
</section>
<section class="bottom">
<h1 class="stathead">12M+</h1>
<p class="stats">QUERIES</p>
</section>
</section>
<section class="image">
<img src="images/image-header-desktop.jpg" alt="">
</section>
</section>
</section>
</body>
检查下面的这个片段。可以使用 Flexbox 或 CSS 网格进行定位。这里使用前者。我冒昧地修改了 HTML 和 CSS 以使其(紧密)匹配您的图像。
我建议您仔细阅读何时应该使用 HTML 元素,例如 <section>
。先研究 Flexbox,然后查看 CSS Grid,它们对于创建布局很重要,如果掌握了它们,您的生活会轻松很多。
图像是用filter
, an overlay and mix-blend-mode
一定要检查@zohirsalak 发布的关于将设计分解成更小块的链接。这是一个非常好的可视化和一个很好的学习课程。
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&family=Lexend+Deca&display=swap');
*, *::before, *::after {
margin: 0;
box-sizing: inherit;
}
html {
box-sizing: border-box;
}
body {
background-color: black;
padding: 1rem;
}
.insights {
display: flex;
border-radius: 10px;
background-color: hsl(244, 38%, 16%);
width: 1000px;
overflow: hidden;
}
.insights .texts {
flex: 0 0 50%;
background-color: hsl(244, 38%, 16%);
font-family: 'Lexend Deca', sans-serif;
padding: 4rem;
}
.insights h1 {
font-family: 'Inter', sans-serif;
font-size: 2em;
color: #fff;
margin-bottom: 2rem;
}
.insights .highlight {
color: hsl(277, 64%, 61%);
}
.insights p {
font-size: 1em;
line-height: 1.5;
margin: 2rem 0;
color: hsla(0, 0%, 100%, 0.75);
}
.insights .stats {
display: flex;
list-style: none;
padding: 0;
margin: 4rem 0 0;
gap: 1rem;
}
.insights .stats strong {
font-size: 1.5em;
color: #fff;
}
.insights .stats span {
font-size: 0.75em;
color: hsla(0, 0%, 100%, 0.75);
text-transform: uppercase;
letter-spacing: 1px;
}
.insights .image {
flex: 0 0 50%;
position: relative;
}
.insights .image::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: hsl(277, 64%, 61%);
mix-blend-mode: multiply;
}
.insights .image img {
display: block;
width: 100%;
height: 100%;
object-fit: cover;
filter: grayscale(100%);
}
<section class="insights">
<div class="texts">
<h1>Get <span class="highlight">insights </span>that help your business grow.
</h1>
<p>
Discover the benefits of data analytics and make better decisions regarding revenue, customer experience, and overall efficiency.
</p>
<ul class="stats">
<li>
<strong>10k+</strong>
<span>Companies</span>
</li>
<li>
<strong>314</strong>
<span>Templates</span>
</li>
<li>
<strong>12M+</strong>
<span>Queries</span>
</li>
</ul>
</div>
<figure class="image">
<img src="https://images.pexels.com/photos/3184357/pexels-photo-3184357.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260" alt="">
</figure>
</section>