CSS-koderna till din kommentarfunktion
Postad: 20 februari 2010 | Uppdaterad · Wordpress | 2 Comments
Lästid: 4 minuter
Denna post innehåller kod-snippar som du kan använda. Det är alltid bra att ta en backup av din stilmall och funktionsfil innan.
CSS-koderna har ändrats från 2010 när detta inlägg skrevs första gången till hur de ser ut i WordPress senaste tema Twenty Twenty One.
Jag vet inte om de äldre koderna längre fungerar, jag har sett att vissa använder dem, dock kan man få lägga till några selektorer och element för att få dem helt funktionella. Idag är det dock nedanstående css-koder som används i WordPress standardtema Twenty Twenty One.
Jag listar dem för enkelhetens skull. Om man vill styla kommentardelen är det mer överskådligt så.
/**
* Comments Wrapper
*/
.comments-area > * {
margin-top: var(--global--spacing-vertical);
margin-bottom: var(--global--spacing-vertical);
}
.comments-area > *:first-child {
margin-top: 0;
}
.comments-area > *:last-child {
margin-bottom: 0;
}
.comments-area.show-avatars .avatar {
border-radius: 50%;
position: absolute;
top: 10px;
}
.comments-area.show-avatars .fn {
display: inline-block;
padding-left: 85px;
}
.comments-area.show-avatars .comment-metadata {
padding: 8px 0 9px 85px;
}
/**
* Comment Title
*/
.comments-title,
.comment-reply-title {
font-size: var(--heading--font-size-h2);
letter-spacing: var(--heading--letter-spacing-h2);
}
.comment-reply-title {
display: flex;
justify-content: space-between;
}
.comment-reply-title small a {
font-family: var(--global--font-secondary);
font-size: var(--global--font-size-xs);
font-style: normal;
font-weight: normal;
letter-spacing: normal;
}
/* Nested comment reply title*/
.comment .comment-respond .comment-reply-title {
font-size: var(--global--font-size-lg);
}
/**
* Comment Lists
*/
.comment-list {
padding-left: 0;
list-style: none;
}
.comment-list > li {
margin-top: var(--global--spacing-vertical);
margin-bottom: var(--global--spacing-vertical);
}
.comment-list .children {
list-style: none;
padding-left: 0;
}
.comment-list .children > li {
margin-top: var(--global--spacing-vertical);
margin-bottom: var(--global--spacing-vertical);
}
@media only screen and (min-width: 482px) {
.comment-list .depth-2,
.comment-list .depth-3 {
padding-left: calc(4 * var(--global--spacing-horizontal));
}
}
/**
* Comment Meta
*/
.comment-meta .comment-author {
line-height: var(--global--line-height-heading);
margin-bottom: calc(0.25 * var(--global--spacing-unit));
}
@media only screen and (min-width: 482px) {
.comment-meta .comment-author {
margin-bottom: 0;
padding-right: 0;
}
}
.comment-meta .comment-author .fn {
font-family: var(--global--font-secondary);
font-weight: normal;
font-size: var(--global--font-size-lg);
hyphens: auto;
word-wrap: break-word;
word-break: break-word;
}
.comment-meta .comment-metadata {
color: var(--global--color-primary);
font-size: var(--global--font-size-xs);
padding: 8px 0 9px 0;
}
.comment-meta .comment-metadata .edit-link {
margin-left: var(--global--spacing-horizontal);
}
@media only screen and (min-width: 482px) {
.comment-meta {
margin-right: inherit;
}
.comment-meta .comment-author {
max-width: inherit;
}
}
.reply {
font-size: var(--global--font-size-sm);
line-height: var(--global--line-height-heading);
}
.bypostauthor {
display: block;
}
.says {
display: none;
}
.pingback .url,
.trackback .url {
font-family: var(--global--font-primary);
}
.comment-body {
position: relative;
margin-bottom: calc(1.7 * var(--global--spacing-vertical));
}
.comment-body > * {
margin-top: var(--global--spacing-vertical);
margin-bottom: var(--global--spacing-vertical);
}
.comment-body .reply {
margin: 0;
}
.comment-content {
word-wrap: break-word;
}
.pingback .comment-body,
.trackback .comment-body {
margin-top: var(--global--spacing-vertical);
margin-bottom: var(--global--spacing-vertical);
}
.comment-respond {
margin-top: var(--global--spacing-vertical);
}
.comment-respond > * {
margin-top: var(--global--spacing-unit);
margin-bottom: var(--global--spacing-unit);
}
.comment-respond > *:first-child {
margin-top: 0;
}
.comment-respond > *:last-child {
margin-bottom: 0;
}
.comment-respond > *:last-child.comment-form {
margin-bottom: var(--global--spacing-vertical);
}
.comment-author {
padding-top: 3px;
}
.comment-author .url {
color: currentColor;
}
.comment-form {
display: flex;
flex-wrap: wrap;
}
.comment-form > * {
flex-basis: 100%;
}
.comment-form .comment-notes {
font-size: var(--global--font-size-sm);
}
.comment-form .comment-form-url,
.comment-form .comment-form-comment {
width: 100%;
}
.comment-form .comment-form-author,
.comment-form .comment-form-email {
flex-basis: 0;
flex-grow: 1;
}
@media only screen and (max-width: 481px) {
.comment-form .comment-form-author,
.comment-form .comment-form-email {
flex-basis: 100%;
}
}
.comment-form .comment-form-cookies-consent > label,
.comment-form .comment-notes {
font-size: var(--global--font-size-xs);
font-weight: normal;
}
.comment-form > p {
margin-bottom: var(--global--spacing-unit);
}
.comment-form > p:first-of-type {
margin-top: 0;
}
.comment-form > p:last-of-type {
margin-bottom: 0;
}
.comment-form > p label,
.comment-form > p input [type=email],
.comment-form > p input[type=text],
.comment-form > p input[type=url],
.comment-form > p textarea {
display: block;
font-size: var(--global--font-size-sm);
margin-bottom: calc(.5 * var(--global--spacing-unit));
width: 100%;
font-weight: var(--form--label-weight);
}
.comment-form > p.comment-form-cookies-consent {
display: flex;
}
@media only screen and (min-width: 482px) {
.comment-form > p.comment-form-author {
margin-right: calc(1.5 * var(--global--spacing-horizontal));
}
.comment-form > p.comment-notes,
.comment-form > p.logged-in-as {
display: block;
}
}
Äldre kommentarkoder
ol.commentlist {}
ol.commentlist li {}
ol.commentlist li.alt {}
ol.commentlist li.bypostauthor {}
ol.commentlist li.byuser {}
ol.commentlist li.comment-author-admin {}
ol.commentlist li.comment {}
ol.commentlist li.comment div.comment-author {}
ol.commentlist li.comment div.vcard {}
ol.commentlist li.comment div.vcard cite.fn {}
ol.commentlist li.comment div.vcard cite.fn a.url {}
ol.commentlist li.comment div.vcard img.avatar {}
ol.commentlist li.comment div.vcard img.avatar-32 {}
ol.commentlist li.comment div.vcard img.photo {}
ol.commentlist li.comment div.vcard span.says {}
ol.commentlist li.comment div.commentmetadata {}
ol.commentlist li.comment div.comment-meta {}
ol.commentlist li.comment div.comment-meta a {}
ol.commentlist li.comment * {} - (p, em, strong, blockquote, ul, ol, etc.)
ol.commentlist li.comment div.reply {}
ol.commentlist li.comment div.reply a {}
ol.commentlist li.comment ul.children {}
ol.commentlist li.comment ul.children li {}
ol.commentlist li.comment ul.children li.alt {}
ol.commentlist li.comment ul.children li.bypostauthor {}
ol.commentlist li.comment ul.children li.byuser {}
ol.commentlist li.comment ul.children li.comment {}
ol.commentlist li.comment ul.children li.comment-author-admin {}
ol.commentlist li.comment ul.children li.depth-2 {}
ol.commentlist li.comment ul.children li.depth-3 {}
ol.commentlist li.comment ul.children li.depth-4 {}
ol.commentlist li.comment ul.children li.depth-5 {}
ol.commentlist li.comment ul.children li.odd {}
ol.commentlist li.even {}
ol.commentlist li.odd {}
ol.commentlist li.parent {}
ol.commentlist li.pingback {}
ol.commentlist li.pingback div.comment-author {}
ol.commentlist li.pingback div.vcard {}
ol.commentlist li.pingback div.vcard cite.fn {}
ol.commentlist li.pingback div.vcard cite.fn a.url {}
ol.commentlist li.pingback div.vcard span.says {}
ol.commentlist li.pingback div.commentmetadata {}
ol.commentlist li.pingback div.comment-meta {}
ol.commentlist li.pingback div.comment-meta a {}
ol.commentlist li.pingback * {} - (p, em, strong, blockquote, ul, ol, etc.)
ol.commentlist li.pingback div.reply {}
ol.commentlist li.pingback div.reply a {}
ol.commentlist li.pingback ul.children {}
ol.commentlist li.pingback ul.children li {}
ol.commentlist li.pingback ul.children li.alt {}
ol.commentlist li.pingback ul.children li.bypostauthor {}
ol.commentlist li.pingback ul.children li.byuser {}
ol.commentlist li.pingback ul.children li.comment {}
ol.commentlist li.pingback ul.children li.comment-author-admin {}
ol.commentlist li.pingback ul.children li.depth-2 {}
ol.commentlist li.pingback ul.children li.depth-3 {}
ol.commentlist li.pingback ul.children li.depth-4 {}
ol.commentlist li.pingback ul.children li.depth-5 {}
ol.commentlist li.pingback ul.children li.odd {}
ol.commentlist li.thread-alt {}
ol.commentlist li.thread-even {}
ol.commentlist li.thread-odd {}
Framöver så kommer jag att lägga upp förslag på hur man kan styla kommentarerna och vilka koder som berörs.