Let’s continue my CSS/HTML questions regarding the “Continue reading” link on Hentairules, if you don’t mind ;)
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 ) 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
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.
Try this:
.more-link {
display: block;
width: 200px;
}
For the width, you can also use width: 13em if relative size is needed
Thanks for the attempts, guys!
I just tested that one: won't work.
(tested with cache: OFF, and CDN: OFF, and browser cache: cleared)
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.
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.)
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 :-/
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
Well, I would really like NOT having to make everything centered everywhere, keeping the option to have things not centered if I want :-/
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.
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;
}
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
Ah, I tested that one just in case,
section.entry :last-child {
text-align: center;
}
And, guess what, it didn't work O_o
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…
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.
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…
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.
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! ^_^
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.
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 ^^)
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. =)
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.
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.
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…
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
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 ^_^
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
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.
.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…
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.
Même remarque qu'au-dessus, j'aimerais bien impacter seulent les textes CONTINUE READING
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.
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)
oh… wow… whoops… didn't know this would render < p > tags as actually html element… @_@
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
.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%;
…
}
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 ^__^
(Note to self: don't use the "less-than" and "greater-than" symbols here)
Try adding this
a.more-link {
display: table;
margin: 0 auto;
}
and remove display: inline-block; property from the same class
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
glad I could be of help