Let’s continue my CSS/HTML questions regarding the “Continue reading” link on Hentairules, if you don’t mind ;)

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 2.50 out of 5)
Loading...
By Oliver (AKA the Admin) on 40 comments
in Categories: Just Talking

No hentai is shared in that post, I’m not blaming anyone not willing to read on, I’m simply asking for CSS and HTML advice ;)

Click that hentairules link, for an example. Look around, see the one thing that is always aligned left, even though the rest is either centered or right-aligned ?

So, a week ago, I was wondering why the “CONTINUE READING” links at the bottom of the posts on the index page of Hentairules weren’t centered.
I was telling I tried centering them with CSS and failed.

For reference, this “CONTINUE READING” separator is, in HTML-for-wordpress, written as <!–more–>, and its CSS class is class=”more-link”.

I got a poor workaround, manually wrap the <!–more–> tag between <p style=”text-align: center;”> </p> before saving the post. It works. Sometimes, I’ve done it in the past, not quite deliberately, but in “let’s center everything it’s simpler” moments.

But, sadly, this is a very poor workaround. That will only work for the posts in which the <!–more–> has been surrounded by the proper HTML But, hey, Hentairules has more than 9400 posts since I started the blog in 2006, and most of them contain a <!–more–> link. Must I rewrite them all ?

OK, OK, sure, I could get it done with a phpmyadmin replacement, such as:
UPDATE wp_posts SET post_content = REPLACE (
post_content,
‘<!–more–>’,
‘<p style=”text-align: center;”><!–more–></p>’);
I would first try it on a temporary clone of the database of Hentairules on a test installation, just to make sure the double quotes don’t need \escaping in that context. I think not, but, hey, better be sure!

But… no. Just… no.
Having to bulk update 9000++ posts with a database operation because I can’t get formatting done with CSS, even for someone like me, it sounds wrong.

And so we’re back to square one:
Please, boys, girls, is there any chance YOU would manage to get the centering of the “CONTINUE READING” done through CSS, in your browser inspectors and code changing developer tools ?

Please ? :)

For reference, the concerned CSS for the “CONTINUE READING” link is:
https://www.hentairules.net/wp-content/themes/canvas/custom.css
and
You can view here a non-minified version of the file.
Also, there may be interferences from the main styleshee of Hentairules, in case if specifies things that aren’t “corrected” in the custom.css above,
You can view here a non-minified version of the main style.css

A clarification, the blog theme first reads its style.css, and then its custom.css: in case something is mentioned in both style.css and custom.css, then custom.css “wins”. Personal additions of new styles also go into custom.css.

My attempts, in which I later added !important after finding they didn’t work (and it still didn’t work :D ) were:
.more-link {
    text-align: center !important;
    margin: 0 auto !important;
}        

.more-link p {
    text-align: center !important;
    margin: 0 auto !important;
}       

I tried only the “text-align: center;” or only the “margin: 0 auto“, but neither of them worked.

And the “normal” CSS specifications for this “CONTINUE READING” text, just above my attempts, are:
article.type-post a.more-link {
    -moz-appearance: none;
    background: none 0 0 repeat scroll #dd3333;
    border-color: rgba(255, 255, 255, 0);
    border-radius: 3px;
    border-style: solid;
    border-width: 1px;
    box-shadow: 0 0 0 0 #888;
    box-sizing: border-box;
    color: white !important;
    cursor: pointer;
    display: inline-block;
    font-family: inherit;
    font-size: 1em;
    font-weight: 200;
    line-height: 1.618em;
    overflow: visible;
    padding: 0.327em 1em;
    text-align: center;
    text-decoration: none;
    text-shadow: none;
    text-transform: uppercase;
    white-space: normal;
    width: auto;
    margin-top: 20px;
}

article.type-post a.more-link:hover {
    background: none 0 0 repeat scroll #881616;
    text-decoration: none;
}

Please, if YOU, you manage to make it work in CSS, I’ll be most grateful if you can share how you achieved that :)

Subscribe
Notify of
guest

40 Comments
oldest
newest most voted
Inline Feedbacks
View all comments
oldbrokenhands
oldbrokenhands
8 years ago

Just one quick question, I'm by no means a CSS or HTML guy, but what part of the page are you inserting this into?

I didn't notice an actual header or body tag, just spoiler body.

Also what is the name of the top banner?

I saw a top.png and a footer.png. Looks like both your top banner and the bottom banner are left aligned.

elbarto
elbarto
8 years ago

Try this:
.more-link {
display: block;
width: 200px;
}

For the width, you can also use width: 13em if relative size is needed

Oliver AKA The Admin
Admin
8 years ago
Reply to  elbarto

