ដើម្បីឱ្យ Logo និង Widget ផ្នែក Header ទាំងអស់រៀបចំមកនៅចំកណ្តាល (Center Alignment) ព្រមទាំងមានទំហំសមរម្យស្អាត ខ្ញុំបានកែសម្រួល CSS លើ .header-container, .header, និងរូបភាពក្នុង Header ឱ្យតម្រៀបនៅចំកណ្ដាលអេក្រង់។
សូម Copy កូដ XML ដែលបានកែសម្រួលរួចរាល់ខាងក្រោមនេះ ទៅ Paste ជំនួសកូដចាស់ក្នុង Theme -> Edit HTML៖
XML
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html b:css='false' b:defaultwidgetversion='2' b:layoutsVersion='3' expr:dir='data:blog.languageDirection' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'>
<head>
<meta charset='UTF-8'/>
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' name='viewport'/>
<title><data:blog.pageTitle/></title>
<b:include data='blog' name='all-head-content'/>
<!-- Google Fonts & FontAwesome -->
<link href='https://fonts.googleapis.com/css2?family=Kantumruy+Pro:ital,wght@0,300..700;1,300..700&display=swap' rel='stylesheet'/>
<link href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css' rel='stylesheet'/>
<b:skin><![CDATA[
:root {
--bg-color: #f4f6f9;
--card-bg: #ffffff;
--text-color: #333333;
--text-muted: #666666;
--primary-color: #0d6efd;
--border-color: #dee2e6;
--header-bg: #ffffff;
}
[data-theme="dark"] {
--bg-color: #121212;
--card-bg: #1e1e1e;
--text-color: #e0e0e0;
--text-muted: #aaaaaa;
--primary-color: #3d8bfd;
--border-color: #2c2c2c;
--header-bg: #181818;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'Kantumruy Pro', sans-serif;
}
html, body {
width: 100%;
overflow-x: hidden;
}
body {
background-color: var(--bg-color);
color: var(--text-color);
line-height: 1.6;
transition: background 0.3s, color 0.3s;
}
header {
background-color: var(--header-bg);
border-bottom: 1px solid var(--border-color);
position: sticky;
top: 0;
z-index: 1000;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.header-container {
max-width: 1200px;
margin: 0 auto;
padding: 12px 15px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 15px;
text-align: center;
}
.logo a {
font-size: 24px;
font-weight: 700;
color: var(--primary-color);
text-decoration: none;
word-break: break-all;
}
nav ul {
display: flex;
list-style: none;
gap: 15px;
align-items: center;
justify-content: center;
flex-wrap: wrap;
}
nav a {
text-decoration: none;
color: var(--text-color);
font-weight: 500;
font-size: 14px;
transition: color 0.2s;
}
nav a:hover {
color: var(--primary-color);
}
.theme-toggle {
background: none;
border: none;
font-size: 16px;
color: var(--text-color);
cursor: pointer;
padding: 5px;
}
/* ស្ទីលសម្រាប់តម្រៀប Header Sections & Widgets ឱ្យនៅចំកណ្តាល */
.widget-section {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
width: 100%;
margin: 10px 0;
text-align: center;
}
.widget-section .widget {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
}
/* កំណត់ទំហំរូបភាព Logo / Banner ក្នុង Header ឱ្យនៅចំកណ្តាល */
.widget-section img, header img {
max-width: 100%;
height: auto;
max-height: 120px;
margin: 0 auto;
display: block;
object-fit: contain;
}
.container {
max-width: 1200px;
margin: 15px auto;
padding: 0 15px;
}
.breaking-news {
background-color: #dc3545;
color: white;
padding: 10px 15px;
border-radius: 5px;
margin-bottom: 15px;
display: flex;
align-items: center;
gap: 10px;
font-size: 13px;
}
.breaking-title {
font-weight: 700;
white-space: nowrap;
}
.post-grid {
display: grid;
grid-template-columns: 1fr;
gap: 15px;
}
@media(min-width: 600px) {
.post-grid {
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 20px;
}
}
.post-card {
background-color: var(--card-bg);
border: 1px solid var(--border-color);
border-radius: 8px;
overflow: hidden;
transition: transform 0.2s, box-shadow 0.2s;
}
.post-card:hover {
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.post-img {
width: 100%;
height: 180px;
object-fit: cover;
display: block;
}
.post-content {
padding: 15px;
}
.post-title {
font-size: 16px;
font-weight: 600;
margin-bottom: 8px;
line-height: 1.4;
}
.post-title a {
text-decoration: none;
color: var(--text-color);
display: block;
}
.post-title a:hover {
color: var(--primary-color);
}
.post-snippet {
font-size: 13px;
color: var(--text-muted);
}
/* Single Post View Style */
.single-post {
background: var(--card-bg);
padding: 25px;
border-radius: 8px;
border: 1px solid var(--border-color);
}
.single-post-title {
font-size: 24px;
font-weight: 700;
margin-bottom: 15px;
line-height: 1.4;
}
.single-post-body {
font-size: 16px;
line-height: 1.8;
color: var(--text-color);
word-wrap: break-word;
}
.single-post-body img {
max-width: 100% !important;
height: auto !important;
border-radius: 6px;
margin: 15px 0;
}
.no-posts {
text-align: center;
padding: 30px;
color: var(--text-muted);
background: var(--card-bg);
border-radius: 8px;
border: 1px solid var(--border-color);
}
footer {
text-align: center;
padding: 20px;
background-color: var(--header-bg);
border-top: 1px solid var(--border-color);
margin-top: 30px;
color: var(--text-muted);
font-size: 13px;
}
]]></b:skin>
</head>
<body>
<!-- Header Section ( Logo Center ) -->
<div class='widget-section'>
<b:section class='header' id='header' maxwidgets='2' showaddelement='yes'>
<b:widget id='Header1' locked='true' title='Page Header' type='Header' version='2' visible='true'/>
</b:section>
</div>
<!-- Navigation Menu -->
<header>
<div class='header-container'>
<nav>
<ul>
<li><a expr:href='data:blog.homepageUrl'>ទំព័រដើម</a></li>
<li><a href='#'>ជាតិ</a></li>
<li><a href='#'>អន្តរជាតិ</a></li>
<li><a href='#'>បច្ចេកវិទ្យា</a></li>
<li><a href='#'>កម្សាន្ត</a></li>
<li>
<button class='theme-toggle' id='themeToggleBtn' onclick='toggleTheme()'>
<i class='fa-solid fa-moon' id='themeIcon'/>
</button>
</li>
</ul>
</nav>
</div>
</header>
<!-- HEADER2 SECTION -->
<div class='widget-section'>
<b:section class='header2' id='header2' showaddelement='yes'/>
</div>
<!-- CROSSCOL SECTION -->
<div class='widget-section'>
<b:section class='crosscol' id='crosscol' showaddelement='yes'/>
</div>
<!-- Main Content Area -->
<div class='container'>
<!-- Breaking News Banner -->
<div class='breaking-news'>
<span class='breaking-title'><i class='fa-solid fa-bolt'/> ព័ត៌មានក្ដៅៗ</span>
<marquee behavior='scroll' direction='left'>សូមស្វាគមន៍មកកាន់គេហទំព័រព័ត៌មាន! លោកអ្នកអាចស្វែងរកព័ត៌មានថ្មីៗបាននៅទីនេះ។</marquee>
</div>
<!-- Blogger Loop Section -->
<b:section id='main-section' name='Main Section' showaddelement='yes'>
<b:widget id='Blog1' locked='true' title='Blog Posts' type='Blog' version='2' visible='true'>
<b:includable id='main'>
<!-- ទំព័របង្ហាញខ្លឹមសារព័ត៌មានពេញ -->
<b:if cond='data:view.isPost'>
<b:loop values='data:posts' var='post'>
<article class='single-post'>
<h1 class='single-post-title'><data:post.title/></h1>
<div class='single-post-body'>
<data:post.body/>
</div>
</article>
</b:loop>
<!-- ទំព័រមុខបង្ហាញកាតព័ត៌មាន (Homepage View) -->
<b:else/>
<div class='post-grid'>
<b:if cond='data:posts and not data:posts.empty'>
<b:loop values='data:posts' var='post'>
<div class='post-card'>
<a expr:href='data:post.url'>
<b:if cond='data:post.featuredImage'>
<img class='post-img' expr:alt='data:post.title' expr:src='data:post.featuredImage'/>
<b:else/>
<b:if cond='data:post.firstImageUrl'>
<img class='post-img' expr:alt='data:post.title' expr:src='data:post.firstImageUrl'/>
<b:else/>
<img alt='No Image' class='post-img' src='https://via.placeholder.com/400x200?text=Khmer+News'/>
</b:if>
</b:if>
</a>
<div class='post-content'>
<h3 class='post-title'>
<a expr:href='data:post.url'><data:post.title/></a>
</h3>
<p class='post-snippet'>
<b:eval expr='snippet(data:post.body, {length: 90})'/>
</p>
</div>
</div>
</b:loop>
<b:else/>
<div class='no-posts'>
<p><i class='fa-solid fa-triangle-exclamation'/> មិនទាន់មានអត្ថបទព័ត៌មានត្រូវបានបង្ហាញទេ!</p>
</div>
</b:if>
</div>
</b:if>
</b:includable>
</b:widget>
</b:section>
</div>
<!-- Footer -->
<footer>
<p>&copy; 2026 <data:blog.title/>. រក្សាសិទ្ធិគ្រប់យ៉ាង។</p>
</footer>
<!-- Dark/Light Mode JavaScript -->
<script>
const htmlElement = document.documentElement;
const themeIcon = document.getElementById('themeIcon');
function toggleTheme() {
let currentTheme = htmlElement.getAttribute('data-theme');
if (currentTheme === 'dark') {
htmlElement.setAttribute('data-theme', 'light');
themeIcon.className = 'fa-solid fa-moon';
localStorage.setItem('theme', 'light');
} else {
htmlElement.setAttribute('data-theme', 'dark');
themeIcon.className = 'fa-solid fa-sun';
localStorage.setItem('theme', 'dark');
}
}
const savedTheme = localStorage.getItem('theme') || 'light';
htmlElement.setAttribute('data-theme', savedTheme);
if (savedTheme === 'dark') {
themeIcon.className = 'fa-solid fa-sun';
}
</script>
</body>
</html>
ការកែលម្អ៖
- Logo / Banner នៅចំកណ្តាល៖ បន្ថែម CSS
margin: 0 auto; display: block;និងtext-align: center;លើផ្នែក Header ដើម្បីឱ្យរូបភាព ឬអក្សរ Logo រត់មកនៅចំកណ្តាលទំព័រ។ - កំណត់កម្ពស់រូបភាព៖ កំណត់
max-height: 120pxដើម្បីការពារកុំឱ្យរូបភាព Logo ឬ Banner ធំពេកពេញអេក្រង់។
No comments:
Post a Comment