How to insert line breaks in HTML documents using CSS

Tags: html,css

Problem :

I'm writing a web service, and I want to return the data as XHTML. Because it's data, not markup, I want to keep it very clean - no extra <div>s or <span>s. However, as a convenience to developers, I'd also like to make the returned data reasonably readable in a browser. To do so, I'm thinking a good way to go about it would be to use CSS.

The thing I specifically want to do is to insert linebreaks at certain places. I'm aware of display: block, but it doesn't really work in the situation I'm trying to handle now - a form with <input> fields. Something like this:

  Thingy 1: <input class="a" type="text" name="one" />
  Thingy 2: <input class="a" type="text" name="two" />
  Thingy 3: <input class="b" type="checkbox" name="three" />
  Thingy 4: <input class="b" type="checkbox" name="four" />

I'd like it to render so that each label displays on the same line as the corresponding input field. I've tried this:

input.a:after { content: "\a" }

But that didn't seem to do anything.

Solution :

It'd be best to wrap all of your elements in label elements, then apply css to the labels. The :before and :after pseudo classes are not completely supported in a consistent way.

Label tags have a lot of advantages including increased accessibility (on multiple levels) and more.

    Thingy one: <input type="text" name="one">;

then use CSS on your label elements...

label {display:block;clear:both;}

    CSS Howto..

    Responsive CSS: Replicating how Facebook's chat panel disappears below a certain browser window width

    Floating divs, different height, building from left to right. how to fill vertical gaps between levels?

    How to read a browser's unsupported CSS properties?

    Using a lot of style sheets. Needing opinions on how to move forward efficiently

    How to send HTML to an embedded WebView without running a local webserver?

    How to align css class using bootstrap

    How to add CSS to ASP.NET site with WebOptimization and Bundling

    How to style using nth-of-type within a ul tag?

    Don't understand how to control css elements with jQuery css

    how to copy font-family from a webpage

    How to transform a production to LL(1) for a list separated by a semicolon?

    How to Make Inline SVG Scale to Parent Element with CSS

    how to align in centre using html css

    How to set footer responsive?

    How do I make the Android WebView not ignore the 'height' css property?

    Need help determining how to position this element with CSS

    How can div with be controlled with responsiveness

    How do I style a specific select option in HTML

    How to change the width of displayed text nested in a div?

    how to override the placeholder icons în AEM 6?

    how to animate width and height 100% using css3 animations?

    How do I remove applied css on a div by JQuery?

    How do I make hidden description text push the content upwards when it shows

    How to spin and rotate in css?

    How to write function in css

    How I do edit the css for just the home page on Magento?

    How do I vertically align text inside an anchor element, which is nested within an unordered list

    How to reduce div size in CSS using twitter bootstrap?

    How to vertically align numbers of ol?

    How to make gridview in scrollable?