Set max width for each line or insert a line break in a section of text in CSS - css

I have a h2 on a slider being populated from a Wordpress post title. Part of that title is a trademark, so I want that to be all on one line, with Welcome to on the line above.
Currently I have...
Welcome to The Happy Foundation
I want...
Welcome to
The Happy Foundation
Using max-width in css I can achieve...
Welcome to The
Happy Foundation
or
Welcome to
The Happy
Foundation
Is there a way to set a max-width for each line, or otherwise get a line break after Welcome to using css?
I have tried a few tricks out there like making the text transparent and adding it back in with content. But this creates all sorts of issues with alignment and also resizing on mobile browser. I don't want to over think it.
Edit: As mentioned above, the text on the slider originates from a Wordpress post title. I can't edit the original text/html markup without changing the post title. Even if I did I can't add selectors.
Edit 2: Adding a (With Option+Shift+Space on OSX) worked but threw out the alignment of my text-align center. I need the text to be centered. Or it just looks skewed anyway and is no good to anyone.

Did you try with a <br/> after Welcome to ?

You can use unbreakable spaces inside The Happy Foundation: http://jsfiddle.net/nusa3y03/
Edit: you don't even have to know max-width if you add an unbreakable space between Welcome and to: http://jsfiddle.net/nusa3y03/1/

Yes it is possible using the max-width property
h2{max-width:236px; color:red}
<h2 id="p1">Welcome to The Happy Foundation</h2>

CSS has the ability to break lines based on the width of the containing element - without wrapping the text you want to treat differently within a different element, such as a span tag, it's hard to specify how those sections of your content should be treated.
The easiest solution IMO for your case is to manually add a line break to the title. However, if you'd like to try using non-breaking spaces [http://blog.liveeditorcms.com/html-tip-keeping-some-words-together/][1] to keep the title of the foundation together, try giving this a shot:
`Welcome to The Happy Foundation`
This will treat your foundation's title as if it's one word, preventing it from being broken up onto different lines. This might cause issues in the future depending on how you display on smaller screens.

Related

Incorrect resizing on h1 and navbar wordpress

I've been fighting with a small(big) issue on a wordpress site all morning. I've tried adjusting margins, adding and adjusting an overflow attribute, adding media queries, and the lot. But it seems I can't get these elements to play nice with a minimized window.
As you can see, I just need the h1 text (Quiescent imaging...) to always stay visible and in place and I also need the text in the sidebar to stay together.
These issues also only occur with a minimized window.
Any tips are highly appreciated. Thank you!
So it turns out this is a lot more simple than needing to edit any code. The h1 attribute, rather, the title bar I was trying to edit can be modified toward the bottom of the page editor which we are using (fusion builder).
I usually overlook these simple solutions, but I'll accept the embarrassment if this helps someone out one day!
More info:
The Page Title Bar is not an Element; rather it is controlled via the Theme Options and the Fusion Page Options. This article will look in depth at the options that are available for this often overlooked tool.
https://theme-fusion.com/documentation/avada/options/page-title-bar-options/

How to prevent text overflow (and fill the div instead) when converting html to pdf?

I'm using wkhtmltopdf to export some html pages to pdf. One of those pages is a "Business Model Canvas" that is filled with text.
The problem is, after the export, text inside each tile/panel of the canvas stays in 1 line, meaning it gets cut when it reaches the border of that div, instead of going to the next line, like the html page does.
This is what it looks like, html on the left and pdf on the right:
I tried to mess with some CSS properties like overflow, text-overflow, width or white-space, but I had no luck.
In theory, both the html and pdf share the same properties, I'm guessing the export happens too fast and the external css files don't load properly or something like that.
Either way, I could try some in-line css for the canvas template, if you have any suggestions besides the ones I tried.
After repeating the process again, made it work with white-space: normal;.
Probably had something adding extra css to the same element before.
I can't find a solution to this problem, but I avoid it it setting the same margin for all pages of my PDF. I realized that if I set a default margin to all pages except the first which has a different margin, text overflow oddly.

Is there a way to force long lines to wrap in all e-readers

