![]() |
#1 |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 476
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,833
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; } |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
A Hairy Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 3,362
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: 476
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; Today at 05:43 PM. |
![]() |
![]() |
![]() |
#5 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,833
Karma: 8700631
Join Date: Mar 2013
Location: Rosario - Santa Fe - Argentina
Device: Kindle 4 NT
|
Quote:
|
|
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Evangelist
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 476
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; Today at 08:29 PM. |
|
![]() |
![]() |
![]() |
#7 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,833
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; Today at 10:23 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 |