DEV Community

张晨筠
张晨筠

Posted on

A CSS for Bear Blog

I found a great blog platform, and it give me some free theme -- and a global CSS editor.

So, I selected a beautiful theme and make its main color -> blue:

My Blog

/* Font */
@import url("https://fonts.googleapis.com/css2?family=Instrument+Sans:ital,wght@0,400;0,600;1,400;1,600&display=swap");

/* Settings */
:root {
  --color-dark: #1f2937; /* 深蓝色 */
  --color-light: #f4f4f4;
  --color-light-2: #fff;
  --color-primary: #3182ce; /* 主色调改为蓝色 */
  --color-border: #e0e0e0;
  --size-step-0: clamp(1rem, calc(0.96rem + 0.22vw), 1.13rem);
  --size-step-1: clamp(1.25rem, calc(1.16rem + 0.43vw), 1.5rem);
  --size-step-2: clamp(1.56rem, calc(1.41rem + 0.76vw), 2rem);
  --size-step-3: clamp(1.95rem, calc(1.71rem + 1.24vw), 2.66rem);
  --size-step-4: clamp(2.44rem, calc(2.05rem + 1.93vw), 3.55rem);
  --spacing: clamp(1rem, 2vw, 2rem);
  --radius: 1rem;
  --shadow: 0 2px 2px rgba(0, 0, 0, 0.04);
  --font-stack: "Instrument Sans", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
    "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  --code-background-color: var(--color-dark);
  --code-color: var(--color-light);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-dark: #f4f4f4;
    --color-light: #1f2937; /* 深蓝色 */
    --color-light-2: #1e1a23;
    --color-primary: #3182ce; /* 主色调改为蓝色 */
    --color-border: #25212c;
  }
}

/* HTML Styles */
body {
  background: var(--color-light);
  color: var(--color-dark);
  font-family: var(--font-stack);
  font-size: var(--size-step-0);
  line-height: 1.7;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--spacing);
  flex-wrap: wrap;
  min-height: 100vh;
  margin: 0;
  padding: var(--spacing);
}
* {
  box-sizing: border-box;
}
header {
  display: flex;
  flex-direction: column;
  gap: calc(var(--spacing) / 4);
  padding-right: 0;
  position: sticky;
  top: 0;
  max-height: 100vh;
  background-image: linear-gradient(var(--color-light), transparent);
}
main {
  flex: 1;
}
main > *:not(script, form),
main .upvote-button {
  display: block;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--spacing);
  background-color: var(--color-light-2);
  box-shadow: var(--shadow);
}
main .upvote-button {
  display: flex;
}
main > *:first-child {
  margin-top: 0;
}

content:has(.blog-posts) {
  border: none;
  padding: 0;
  background-color: transparent;
  box-shadow: none;
}
img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
h1,
h2,
h3,
h4,
h5 {
  font-weight: 600;
  line-height: 1.3;
  text-wrap: balance;
}
h1 {
  font-size: var(--size-step-4);
}
h2 {
  font-size: var(--size-step-3);
}
h3 {
  font-size: var(--size-step-2);
}
h4 {
  font-size: var(--size-step-1);
}
h5 {
  font-size: var(--size-step-0);
}
ul,
ol {
  -webkit-padding-start: var(--spacing);
  padding-inline-start: var(--spacing);
}
li {
  --flow-space: var(--spacing);
  margin-block-start: var(--flow-space, var(--spacing));
}
blockquote {
  -webkit-padding-start: var(--spacing);
  padding-inline-start: var(--spacing);
  -webkit-border-start: 0.3em solid;
  border-inline-start: 0.3em solid;
  font-style: italic;
  font-size: var(--size-step-1);
}

a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 600;
}