I have this epub that is made in indesign.
The main text flows just fine and wraps just as it is supposed to.
The problem is with the footnotes.
Long footnotes will not wrap but extend past the right side of the screen.
It does wrap in iBooks but not in Adobe Digital Editions or Bluefire reader.
Is there a way to force wrapping of long lines through css?
Here is a link to one of the xhtml files:
http://dl.dropbox.com/u/22417556/text.xhtml
and here is a link to the css:
http://dl.dropbox.com/u/22417556/styling.css
(indesign is doing a great job of putting a lot of extra junk in here so maybe that's the problem.)
Ok I just found the a solution! My "a" tags were styled with "white-space: pre;" When I commented out that line I got the footnotes wrapping as they were supposed to. Now I just wonder if removing that line may cause something else to misbehave.
Edit: changed it from pre to pre-wrap. It also works.

How to use CSS text-overflow on text that's wrapping?

Does anybody know of a way to use {text-overflow: ellipsis;} on a piece of text that's wrapping to a second line?
Adding:
{whitespace: nowrap;}
makes text-overflow work, but I need the text to wrap so I really can't use that.
If you know the content is going to wrap to two lines every time this solution will work. Use ::after and content: '...'; and then position it over the bottom right corner of your type (which should be a block level element). This will only work if you are working against a solid background color as you need to set the background of the ::after to match.
The only downfall is the limited parameters this can be successful in and the fact that it will cut a character in half if things don't line up right (which they probably won't).
I am fairly sure that what you are trying to do is impossible in a pure CSS solution. However there is a way of hacking together a similar result. Here is what I did:
http://cce.usyd.edu.au/courses/Business+%26+Management/Business+Communication
See the fade on the block of text introducing each course? That was done by firstly restricting the overflow in the usual way and then placing another div over the top of the last line and implementing the fade in CSS. Instead of a fade you could also insert an ellipsis or some other visual clue.
So, not exactly solving it the way you want, but achieving a similar UI result to ensure the user is aware that content is truncated. Personally I think it is quite pretty :-)

How to remember in CSS that margin is outside the border, and padding inside [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I don't edit CSS very often, and almost every time I need to go and google the CSS box model to check whether padding is inside the border and margin outside, or vice versa. (Just checked again and padding is inside).
Does anyone have a good way of remembering this? A little mnemonic, a good explanation as to why the names are that way round ...
When working with CSS finally drives you mad the padded cell that they will put you in has the padding on the inside of the walls.
pin - P is in
You are using a box. If you were putting something in a box you would put some padding inside to make sure it didn't smack against the sides. Margin would then be the other thing.
Print the diagram from the Box Dimensions section of the specification, and put it on the wall.
To me, "padding" just sounds more inner than "margin". Perhaps thinking about the printed page would help? Margins are areas on the far outside - generally, you cannot even print to the edge - they are unmarkable. Within those margins, the content could be padded to provide an extra barrier between the content and the margin?
Once you work in CSS enough, it'll become second nature to remember this.
I've just learnt it over time - the box model is fairly simple but the main reason people find it hard is because body doesn't visibly break the model.
Really, if you give body a margin and a background you should see it surrounded by a white strip. However this isn't the case - body's padding is the same as margin. This establishes a few incorrect things about the box model.
I usually think about it like this:
margin = spacing around the box;
border = the edge of the box;
padding = space inside the box.
Padding is usually used inside. Either on the interior of a wall or a delivery box, that's simple. And if padding is inside, then margin is outside. Shouldn't be too hard.
use firebug to help you see.
Tim Saunders gave some excellent advice - when I first got started with CSS, I made a point of building a good, fully commented base stylesheet. That stylesheet has changed many times and remains a terrific resource.
However, when I ran into my own box model problems, I started using 'Mo Pi'. As in, "I'm not fat enough, I need to eat mo pi." Strange, but it worked for me. Of course, I put on twenty pounds while learning CSS...;-)
Create yourself a commented base stylesheet which you can use as a template whenever you need to create a new site or edit an existing site.
You can add to it as you grow in knowledge and apply it to various different browsers to see how various things behave.
You'll also be able to add in comments or examples about other hard to remember stuff or stuff that is counter intuitive.
Add border, even just temporarily. As you play with the numbers, you'll see the difference.
In fact, temporary borders around elements is a helpful way to work, such that you can see why floats are dropping, etc.
I know this is an answer to your question, but more of a tip. Whenever I am dealing with margin and padding, I will add a border around the part you are working with, then from there, it shows me the room I have to work with. When I am all set, I remove the border.
PAdding is a PArt of an element's PAinting: it extends the element's background. It makes sense to think of a pair element+padding as sharing a common background. Padding is analogous to the painting's canvas: the bigger the padding, the bigger the canvas and therefore background. Border (the painting's frame) would go around that pair. And margin will separate paintings on the gallery wall. Thinking about the concept of object background helps glue the pair object+padding together. The usual explanations of what is inside vs outside do not stick to memory: after a while everybody gets back to the original confusion. Remember also that margins are vertically collapsible and padding is not.
Instead of ask again and again to google you just use inspector window. In that style tab and scroll down to bottom you can see like this.
Margin:When you want move the block.
Padding: When you want move the items within a block.

Resources