Skip to content

Commit 1c5e60e

Browse files
committed
update css
Yes, those styles can move directly into a **`PostDetail.razor.css`** file. Because your `PostDetail.razor` contains the HTML with the class `class="btn-link share-btn"`, Blazor will correctly apply the isolated styles to that button. ### Refactoring Steps 1. **Create** a file named `Pages/PostDetail.razor.css` (or wherever your page is located). 2. **Paste** the `.share-btn` styles there. 3. **Delete** them from `site.css`. ### Important Note: The "Deep" Selector Rule There is one thing to be aware of when using CSS isolation on Pages that contain child components (like your `ReaderBadge` or `MarkdownRenderer`). * **Isolated CSS** in `PostDetail.razor.css` will **only** affect HTML elements defined *inside* `PostDetail.razor`. * It will **not** affect HTML elements inside `MarkdownRenderer` unless you use the `::deep` combinator. Since your `.share-btn` is defined directly in the `PostDetail.razor` file, it works perfectly without any changes. --- ### One Small Enhancement Since you are using a standard `<button>` with a `share-btn` class, you might want to ensure the button doesn't have the default "grey box" browser styling. You can add these lines to your `PostDetail.razor.css` to keep it clean: ```css /* PostDetail.razor.css */ .share-btn { display: inline-flex; align-items: center; gap: 0.25rem; font-size: 0.875rem; color: var(--color-text-muted); /* Reset button styles if not already handled by btn-link */ background: none; border: none; padding: 0; cursor: pointer; } .share-btn:hover { color: var(--color-primary); text-decoration: underline; } .share-btn svg { margin-top: -2px; /* Fine-tune icon alignment */ } .share-btn.success { color: var(--color-success); } ``` ### Why this is better By moving these styles to the page level: 1. **Bundle Size:** Your `site.css` stays focused on global layout (colors, fonts, grids). 2. **Naming Safety:** You could have a completely different `.share-btn` on a "User Profile" page or "Image Gallery" and they would never conflict. 3. **Maintenance:** When you decide to change the share icon or color, you know exactly which file to open. Would you like me to help you create the **`sharePost`** JavaScript function in your `site.js` to actually make that button work with the native browser share menu?
1 parent 773af1a commit 1c5e60e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/MyBlog.Web/Components/Pages/PostDetail.razor.css

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
/* Share button styling */
1+
/* PostDetail.razor.css */
2+
23
.share-btn {
34
display: inline-flex;
45
align-items: center;
56
gap: 0.25rem;
67
font-size: 0.875rem;
78
color: var(--color-text-muted);
9+
/* Reset button styles if not already handled by btn-link */
10+
background: none;
11+
border: none;
12+
padding: 0;
13+
cursor: pointer;
814
}
915

1016
.share-btn:hover {
1117
color: var(--color-primary);
18+
text-decoration: underline;
1219
}
1320

1421
.share-btn svg {
15-
margin-top: -2px;
22+
margin-top: -2px; /* Fine-tune icon alignment */
1623
}
1724

1825
.share-btn.success {

0 commit comments

Comments
 (0)