Thanks for the attempts, guys!

I just tested that one: won't work.

(tested with cache: OFF, and CDN: OFF, and browser cache: cleared)

Daedolon
8 years ago

Elbarto is almost right.

Setting the display to block with a fixed width solves part of the problem.

He just forgot to set the left and right margin so the block will always be centered in its container.

So you basically just need to add/edit the following CSS :

.more-link {

display: block;

width: 200px;

margin: 20px auto 0;

}

Tested and worked in Firefox with Firebug.

Don’t forget to remove the “margin-top:20px” since it’s already included in the new margin rule.

If you want to avoid having a fixed width, I noticed the whole content of you section is centered.

So instead of using multiple tag with the text-align:center value, it would be better to apply the rule to the whole container like this :

section.entry {

text-align:center;

}

then all image, text and link should be centered.

elbarto
elbarto
8 years ago
Reply to  Daedolon

I tried my code snippet on both FF & Chrome's developer tools. Doesn't seem to need a margin attribute (or rather, I didn't see any difference).

Also Oliver, Chrome & FF calculates box models slightly differently, so the width may need to be increased a little bit to accommodate this (200px -> 205px, 13em -> 15em, etc.)

Oliver AKA The Admin
Admin
8 years ago
Reply to  Daedolon

Thanks for the attempts, guys!

I just tested that one: won't work.

(tested with cache: OFF, and CDN: OFF, and browser cache: cleared)

Also, I would like to leave the option to have things NOT centered in the posts, you know :-/

Azathoth
Azathoth
8 years ago

Hi Oliver!, well I fixit editing not the class .more-link, but the class entry

so
.entry, .entry p {
font: 300 15px/1.5em Arial,sans-serif;
color: #E0E0E0;
// Next line were added.
text-align: center;
}
it should work, but every text in your post is now centerd, maybe not wat you need. in the other hand if you don't care have the post text centered it will work. And you also don't use all the style="text-align: center;" stuff any more

Oliver AKA The Admin
Admin
8 years ago
Reply to  Azathoth

Well, I would really like NOT having to make everything centered everywhere, keeping the option to have things not centered if I want :-/

Name
Name
8 years ago

If you don’t want to use, which would center every element in the section.

section.entry {

text-align:center;

}

you can use this to center only the link

article.type-post a.more-link {

position: relative;

left: 50%;

width: 200px:

margin-left: -100px;

}

This will position the link in the center of the section and then move 1/2 * width to the left.

If you like, you can use % instead of px values.

Name
Name
8 years ago
Reply to  Name

an other trick, which only works in modern browsers
http://www.w3schools.com/cssref/sel_last-child.asp

and your link needs to be inside the last child element, like a p-tag, then you can style it like this

section.entry :last-child {
text-align: center;
}

elbarto
elbarto
8 years ago
Reply to  Name

Agreed. The only downside is this would work without fail only if the containing the a.more-link is always the last element inside section.entry

Oliver AKA The Admin
Admin
8 years ago
Reply to  Name

Ah, I tested that one just in case,

section.entry :last-child {
text-align: center;
}

And, guess what, it didn't work O_o

Oliver AKA The Admin
Admin
8 years ago

Ooops. My bad.
Forgot to update the CSS before testing. That one works :)

But it's got that problem, that it will center practically EVERYTHING in the posts, while I sometimes want my posts' content, or parts of it, to be left-centered…

Name
Name
8 years ago

This rule uses a CSS selector, it will only work on the last element in a section.
The last element could be pretty much everything (div, p, a, span).

Currently you have something like this:

text 1
text 2
text 3
text 4
more-button <– everything inside will be centered

The rule will grab the last p-tag with the “more-button” and apply the rule to the p-tag. That works, but if you change it to this.

text 1 <– everything inside will be centered

or this

text 1
text 2
text 3
more-button
text 4 <– everything inside will be centered

I don’t think, it is what you really want.

So use the first thing I suggested. Add the rules at the end of custom.css and put !importet after the margin-left.

You will need to remove your workaround inline-styles, because those will be moved all the way to the right.

Oliver AKA The Admin
Admin
8 years ago
Reply to  Name

Ah, that one, worked a bit:

article.type-post a.more-link {
position: relative;
left: 50%;
width: 200px:
margin-left: -100px;
}

With that one, the CONTINUE reading is a bit on the right of the horizontal middle…
The "margin-left at -100 had no impact, though, I removed it and nothing happened to change the odd positioning…

Name
Name
8 years ago

The position of CSS-rules effect there usage, only the last correct rule will be used.

