aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
I have a line of code ( which is to long to be displayed in one line ) to be displayed on a web page in one line, just like above.
I don't it to be wrapped into two lines.
Can I accomplish this only using css?
To actually make this happen when you use words with spaces in between them overflow:auto is not enough, you'll also need text-overflow: nowrap.
http://jsfiddle.net/kZV3j/
Here's how SO's code block looks:
<pre>
<code>
<span>...</span>
</code>
</pre>
And the CSS:
pre {
overflow: auto;
}
Demo: http://jsfiddle.net/TfeLm/
I think you're looking for overflow:auto:
<div style="overflow:auto; width:200px;">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
Create a containing element (e.g. a div), then set some basic CSS properties on it that define a width, and handle the overflow. Like this:
HTML
<div class="short">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
CSS:
.short {
width:400px;
padding: 10px;
overflow-x:scroll;
}
jsFiddle example. Works in all modern browsers and IE8.
I think you are looking for the overflow property with a auto value:
<style>pre { width: 200px; overflow: auto; }</style>
<pre><code><p>Some tooooo long text on one line</></code></pre>
Live example: http://jsbin.com/uhuveg/
I believe that you should use the following CSS
#id {
width: 400px;
padding: 5px;
background: #C3C3C3;
overflow-x: scroll
}
See this live example
Related
Browser is replacing Multiple space between words to the single space in html page. for e.g if my text is 'AB-DC 3' in Browser its showing 'AB-DC 3'. Inspect window its showing 2 spaces 'AB-DC 3'.
you can also try out yourself. just inspect element and add multiple spaces in word of any line check.
is there any solution for this??
Similar question answered cause, but not explaining how to resolve this.
Whitespace is non-significant by default, and is compacted down to a single space when rendered.
CSS can change that: white-space: pre-wrap will provide the default line-wrapping functionality that you would expect, plus the significant-whitespace behaviour of preformatted text. Best of both worlds!
<pre>AB BA</pre>
pre tag will also solve your problem
On the Op scenario:
Use white-space:pre; (no wrap except at <br>) or white-space:pre-wrap; (wrap when needed).
Example:
body{
margin: 0;
}
div {
width: 200px;
height: 100px;
}
#a {
white-space:pre;
background: gold;
}
#b {
white-space:pre-wrap;
background: skyblue;
}
<div id=a>This is some Text writen on here as example.<br> Here's a second sentence after the line-break .</div>
<div id=b>This is some Text writen on here as example.<br> Here's a second sentence after the line-break .</div>
Single White spaces:
Sometimes you need to use single spaces, like at the start of a sentence (when it is ignored). In situations like this, the best choice is to use instead.
Example:
p:nth-of-type(1) {
font-size: 2em;
background: tomato;
}
p:nth-of-type(2) {
font-size: 2em;
background: greenyellow;
}
<p> content</p>
<p> content</p>
To avoid changing your style of display.
Better to use style:
<style>
{ white-space: pre;}
</style>
If you give so many spaces in html it is of no use because browser will consider only one you have to use space entity the no. of times you type this entity browser will so that much spaces
HTML:
<p>He llo</p>
It will show exact 4 spaces in the work
Here is the fiddle link https://jsfiddle.net/yudi/zrqrfw98/
I'm not the best at HTML. Essentially I am trying to get the effect of a lot of line breaks, without filling my code with a lot of consecutive <br> tags. What I have in my head is this CSS:
.movedown {
position: relative;
down: 120px;
}
and this HTML, where my text is:
<span class="movedown">*text here*</span>
I only need it on a single page. Anyone know where I'm going wrong?
Assuming you want to inject lots of breaks between two words you can inject a span tag styled as follows:
.long-br {
display: block;
height: 12em; /* 12em is roughly 10 lines at current font size/1.2 line height */
}
<p>Hello <span class="long-br"></span> World</p>
Alternate: if you want to insert lots of breaks between two blocks of text, the ideal way is to use margins:
.long-gap {
margin-top: 12em;
}
<p>Paragraph 1</p>
<p class="long-gap">Paragraph 2</p>
Try this:
.movedown {
position: relative; //Not required
margin-top: 120px;
}
You need to use the CSS property margin-top to add some space without using line breaks.
.movedown {
margin-top: 120px;
}
down is not an existing css rule. What you should be using is a div with margin-top, this creates a space above the element.
.down {
margin-top: 50px;
}
*top text*
<div class="down">*text here*</div>
Instead of 'down' try:
top:120px;
Just use <div> elements instead of <span>.
By default div is a block style element and span is inline.
block occupies the whole row, so each new one will be on a new row.
You can change the default behaviour with CSS but better to get a grip of the basic elements first.
I have been searching the web for a solution for 3 hours without success. I want to set overflow: auto to tag as follows:
td {
overflow:auto!important;
}
It works fine in chrome but not in Firefox. I checked my entire css file by w3c css validator.
There is no error too. Any idea please? I am sorry if it is very silly question but everyone have to learn this first to be expert.
Try wrapping it in a <div>. The overflow attribute is not defined for a <td> element.
See here
Try to put your overflow:auto to the wrapper like this,
pre, div {
width:100%;
overflow: auto !important;
}
See demo
Try this
td {
height: 20px; // mention a height
overflow:auto!important;
}
These are codes:
<div>Hello World. http://www.newyorker.com/arts/events/2014/02/03/140203gofr_GOAT_front.</div>
div {
background: red;
width: 200px;
height:200px;
}
http://jsfiddle.net/gEDx9
This long link is displayed at 2nd line. I hope long this link can be displayed in multiple lines. I also hope this long link won't be displayed at outside of red div element. This long link should be fully displayed.
So this long link should be displayed at 1st line, 2nd line and 3rd line. May it will also be displayed at 4th line.
How can this be done via CSS?
There is a CSS Property called "word-break" which you may find useful:
div {
background: red;
width: 200px;
height: 200px;
word-break: break-all;
}
Reference: W3Schools word-break information
Just add the word-wrap-attribute this way:
div {
background: red;
width: 200px;
height:200px;
word-wrap: break-word;
}
See updated fiddle: http://jsfiddle.net/qhzKF/
If you really need to include a URL in page content, insert zero-width spaces at permissible break points. You can use the reference for them, e.g.
http://www.newyorker.com/arts/events/2014/02/03/140203gofr_GOAT_front
The details depend on the conventions on line breaks in URLs. The above example complies to the rules of The Chicago Manual of Style. There are other styles, too, but no reasonable style allows arbitrary breaking of URLs (which is what you would get by using word-wrap: break-word).
The proper handling of URLs in content is thus somewhat tricky, but it can be automated. However, it is best avoided by not using URLs in content unless the page content is about URLs. Normally, you should use links with descriptive link texts, “hiding” URLs into href attributes.
apply this css to your A element
a { word-wrap:break-word; }
You can use the word-wrap:break-word
CSS:
div {
background: red;
width: 200px;
height:200px;
word-wrap:break-word;
}
http://jsfiddle.net/gEDx9/3/
How can I stop this text from overflowing?
<html>
<head>
<style type="text/css">
.sticky
{
background-color: #FCFC80;
margin: 5px;
height: 100px;
width: 135px;
}
.sticky .edit
{
vertical-align:middle;
height: 100px;
position:relative;
color:Black;
background-color:blue;
height:90px;
vertical-align:middle;
width:90px;
border-collapse:collapse;
}
</style>
</head>
<body>
<div id="note44" class="sticky">
<div id="text44" class="edit" title="Click to edit" style="">A very long word: abcdefasdfasfasd</div>
</div>
</body>
</html>
I think word-wrap is supported in most browsers?
word-wrap:break-word;
Depends on what the desired output should be, but if you want to hyphenate the word, you can use , that is, replace "abcdefasdfasfasd", with say, abcdefasdfasfasd.
You could also have a look at the overflow property.
does justify do it?
There's a CSS property called word-wrap. Give it the attribute "break-word" and you should be good to go.
.break-word {
word-wrap: break-word;
}
Source: Web Designer Wall - Force text to wrap
The css mentioned above won't work in all browser's as it's non-standard.
When I run into this I usually use php's wordwrap function, but that's no good if you're not using php.
Two things which need to be pointed out:
You've defined the height of the second element twice in the css.
If you wrap text inside an element with a defined height, it could well overflow, and cause you a new set of problems.