Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Causing line breaks for inline elements without <br />

Tags:

css

How can I have each of these a elements break on to new lines, but keeping them as display=inline and without br tags?

<div>
   <a href="element1">Element 1</a>
   <a href="element1">Element 2</a>
   <a href="element1">Element 3</a>
</div>
like image 627
cbp Avatar asked Apr 15 '10 05:04

cbp


People also ask

How do you line break without a br tag?

Use block-level elements to break the line without using <br> tag. There are many ways to break the line without using <br> tag. The used properties are listed below: white-space: pre; It is used to make elements acts like <pre> tag.

How do you prevent a line from breaking in CSS?

The white-space property has numerous options, all of which define how to treat white space inside a given element. Here, you have set white-space to nowrap , which will prevent all line breaks.

How do I stop a line breaking in HTML?

The <nobr> HTML element prevents the text it contains from automatically wrapping across multiple lines, potentially resulting in the user having to scroll horizontally to see the entire width of the text.


Video Answer


2 Answers

This can now be implemented reliably with css grid

div {
  display: grid;
  grid-template-columns: 100%;
}

div a {
  grid-column-start: 1;
}
like image 131
Interlated Avatar answered Oct 24 '22 23:10

Interlated


This can be done, but will not work for all browsers. You need to use the :after pseudo-element with white-space and content. Like so

<html>
<head>
<style type="text/css">
    div a:after {white-space: pre;content:'\A';}
</style>
</head>
<body>
<div>
   <a href="element1">Element 1</a>
   <a href="element1">Element 2</a>
   <a href="element1">Element 3</a>
</div>
</body>
</html>

Reference: http://www.w3.org/TR/CSS2/generate.html#content

like image 25
Jonathan Avatar answered Oct 25 '22 00:10

Jonathan