If margin-left had no effect then the rule is overridden by an other margin-rule, which is loaded after this one. So you can use !important to mark it not to be overridden by a normal CSS-rule.

article.type-post a.more-link {
position: relative;
left: 50%;
width: 200px:
margin-left: -100px !important;
}

The “last-child” rule is a bit tricky to use. If the conditions aren’t met, it will not work.

Oliver AKA The Admin
Admin
8 years ago
Reply to  Name

I finally got to understand those ideas, the last-child one and such. However, !important hasn't always worked as magically as expected, haha.

I finally got it to work, thanks to other comments below.

Thanks for your help! ^_^

Shaile
Shaile
8 years ago

In the custom.css file… try adding
.entry, .entry p { text-align:center !important; }

i'm not sure if that will hit all posts, but it is a pure css change within the custom.css file you can do. And it works in the Dev Tools in Chrome at least.

Oliver AKA The Admin
Admin
8 years ago
Reply to  Shaile

Yeah, that one works, thank you.

But I would prefer not to affect the entirety of posts, sometimes I have texts that are left aligned for a good reason…
(sorry to be picky ^^)

Shaile
Shaile
8 years ago

No….no need to apologize… =D

In that case then… try this in place of what I suggested before (if you haven't already figured it out)

.entry p:last-of-type { text-align:center !important; }

it's still pure css only… no html adjustment required. =)

Oliver AKA The Admin
Admin
8 years ago
Reply to  Shaile

Hm ? That one would still affect the entirety of the posts as long as it's within p, though…

Also, in case there are conflicts with the main CSS (for instance I just caught why i didn't work while em worked, there was a reset clause, same for < small > that didn't work for the same reason), I updated my post to provide a link to the site's main CSS.

Ahinigami
Ahinigami
8 years ago

Just change "display:inline-block" to "display: table;", this will solve your problem without messing around without other properties.

I tried it with 3 browsers, google chrome, firefox, and internet explorer.

Oliver AKA The Admin
Admin
8 years ago
Reply to  Ahinigami

You mean in

article.type-post a.more-link {
-moz-appearance: none;
background: none 0 0 repeat scroll #dd3333;
border-color: rgba(255, 255, 255, 0);
border-radius: 3px;
border-style: solid;
border-width: 1px;
box-shadow: 0 0 0 0 #888;
box-sizing: border-box;
color: white !important;
cursor: pointer;
display: inline-block;
font-family: inherit;
font-size: 1em;
font-weight: 200;
line-height: 1.618em;
overflow: visible;
padding: 0.327em 1em;
text-align: center;
text-decoration: none;
text-shadow: none;
text-transform: uppercase;
white-space: normal;
width: auto;
margin-top: 20px;
}

In that one, the line with display: inline-block;, I replaced it with display: table;

… but that didn't make the CONTINUE READING become centered at all…

Ahinigami
Ahinigami
8 years ago

article.type-post a.more-link {
-moz-appearance: none;
background: none 0 0 repeat scroll #dd3333;
border-color: rgba(255,255,255,0);
border-radius: 3px;
border-style: solid;
border-width: 1px;
box-shadow: 0 0 0 0 #888;
box-sizing: border-box;
color: white!important;
cursor: pointer;
display: table; /* Change to table instead of inline-block */
font-family: inherit;
font-size: 1em;
font-weight: 200;
line-height: 1.618em;
overflow: visible;
padding: 0.327em 1em;
text-align: center;
text-decoration: none;
text-shadow: none;
text-transform: uppercase;
white-space: normal;
width: auto;
margin-top: 20px;
margin: auto; /* Add this */
}

Here is the full css that I've tested again. If I'm not mistaken, your css yesterday had the "margin" property set to auto but it was no longer there today which is why changing the display property didn't work anymore

Oliver AKA The Admin
Admin
8 years ago
Reply to  Ahinigami

Ah, there's been a working answer at last, in a comment below.

Besides changing to display: inline:table, it also required (for whatever reasons there may be)
a.more-link {
display: table;
margin: 0 auto;
}

Well, now, it works, woot!

Thanks for the helping everyone ^_^

Oliver AKA The Admin
Admin
8 years ago
Reply to  Ahinigami

Ah, something that may (or most likely, may not) cause the problem, I found these were those entries in the site's CSS related to the "more" term:

.post-more {
clear: both;
padding: 0.2em 0;
font-size: 13px; }

.post-more .sep {
padding: 0 0.5em; }

.post-more a:hover, .post-meta a:hover, .post p.tags a:hover {
text-decoration: underline;
color: red; }

I'm copy-pasting it here in case it may help :)

miguel
miguel
8 years ago

in the custom css add:

p {

text-align: center;

}

That will center all “” elements, including the “continue reading”. As by a quick inspecting of the page code all elements seems to be centered that must not be a major issue.

If its a major issue, try:

.entry, .entry p {

text-align: center;

}

To center only p elements inside a entry class.

Oliver AKA The Admin
Admin
8 years ago
Reply to  miguel

.entry, .entry p {
text-align: center;
}

I tested that one, because the <!–more–> weren't between < p > in the past, and unsurprisingly, that one works, haha, thank you.

Still, I would much rather find a way to only affect the CONTINUE READING texts. Sometimes, it's better for my posts to have texts aligned left, and I *did* align left some texts on the occasion…

fred
fred
8 years ago

en regardant la strucuture de la page, ajouter la classe :
article .entry p:last-child{
text-align: center;
}

devrait régler le problème.
le lien a l'aire d'être toujours le dernier élément de l'article.

Oliver AKA The Admin
Admin
8 years ago
Reply to  fred

Même remarque qu'au-dessus, j'aimerais bien impacter seulent les textes CONTINUE READING ;)

