diff --git a/src/browser/tests/element/styles.html b/src/browser/tests/element/styles.html
index 05dfa34f0..42250d168 100644
--- a/src/browser/tests/element/styles.html
+++ b/src/browser/tests/element/styles.html
@@ -198,3 +198,22 @@
testing.expectEqual('1', divStyle.opacity);
}
+
+
diff --git a/src/browser/webapi/css/CSSStyleDeclaration.zig b/src/browser/webapi/css/CSSStyleDeclaration.zig
index f1c915506..a106731fd 100644
--- a/src/browser/webapi/css/CSSStyleDeclaration.zig
+++ b/src/browser/webapi/css/CSSStyleDeclaration.zig
@@ -96,6 +96,9 @@ pub fn getPropertyValue(self: *const CSSStyleDeclaration, property_name: []const
const prop = self.findProperty(wrapped) orelse {
// Only return default values for computed styles
if (self._is_computed) {
+ if (self._element) |element| {
+ if (findInlineValue(element, normalized, frame)) |value| return value;
+ }
return getDefaultPropertyValue(self, wrapped);
}
return "";
@@ -236,6 +239,19 @@ pub fn findProperty(self: *const CSSStyleDeclaration, name: String) ?*Property {
return null;
}
+fn findInlineValue(element: *const Element, normalized_name: []const u8, frame: *Frame) ?[]const u8 {
+ const attr_value = element.getAttributeSafe(comptime .wrap("style")) orelse return null;
+ var it = CssParser.parseDeclarationsList(attr_value);
+ var result: ?[]const u8 = null;
+ while (it.next()) |declaration| {
+ if (std.ascii.eqlIgnoreCase(declaration.name, normalized_name)) {
+ // Keep the last matching declaration, matching CSS declaration order.
+ result = normalizePropertyValue(frame.call_arena, normalized_name, declaration.value) catch declaration.value;
+ }
+ }
+ return result;
+}
+
fn normalizePropertyName(name: []const u8, buf: []u8) []const u8 {
if (name.len > buf.len) {
log.info(.dom, "css.long.name", .{ .name = name });