Add line break in css using class / injecting a line break in css
Get link
Facebook
X
Pinterest
Email
Other Apps
-
Injecting a Line Break
I had a little situation where I had a header with a span in it, and I wanted to make sure to put a line break before the span. For the record, there really isn't anything wrong with just chucking a <br> tag before it (and in fact the ability to show/hide that is very useful). But... it always feels a little weird to have to use HTML to achieve a layout thing.
So let's take a journey. A journey in which we say "But..." a lot.
<h1class="one">
Break right after this
<!-- <br> could go here, but can we do it with CSS? --><span>
and before this
</span></h1>
Rather than a <span>, we could use a <div>, and we'll get that break just by virtue of the div being a block-level element.
But we're using a span on purpose, because of the design. The text after the break should be inline/inline-block, because it's going to have a background and padding and such.
That actually works. But... because of the padding and background, it leaves a little chunk of that behind when the line breaks:
We could fix the awkward-left-edge-hugging on by using box-decoration-break: clone;, but... that just leaves a bigger chunk up top:
box-decoration-break is great for some issues, but not this one.
If we made the span inline-block, the break would happen within that block, which isn't what we want either:
Making the pseudo element block-level and leaving the span alone doesn't do the trick either:
#You could get a little weird and inject the actual text with a pseudo element
This was Aaron Bushnell's idea. The trick here is to make the span block level, but then inject the text with a pseudo element and style it as an inline element.
I've long been a fan of pseudo-element trickery, but this feels slightly dangerous in that you may be hurting accessibility. I think some screen readers read pseudo-elements, but I don't think all, nor are they supposed to. Not to mention you can't copy and paste all the text this way. At least the text is still maintained entirely in the HTML!
My favorite idea came from Thierry Koblentz. Just make the span display: table; and you're done. It's not tabular data of course, but that doesn't matter. The fact you can force table layout from CSS is all about exploiting the unique layout properties of table layout — not semantics.
I have a project in which I use MVC C#, with Bootstrap and FontAwesome. My objective is to show a spinner and disable the page while waiting for an ajax request. So far, I have successfully acomplished this goal with the following code: HTML: <div id = 'ajax_loader' style = " position : fixed ; left : 50% ; top : 50% ; display : none ; " > <img src = "~/Images/ajax-loader.gif" > </div> JS: function blablabla () { //show spinner, disable page var modal = $ ( '<div>' ). dialog ({ modal : true }); modal . dialog ( 'widget' ). hide (); $ ( '#ajax_loader' ). show (); $ . ajax ({ type : "Get" , url : url , success : function ( result ) { alert ( "success! " + result ); }, error : functi...
Open settings.json file and write below code ==> // Whether git is enabled. "git.enabled" : false , // Path and filename of the git executable, e.g. `C:\Program Files\Git\bin\git.exe` (Windows). "git.path" : null , // When enabled, commits will automatically be fetched from the default remote of the current Git repository. "git.autofetch" : false ,
Comments
Post a Comment