Oddjob
Oddjob
8 years ago

Not on topic of alignment and haven't checked if someone already mentioned it, but I think the "Previous", "Next" and "(Page) Number" could be at least the same size of "Continue Reading".

The way "Continue Reading" is (bigger and aligned left, as "Previous" always used to be and still is… which itself took some time to get used to, as most blogs put "older" in right) may get people to wrongly click in it instead of "Previous". Happened with myself some times, opening a post instead of checking previous page, and was kind of annoying.

Oliver AKA The Admin
Admin
8 years ago
Reply to  Oddjob

I don't know… they're less useful, and the CONTINUE reading link is used much more often.

I can't give them the same formatting, it wouldn't even hold in one line.

Additionally, how could you confuse the positions of previous (on the left) and next (on the right) ? O_o

I mean, just above, there are a few select page numbers, 1, 2, 3…. 1354: it's clear as day, it's from left (latest) to right (older)

Shaile
Shaile
8 years ago

oh… wow… whoops… didn't know this would render < p > tags as actually html element… @_@

Oliver AKA The Admin
Admin
8 years ago
Reply to  Shaile

Yeah, it can be confusing that simple HTML *is* interpreted, haha.

I didn't really understand this last-child thingy, I imagined this would affect whole posts, but, no, on lists of posts each posts ends on the CONTINUE READING link, precisely.

So, yeah, the solution would have been working.

Still, I didn't adopt it, because I felt uneasy about targetting potentially other areas while simply fortunately having the one thing I want included in this broader targetting. What if I didn't want the last paragraph of each post center ? ^^

Fortunately the hunt is over, someone provided the working code later in the comments. At last ^_^

Thanks for the help :)

BBB
BBB
8 years ago

.more-link {text-align: center} works fine because it's centering the text in the <a>, but it won't the <a> in the .

.more-link p {text-align: center} won't work because you're specifying a "child > parent" relationship, not the correct "parent > child".

I'm surprised some of the previous suggestions didn't work. To test if any of your changes have been loaded properly, you will have to open the browser's dev tools and verify that you can see the changes. Clearing your browser's cache won't help if the server's cache hasn't updated as well.

You can try this:

Change width:auto to width:33.3%. This will make it 1/3 the width of (just a little larger than current)
Add margin-left:33.3%. This will move it to the left by 1/3 the width of

Original:
article.type-post a.more-link {

width:auto;

}

Updated:
article.type-post a.more-link {

width:33.3;
margin-left:33.3%;

}

Oliver AKA The Admin
Admin
8 years ago
Reply to  BBB

Well, thanks for the suggestions, but I ended up not trying it, when I checked the page for new comments since the last time, the first solution I tried (switching to display: block to display: inline-table, + margin:0 auto) worked.

I'm relieved, at last, it's working ^__^

BBB
BBB
8 years ago

(Note to self: don't use the "less-than" and "greater-than" symbols here)

Yorojuya
Yorojuya
8 years ago

Try adding this
a.more-link {
display: table;
margin: 0 auto;
}
and remove display: inline-block; property from the same class

Oliver AKA The Admin
Admin
8 years ago
Reply to  Yorojuya

YAHAAAAA!!

That one worked!

And, unlike every other solution so far, it
– doesn't affect other parts of the posts or blog
– doesn't rely on a fixed width of the "more" text

Well, Yorojuya, thank you VERY much, that discrepancy in display was bothering me to no end, and I'm feeling really glad, and relieved, to know it's working at last, you have my deepest gratitude :)

Yorojuya
Yorojuya
8 years ago

glad I could be of help :)