Designing HTML components with cohesive HTML and CSS

Check out this live demo

I'm working on creating modules that have consistent markup and CSS, allowing for flexibility in size adjustments. I want to use the same module in various sections like utilities, footer, or header.

My goal is to structure my CSS like this:

article {
    base styles
}
article.sample1 {
    custom styles
}
article.sample2 {
    custom styles
}

I can control the size of the article.login module with the following code:

section.utilities > article

or

section.test > article
  1. Choice of Element: I'm using the article element but should I consider a different one or create a custom element? Any suggestions?

  2. IE Compatibility: I haven't tested this in IE yet. Do you foresee any issues with support for inline-block, background-size, or child selectors?

  3. Is this Method Efficient: Will building modules/objects in PHP files using this approach lead to efficient development and code management?

Update

After attempting to create a custom element (module) and finding it impractical, I discovered that utilizing data attributes and CSS attribute selectors allows me to treat them as custom elements.

<article data-module="helloWorld" />

All modules can be styled by

article[data-module] { ... }

Answer №1

My perspective:

  1. Traditionally, the practice of defining custom elements has not been widely embraced. It is generally recommended to choose an element that closely aligns with your intended purpose for semantic reasons. This led to a heavy reliance on div and span elements. Personally, I believe the inclusion of the article tag provides a middle ground by allowing for highly customizable elements within the boundaries of HTML. Referencing the W3C Specification:

    The article element represents a component of a page that consists of a self-contained composition in a document, page, application, or site and that is intended to be independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content. W3C Specification

    In summary, the article tag is a suitable choice for this scenario.

  2. Dealing with IE can be challenging. You may find yourself spending significant amounts of time crafting convoluted code to accommodate newer concepts in IE, as many traditional methods do not work as expected.

  3. I believe implementing this idea is beneficial. However, it’s important to consider the number of modules you integrate. Depending on your server setup, utilizing php wrappers to contain the modules could result in increased file reading and seek times.

I trust this information proves helpful.

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

Leveraging variables within CSS

What is the most effective method to create a cross-browser compatible variable in my CSS stylesheet? I am looking to define color: #123456; as a variable as I need to utilize it in multiple places, and if I decide to modify this color, I want it to upd ...

Vertically aligning text in separate div containers

Currently, part of my dashboard page is styled using the Bulma CSS framework. One feature is a 'Widgets' feature with three large containers displaying key facts such as the number of sales, new customers, etc. The issue I'm facing is that ...

Two columns of equal height featuring three card UI elements

I'm currently working with Bootstrap 4 and I have a grid set up with 1 row containing 2 columns and 3 card elements. However, I am struggling to adjust the height of the blue card element to align with the yellow card element. I want both cards to ha ...

Unable to access hyperlinked text on WordPress sites

For a school project, I am in the process of developing a theme using WordPress to create a blog. This theme is not intended for sharing so all website design aspects are already pre-made. The issue arises when I attempt to access the blog.php file from ...

Choose dropdown menus that are pre-filled by JSON may require a manual refresh to show the content

Occasionally, I encounter an issue with a JSON file used to populate select boxes, where the items in the drop down fail to display until the page is refreshed. Despite no errors in the console or log, the loading is seamless on most occasions, leaving me ...

I am attempting to adjust the CSS code so that it does not shrink when clicked on. How can I prevent this from happening?

Here is the element I am attempting to modify. I attempted &:active { flex:7;} but upon releasing the left click button, it reverted back to its original size. I was aiming for something similar to this <h1>Gallery</h1> < ...

What is the best way to define the relative path and folder paths in HTML and CSS when working in Visual Studio 2012?

Working on a basic HTML project that includes css and javascript. Within the project folders named css, scripts, and images are used for organization. The project structure can be seen in the provided image. https://i.sstatic.net/OwCSL.jpg The issue that ...

Having difficulty getting my ASP telerik menu to function properly

After researching numerous threads on how to apply a personalized design to a telerik menu on my website, I have reached out for assistance. Even though some may not be familiar with the specifics, I am in urgent need of help with my current coding. In my ...

Using AngularJS to add an element to an array based on a specified condition

dashboardCtrl Data app.controller('dashboardCtrl', ['$scope','$rootScope', function ($scope, $rootScope) { //Color $scope.Color = [{ colorname: "Red", number: "(3)" }, { colorname: "Brown ...

Creating a dynamic dropdown menu triggered by a button click using Angular

I am a beginner in Angular (typescript) and I am facing some challenges in adding a new dropdown menu when a user clicks a button. My main struggle is creating additional attribute fields. I'm considering keeping track of the newly added dropdowns wit ...

What is the reason behind the android code being incompatible with IOS operating systems?

I'm encountering an issue where a particular code is working on Android, but not on IOS. The code in question involves using JavaScript to differentiate the items in a list within an HTML select tag. It's perplexing to me how the code can operat ...

Issue with HTML file not found in Python Tornado AngularJS application (using ui-router)

Looking at my code Folder Structure: App- |--- static | |--- css | |--- js | |--- app.js | |--- templates | | --- header.html | | --- template.html | | --- footer.html | | --- index.html |--- startup ...

Adaptable Bootstrap Button that Adjusts to Different Screen Sizes

I want this button to adjust its size according to the screen dimensions. The current code keeps the button fixed in place. See below for the code snippet. <button type="button" [className]="'btn btn-block m-0'" kendoButton ...

In HTML, the size and position of an <a> element cannot be altered or adjusted

I am having trouble with an anchor element that is contained within a div. No matter what I try, I cannot resize or move it up or down without it covering its sibling element. I have attempted using transform-translate and margin properties, but to no avai ...

"Challenges with Full-Width Dropdowns in Multi-level Mega Menus

I am currently attempting to design a multi-level mega menu that spans the full width of the screen, while keeping the content within it restricted to a maximum width of 1240px. I have managed to set the content to the maximum width, but I am facing challe ...

Leveraging Selenium Basic with Excel Version 16 to Manipulate Arrays within "div" Tags

Currently, I am extracting data through Web scraping from a Chrome web page in Excel v.16 with the help of Selenium Basic. Due to the sensitive nature of patient information, I must be cautious about disclosing too much detail. (Initially, I developed the ...

What is the proper way to pass options using jquery.timeline.js?

My implementation of jquery.timeline.js involves initializing the timeline using the script below: <script> $(function () { $("#myTimeline").Timeline({ startDatetime: "2019-02-25 00:00", rows : 5 }) }) </script&g ...

Quicker loading times for background images when creating PDFs using wkhtmltopdf

As I work on generating a 5-page PDF from my HTML file using wkhtmltopdf, everything seems to be running smoothly. However, I've encountered an issue when it comes to the time it takes to complete this task, especially when a background image is inclu ...

Utilizing either AJAX or PHP to input information into a predetermined section within a text document

I am currently in the process of developing a website that involves intricate table structures and text files acting as databases. At the moment, I have a page that displays all the available data to the user, shown below: all_data <html> <h ...

Issue with white spaces in footer content in Chrome browser

Currently in the process of developing a website and encountering a strange bug that only seems to be affecting Chrome. Despite having the latest version of Chrome, it appears to be an issue that was prevalent in older versions (v18 - v20). The problem is ...