標題
描述文字...
圖文並排是網頁設計中常見的佈局模式,用於產品展示、服務介紹、關於頁面等。
.image-text {
display: flex;
gap: 40px;
align-items: center;
}
.image-text img {
width: 50%;
border-radius: 8px;
}
.image-text-content {
flex: 1;
}
<div class="image-text">
<img src="image.jpg" alt="圖片" />
<div class="image-text-content">
<h2>標題</h2>
<p>描述文字...</p>
</div>
</div>
描述文字...
.image-text {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 40px;
align-items: center;
}
.image-text img {
width: 100%;
border-radius: 8px;
}
<div class="image-text">
<img src="image.jpg" alt="圖片" />
<div class="image-text-content">
<h2>Grid 標題</h2>
<p>Grid 描述文字...</p>
</div>
</div>
Grid 描述文字...
常見於特色介紹,奇數項圖左文右,偶數項文左圖右:
.feature-section {
display: flex;
gap: 60px;
align-items: center;
padding: 80px 0;
}
.feature-image {
flex: 1;
}
.feature-image img {
width: 100%;
border-radius: 12px;
}
.feature-content {
flex: 1;
}
/* 偶數項反轉 */
.feature-section:nth-child(even) {
flex-direction: row-reverse;
}
或使用 CSS class:
.feature-section.reverse {
flex-direction: row-reverse;
}
<section class="feature-section">
<div class="feature-image">
<img src="image1.jpg" alt="圖片 1" />
</div>
<div class="feature-content">
<h2>特色一</h2>
<p>描述內容 1...</p>
</div>
</section>
<section class="feature-section">
<div class="feature-image">
<img src="image2.jpg" alt="圖片 2" />
</div>
<div class="feature-content">
<h2>特色二</h2>
<p>描述內容 2...</p>
</div>
</section>
描述內容 1...
描述內容 2...
在小螢幕上堆疊顯示:
.image-text {
display: flex;
flex-direction: column;
gap: 24px;
}
.image-text img {
width: 100%;
border-radius: 8px;
}
@media (min-width: 768px) {
.image-text {
flex-direction: row;
gap: 40px;
align-items: center;
}
.image-text img {
width: 50%;
}
}
<div class="image-text">
<img src="responsive.jpg" alt="響應式圖片" />
<div class="image-text-content">
<h2>響應式標題</h2>
<p>在大螢幕併排,小螢幕堆疊。</p>
</div>
</div>
在大螢幕併排,小螢幕堆疊。
.feature {
display: flex;
flex-direction: column;
gap: 32px;
padding: 60px 24px;
}
@media (min-width: 768px) {
.feature {
flex-direction: row;
gap: 60px;
align-items: center;
padding: 100px 24px;
}
.feature.reverse {
flex-direction: row-reverse;
}
}
.feature-image {
flex: 1;
}
.feature-image img {
width: 100%;
border-radius: 16px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}
.feature-content {
flex: 1;
}
.feature-content h2 {
font-size: 32px;
margin: 0 0 16px;
}
.feature-content p {
color: #666;
line-height: 1.8;
margin: 0 0 24px;
}
.feature-content .btn {
display: inline-block;
padding: 12px 28px;
background: #007bff;
color: white;
text-decoration: none;
border-radius: 8px;
}
<section class="feature">
<div class="feature-image">
<img src="product.jpg" alt="產品圖片" />
</div>
<div class="feature-content">
<h2>強大功能</h2>
<p>這是功能的詳細描述內容,解釋為什麼這個產品這麼出色。</p>
<a href="#" class="btn">立即體驗</a>
</div>
</section>
.about-section {
display: grid;
grid-template-columns: 1fr;
gap: 40px;
max-width: 1200px;
margin: 0 auto;
padding: 80px 24px;
}
@media (min-width: 768px) {
.about-section {
grid-template-columns: 1fr 1fr;
gap: 60px;
align-items: center;
}
}
.about-image {
position: relative;
}
.about-image img {
width: 100%;
border-radius: 16px;
}
.about-image::after {
content: '';
position: absolute;
top: 20px;
left: 20px;
right: -20px;
bottom: -20px;
border: 3px solid #007bff;
border-radius: 16px;
z-index: -1;
}
.about-content h2 {
font-size: 36px;
margin: 0 0 24px;
}
.about-content p {
color: #666;
line-height: 1.8;
}
<section class="about-section">
<div class="about-image">
<img src="about.jpg" alt="關於我們" />
</div>
<div class="about-content">
<h2>關於我們</h2>
<p>我們致力於提供最優質的服務與教學內容。</p>
</div>
</section>
我們致力於提供最優質的服務與教學內容。
.services {
max-width: 1200px;
margin: 0 auto;
}
.service-item {
display: flex;
flex-direction: column;
gap: 32px;
padding: 60px 24px;
border-bottom: 1px solid #eee;
}
@media (min-width: 768px) {
.service-item {
flex-direction: row;
gap: 48px;
align-items: center;
}
.service-item:nth-child(even) {
flex-direction: row-reverse;
}
}
.service-image {
flex: 0 0 400px;
}
.service-image img {
width: 100%;
border-radius: 12px;
}
.service-content {
flex: 1;
}
.service-number {
font-size: 64px;
font-weight: bold;
color: #007bff;
opacity: 0.2;
line-height: 1;
}
.service-content h3 {
font-size: 24px;
margin: 8px 0 16px;
}
.service-content p {
color: #666;
line-height: 1.8;
}
<section class="services">
<div class="service-item">
<div class="service-image">
<img src="service1.jpg" alt="服務 1" />
</div>
<div class="service-content">
<div class="service-number">01</div>
<h3>網頁設計</h3>
<p>提供專業的 UI/UX 設計與開發服務。</p>
</div>
</div>
<div class="service-item">
<div class="service-image">
<img src="service2.jpg" alt="服務 2" />
</div>
<div class="service-content">
<div class="service-number">02</div>
<h3>系統開發</h3>
<p>高效能的後端 API 與資料庫架構設計。</p>
</div>
</div>
</section>
提供專業的 UI/UX 設計與開發服務。
高效能的後端 API 與資料庫架構設計。
.card {
display: flex;
flex-direction: column;
}
<div class="card">
<img src="top.jpg" alt="上方圖片" />
<div class="card-body">
<h3>標題</h3>
<p>圖片位於文字上方。</p>
</div>
</div>
.hero {
position: relative;
padding: 100px 24px;
color: white;
}
.hero-background {
position: absolute;
inset: 0;
z-index: -1;
}
.hero-background img {
width: 100%;
height: 100%;
object-fit: cover;
}
.hero-background::after {
content: '';
position: absolute;
inset: 0;
background: rgba(0, 0, 0, 0.5);
}
<section class="hero">
<div class="hero-background">
<img src="hero.jpg" alt="背景圖" />
</div>
<div class="hero-content">
<h1>文字在背景上</h1>
<p>使用絕對定位將圖片置於底層。</p>
</div>
</section>
.article img {
float: left;
width: 300px;
margin: 0 24px 16px 0;
border-radius: 8px;
}
<div class="article">
<img src="float.jpg" alt="浮動圖片" />
<p>這是一段很長的文字,會環繞在圖片周圍。文字環繞是傳統報章雜誌常見的排版方式...</p>
</div>