![]() |
#1 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 478
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Inline-block and float interaction
I am trying to center some left-aligned text with a floating image on the left. Unfortunately, it seems that the width of the container is defined as the width of the text BEFORE the floating image is applied, and as a result, the text automatically breaks before the last word. Now, I can get around this by using "white-space: nowrap", but doing so invites the potential for future issues.
STYLING: Code:
.center { text-align: center; margin-left: -2.2em; } .ib { font-size: 0.9em; margin-top: 5em; line-height: 1em; display: inline-block; text-align: left; } .floatimg { float: left; height: 1.75em; clear: right; line-height: 1.15em; margin-top: 0.15em; margin-bottom: -0.25em; margin-right: 0.3em; } Code:
<div class="center"> <p class="ib"><img alt="" class="floatimg" src="../Images/00.jpg" /><b>LOREM</b><br /> IPSUM DOLOR SIT AMET, CONSEC</p> </div> But what I'm getting is: Any ideas? |
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,834
Karma: 8700631
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
What you need to do is employ two divs, or one <div> and a <p>: the first div with the property "text-align: center"; the second div (or p) with the properties "display: inline-block" and "text-align: left". Something like:
Code:
<div class="centerLeft"> <p class="inlineLeft">LOREM<br/>IPSUM DOLOR SIT AMET, CONSEC</p> </div> Code:
.centerLeft { text-align: center; } .inlineLeft { display: inline-block; text-align: left; } Code:
.centerLeft::before { content: "©"; font-size: 2.4em; /* This size has to be linked with the line-height */ } Code:
.centerLeft { text-align: center; } .inlineLeft { display: inline-block; font-weight: bold; text-align: left; line-height: 1.5em; } .centerLeft::before { content: "©"; /* here, instead of the symbol, you need to write the url of your image */ font-size: 3em; } |
![]() |
![]() |
![]() |
#3 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,363
Karma: 20212733
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
You could also try this:
Code:
CSS:
.pub {clear:both; margin:2em auto; width:50vw} /* or 50% */
.pub img {float:left; width:2em;
padding:0 .5em 0 0; vertical-align: text-top;}
.pub div {font-weight:bold; margin-left:2.5em;
text-indent:0; text-align:left;
font-variant:small-caps}
.pub span {display:block; font-weight:normal}
HTML:
<div class="pub">
<img alt="" src="../Images/d20.svg"/>
<div>Lorem <span>ipsum dolor sit amet, consect</span></div>
</div>
|
![]() |
![]() |
![]() |
#4 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 478
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Thanks, guys.
couple of clarifying questions: @RbnJrg: So this looks basically like what I had, except the trick is using the "before" pseudo-element instead of a float. And because I'm completely ignorant of pseudo-elements, I'm not too angry at myself for missing this solution. I guess I'm going to have to read up on pseudoelements, now! Unfortunately, in the continuing spirit of that ignorance, I can't for the life of me figure out how to swap the content symbol for an image... All I get is either nothing or the text of the filepath! What am I doing wrong? EDIT1: P.S. — oh man... these pseudo-elements are really going be the end of me... So much potential for OCD formatting tweaks... PPS: Nevermind, i finally got it! content: url(filepath)... Unfortunately, now I can't figure out how to define the image height.... The pseudo element image doesn't seem to respond to height values... EDIT2: Okay, so this is what I got after some digging: Code:
.centerLeft::before { background-image: url(../Images/00.jpg); background-size: 2em auto; display: inline-block; width: 2em; height: 2em; content:""; } @Turtle91: When I first reproduced the code, this is what I got: With a little poking, I figured out that it was the container width that was causing the 2nd line to break, which i changed to 60%. However, no matter how you slice it, the text isn't actually automatically centering in the page. So for example, if i expand the window (keeping your original 50vw) you'll see: Is having to set the viewport width relative to the physical width of the viewing window just an unavoidable feature of this solution, or is there a way to make it automatically center for any length of text? Last edited by ElMiko; Yesterday at 05:43 PM. |
![]() |
![]() |
![]() |
#5 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,834
Karma: 8700631
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
|
|
![]() |
![]() |
![]() |
#6 | |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 478
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Quote:
For over a decade, I've been reading threads on this forum in which ADE is raked over the coals for its idiosyncratic rendering. You would think they would have listened to the community, and made some adjustments. But I guess not. Makes me think of another tech company that starts with an A, uses a fruit logo, and ends in "pple"... EDIT: looks like pseudo-elements are only sporadically supported by epub2... boo. Last edited by ElMiko; Yesterday at 08:29 PM. |
|
![]() |
![]() |
![]() |
#7 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,834
Karma: 8700631
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
Code:
<div class="bigWrapper"> <div class="wrapper"> <p class="col1"><img alt="" src="../Images/your_image.png"/>LOREM<br/>IPSUM DOLOR SIT AMET, CONSEC</p> </div> </div> Code:
.bigWrapper { text-align: center; } .wrapper { display: inline-block; } .col1 { text-align: left; } .col1 img { display: block; float: left; width: 3em; /* This must be changed according to your image */ height: 3em; /* This must be changed according to your image */ margin: 0 5px 0 0; } Last edited by RbnJrg; Yesterday at 10:23 PM. |
|
![]() |
![]() |
![]() |
#8 | |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,363
Karma: 20212733
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
|
Quote:
Try adding a border (border:1px solid red; or green) to each of the divs as you play with the widths to help visualize what it is doing. Your other option is to use a flex box (if ePub3), or a table (ugh), or just center each of the parts...it doesn't have to be exactly like the print version. Last edited by Turtle91; Today at 12:21 AM. |
|
![]() |
![]() |
![]() |
#9 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 478
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
|
![]() |
![]() |
![]() |
#10 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 80,009
Karma: 147977995
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Don't use pseudo elements. Use a proper class and span(s) and it will work in older ADE/RMSDK as well as other programs. If this is going to be an eBooks for sale, you have to do what's most compatible vs what's easiest.
|
![]() |
![]() |
![]() |
#11 | |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 478
Karma: 65460
Join Date: Jun 2011
Device: Kindle
|
Quote:
I believe that this is because the width of the container is defined by the width of the inline-block text (without the floating element). When the floating element is "added" the last word of text extends beyond the previously "established" container width, and causes the line to break. What is kind of confusing to me is WHY the text component is what determines the width of the <p> element rather than, you know, the ACTUAL contencts of the <p> element (including the image)... This isn't for sale (I wouldn't feel comfortable outsourcing book design questions as aggressively as I do here, if I was profiting on it... although I suppose it could still be for sale without MY part in it being compensated). And, taking @Turtle91's statement more seriously, the truth is I know that reflowable text is simply not the same as fixed layout formatting. This is more of an intellectual exercise about understanding the limits of html, since I'm entire self/MR-taught on the subject, and often I'm merely intuiting html rules (incorrectly) rather than fundamentally understanding them. Last edited by ElMiko; Today at 10:19 AM. |
|
![]() |
![]() |
![]() |
#12 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,887
Karma: 6120478
Join Date: Nov 2009
Device: many
|
Instead of "what is easiest", don't you mean, "what is best"?
Or maybe, "what it should be" if people would just throw out their old, obsolete, broken, out of date, epub2 only e-readers (and all ADE 2/3 devices)". ![]() |
![]() |
![]() |
![]() |
#13 |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 80,009
Karma: 147977995
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
That would mean everyone with a Kobo Reader would have to get rid of it. That's never going to happen.
|
![]() |
![]() |
![]() |
#14 |
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 8,887
Karma: 6120478
Join Date: Nov 2009
Device: many
|
I'd be happy if they just threw out all the epub2 only e-readers!
![]() |
![]() |
![]() |
![]() |
#15 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,834
Karma: 8700631
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
Code:
.bigWrapper { text-align: center; } .wrapper { display: inline-block; } .col1 { display: inline; text-align: left; } .col1 img { display: block; float: left; width: 2.5em; height: 2.5em; margin: 0 5px 0 0; } .ib { display: inline-block; } Code:
<div class="bigWrapper"> <div class="wrapper"> <p class="col1"><img alt="" src="../Images/diamant.png"/><span class="ib">LOREM<br/>IPSUM DOLOR SIT AMET, CONSEC</span></p> </div> </div> Centered block, text aligned to left, no breaks. Last edited by RbnJrg; Today at 12:45 PM. |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Inline-block | eggheadbooks1 | Sigil | 3 | 10-31-2016 03:07 AM |
The operator >> is undefined for the argument type(s) float, float | twobob | Kindle Developer's Corner | 10 | 09-05-2012 12:50 PM |
Creating epub with inline block problem | Gerlyn | ePub | 5 | 12-22-2011 01:59 PM |
Interaction | umarramzan47 | Introduce Yourself | 2 | 12-11-2011 05:29 PM |
Does mobi support display: inline-block; | DeniseL | Kindle Formats | 2 | 09-30-2011 07:33 PM |