a:hover {
  text-decoration: underline;
  text-decoration-color: var(--color-border);
}
/* Utilities */
content > div > * {
  -webkit-margin-before: var(--flow-space, var(--spacing));
  margin-block-start: var(--flow-space, var(--spacing));
}
content > *:first-child {
  -webkit-margin-before: 0;
  margin-block-start: 0;
}
/* Flow and rythm */
:is(h1, h2, h3, h4, h5, blockquote) {
  --flow-space: calc(var(--spacing) * 2);
  margin-block-end: calc(var(--spacing) / 2);
}
:is(h1, h2, h3, h4, h5) + * {
  --flow-space: calc(var(--spacing) / 3);
}
:is(h1, h2, h3, h4, h5) + :where(h2, h3, h4, h5) {
  --flow-space: calc(var(--spacing) * 2);
}

/* Line lengths */
blockquote {
  max-width: 50ch;
}
h1 {
  max-width: 24ch;
}
h2,
h3 {
  max-width: 32ch;
}
/* Bear Content */
.title {
  padding: var(--spacing);
  display: flex;
  flex-direction: column;
  word-break: break-word;
  border-radius: var(--radius);
  border-top-left-radius: 0;
  text-decoration: none;
  color: var(--color-light-2);
  background-color: var(--color-primary);
  box-shadow: var(--shadow);
  font-weight: 400;
  max-width: 340px;
}
.title::before {
  content: "00";
  font-size: 60%;
}
.title h1 {
  font-size: var(--size-step-2);
  margin: 0;
}
.title:hover {
  text-decoration: none;
}
nav p {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--spacing) / 4);
  counter-reset: nav-counter;
}

nav p a {
  display: flex;
  word-break: break-all;
  text-decoration: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  gap: calc(var(--spacing) / 4);
  padding: calc(var(--spacing) / 4) var(--spacing);
  background-color: var(--color-light-2);
  color: var(--color-dark);
  font-weight: 600;
  box-shadow: var(--shadow);
  transition: color 0.2s ease-in-out;
}
nav p a::before {
  counter-increment: nav-counter;
  content: "0" counter(nav-counter);
  font-size: 60%;
  font-weight: 400;
  color: var(--color-primary);
}
nav p a:hover {
  text-decoration: none;
  color: var(--color-primary);
}

.highlight,
.code {
  padding: 1px var(--spacing);
  background-color: var(--code-background-color);
  color: var(--code-color);
  border-radius: var(--radius);
  overflow-x: auto;
  line-height: 1.3;
  box-shadow: var(--shadow);
}
table {
  width: 100%;
}
th {
  text-align: left;
}

footer {
  padding: calc(var(--spacing) / 1.1) 0 !important;
  font-size: 60%;
  font-weight: 400;
  font-style: normal;
  color: var(--color-primary);
  text-transform: uppercase;
}

.blog-posts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: calc(var(--spacing) / 4);
}

.blog-posts li {
  display: flex;
  flex-direction: column;
  word-break: word-break;
  text-decoration: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: calc(var(--spacing) / 1.5) var(--spacing);
  background-color: var(--color-light-2);
  color: var(--color-dark);
  font-weight: 600;
  box-shadow: var(--shadow);
  margin: 0;
  max-width: calc(50% - calc(var(--spacing) / 2));
}
.blog-posts li time {
  font-size: 60%;
  font-weight: 400;
  font-style: normal;
  color: var(--color-primary);
}
.blog-posts li a {
  text-decoration: none;
  color: var(--color-dark);
  line-height: 1.3;
  transition: color 0.2s ease-in-out;
}
.blog-posts li a:hover {
  color: var(--color-primary);
}

@media screen and (max-width: 768px) {
  body {
    flex-direction: column;
  }
  .blog-posts {
    flex-direction: column;
  }
}
@media screen and (min-width: 768px) {
  body {
    flex-direction: row;
    gap: calc(var(--spacing) / 4);
  }
  header {
    max-width: 25ch;
    top: var(--spacing);
  }
  .title {
    gap: var(--spacing);
  }
  nav p a {
    width: 100%;
    gap: calc(var(--spacing) / 1.5);
    flex-direction: column;
    padding: calc(var(--spacing) / 1.5) var(--spacing);
  }
  main {
    max-width: 56ch;
    min-width: 38ch;
    transform: translateY(-3px);
  }
  .blog-posts li {
    gap: calc(var(--spacing) / 1.5);
  }
  .blog-posts li a {
    font-size: var(--size-step-1);
  }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)