What is the process of replacing a regular HTML tag with a custom one?

Currently, I am developing a website using Hugo and Tailwind CSS while learning along the way. One aspect that remains unclear to me after going through both Hugo and Tailwind documentation is how to override standard tags.

For instance, let's take the h1 tag. What if I want to apply classes like .text-bold and .text-xl (which are Tailwind classes) to it? How should I proceed?

  • Should I use SCSS to @extend these classes in the following manner:
h1 {
    @extend .text-xl, .font-bold ;
}

However, this approach does not seem to work as the classes are not recognized:

Error: Error building site: TOCSS: failed to transform "styleScssSource.scss" (text/x-scss): SCSS processing failed: file "stdin", line 2, col 23: The target selector was not found.
Use "@extend .font-bold !optional" to avoid this error.
  • Is there a Hugo feature or mechanism that can dynamically replace <h1> with

    <h1 class="text-xl font-bold">
    ? (I am uncertain if such functionality exists)

  • Or perhaps there is another method to achieve this?

Answer №1

One way to achieve this styling in Tailwind CSS is by using the @apply directive.

h2 {
  @apply font-extrabold text-3xl my-5;
}

Answer №2

In Hugo, one way to accomplish this is by utilizing partials.

To achieve this, you must generate a file in the directory layouts/partials (such as layouts/partials/tag.html) with content representing what you wish to ultimately display in the HTML.

<a href="/tags/{{ . }}" class="bg-gray-300 text-sm rounded-full p-1 px-2">{{ . }}</a>

To incorporate this, you would use

{{ partial "tag.html" . }}
within your code.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Trouble with CSS sprites displaying text alongside images

My current CSS code is set up to display images using CSS image sprites as background images. The images are displayed based on the file extension, however, the href/link text is not appearing in line and is splitting into two lines. a[href$='.pdf& ...

What is the reason for requiring the addition of "repeat" to ensure that it appears on the

Check out my website Take a look at my custom CSS dot { background:url("images/non_selected.png") repeat scroll 22px 22px transparent; height:22px; width:22px; } After making this change url("images/non_selected.png") norepeat scroll 22px 22px tran ...

Can we limit the number of items to just two per row in a grid with two columns?

I'm currently facing issues with aligning items within a two-column grid. When looking at this image, you'll notice that the alignment is off. Specifically, 'Example 3' does not align properly with 'Example 4'. This seems to b ...

Positioning Images in Tables with Absolute CSS Styling

I need to alternate between two sets of images using JavaScript. To achieve this, I have to use CSS to set the position of each image to absolute so that each new image replaces the old one as it cycles through. My goal is to arrange the image sets in an ...

When the navbar is expanded, a right-aligned image is visible; however, it becomes invisible when the

My website has a navigation bar with two logos - one in the left corner (the coat of arms) and one in the right corner (the scout lily), along with text links in between. The coat of arms uses the "navbar-brand" class. To see how it looks, click here: htt ...

stopping the collapsible animation of bootstrap before the medium breakpoint

I recently developed a website using Bootstrap. On my site, there is a navigation bar with menu options including 'About,' 'My Projects,' and 'Contact Me' that are hidden behind an expandable menu when the page width is less t ...

All you need to know about fundamental HTML attributes

I've been struggling to resize images on my webpage. No matter how many times I change the attributes in the image tag, the image always shows up at its original size. For example, I tried this: <img src="url" alt="some text" style="width:40px;he ...

What is the best way to conduct automated tests on CSS rendering across various browsers, including Safari Mobile and the Android Browser?

Is there a way to programmatically and automatically test how CSS is rendered in various browsers, similar to how Selenium tests HTML and Javascript across different browsers? It would be great to integrate this with a BDD framework. ...

Repair top navigation bar in Bootstrap

Is it feasible to make that bar always visible while scrolling? I am looking to keep the navigation and the top bar (the one with the logo) fixed in place during scrolling. Here is the HTML code snippet for the logo bar: <!--*-*-*-*-*-*-*-*-*- Start ...

Guide to effortlessly convert SCSS to CSS using an automatic vendor prefixer

Is there a tool that can convert SCSS to CSS while automatically adding vendor prefixes? I've tried using node-sass with npm, which worked well, but it doesn't add prefixes like box-sing: border-box; or display: flex; properties. Note: I also tr ...

What steps should be taken to convert the field into a search icon?

Is it possible to change the field to an icon for mobile devices? See the example below: https://i.sstatic.net/UNZG8.png <html> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" ...

Positioning an image beneath the navigation bar in Bootstrap and CSS without it getting covered by text

I am having difficulty positioning an image below the navbar without it overlapping with the text in the navbar. No matter what I try in my code, the image remains attached to the bottom of the navbar and won't move to a separate row below it. I hav ...

What is the process for including CSS in the .ashx.cs code-behind file in ASP.NET?

How can I insert a css class in the .ashx file while the .aspx UI page displays it as a string? What is the method to include css in the code behind of the .ashx page? I would like the text "Cook" to be displayed in red. Problem: https://i.sstatic.net ...

What is the best way to transform Adobe XD designs into HTML and CSS with Vue.js?

I am looking to create a single page application with vue.js and came across this helpful reference at . A colleague has created a prototype using Adobe XD, and now my task is to transform it into HTML/CSS while making it functional and connecting it to an ...

Is there a way to display a secondary header once the page is scrolled down 60 pixels?

.nav-header2{ background: purple; display: flex; justify-content: center; align-items: center; } .header2-container{ width: 68vw; height: 60px; padding: 0 2vh; border: 1px solid red; ...

Ways to distinguish between popovers using identifiers or classes

I'm encountering an issue where I have two popovers, each containing HTML content. Below is the code snippet: <button class="count" data-toggle="popover">+click me</button> <div class="popover_content_wrapper" style="display: none"&g ...

Adjust the scroll bar to move in the reverse direction

I'm trying to modify the behavior of an overlay div that moves when scrolling. Currently, it works as expected, but I want the scroll bar to move in the opposite direction. For example, when I scroll the content to the right, I want the scroll bar to ...

"Switching Bootstrap themes with the click of a link - a step-by-step

Is there a way to switch between bootstrap themes by clicking on a link with the theme name? Here is the HTML code snippet: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" c ...

The CSS styles for a:link, a:active, and a:visited do not seem to work with

My page contains the following CSS rule: a:link,a:active,a:visited{text-decoration:none;} I have encountered an issue where this rule is not working as expected. To apply the rule within a div with the id="test", I had to modify the rule like this: #tes ...

Excessive letter spacing in font-face causing display issues on Apple devices such as iPhone and iPad

Recently, I designed a website using some unique fonts that aren't supported on all devices. To ensure compatibility across various platforms, I converted the fonts to all major file formats, including SVG for iPhones and iPads. Surprisingly, this sol ...