I've got a Twitter feed on my blog. It's working great, but there's an issue with long URLs in tweets. Long URLs break the layout by extending past the width of the container.
My code looks like this:
<ul id="twitter_update_list">
<!-- twitter feed -->
</ul>
<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/USERNAME.json?callback=twitterCallback2&count=3"></script>
The blogger.js script contains the callback function which takes the data from the Twitter request and populates <li> elements to a predefined <ul>.
I'm using the following CSS to automatically break the line (for browsers that support it):
#twitter_update_list li span a {
word-wrap: break-word;
}
I know about the <wbr> tag and was trying to use it with a jquery function that looked like this:
$(document).ready(function(){
$("#twitter_update_list li span a").each(function(){
// a replaceAll string prototype was used here to replace "/" with "<wbr>/"
});
});
However when I tried using that snippet, it would cause IE to stop responding and that's no good.
I'm looking for a block of code I can just drop in that will fix the line break issue (by adding a line break to long URLs). Firefox and Chrome are working properly, but IE7 and IE8 need something more. (I don't care about IE6.)
You can try using: word-break: break-all;
div {
background: lightblue;
border: 1px solid #000;
width: 200px;
margin: 1em;
padding: 1em;
}
.break {
word-break: break-all;
}
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cupiditate vitae fugiat fuga fugit cum http://www.ThisLongTextBreaksBecauseItHasWordBreak-BreakAll.com facere mollitia repellat hic, officiis, consequatur quam ad cumque dolorem doloribus ex magni necessitatibus, nisi accusantium.</p>
<p>Voluptatibus atque inventore http://www.looooooooooooooooooooooooooooongURL.com veritatis exercitationem nihil minus omnis, quisquam earum ipsum magnam. Animi ad autem quos rem provident minus officia vel beatae fugiat quasi, dignissimos
sapiente sint quam voluptas repellat!</p>
</div>
Just be sure of applying this only to the link. Otherwise, all other words will break too. :)
Try playing with the white-space CSS property.
Check this link for more info: http://perishablepress.com/press/2010/06/01/wrapping-content/
I believe what you're looking for are soft hyphens. This was covered by ALA a while back.
http://www.alistapart.com/articles/the-look-that-says-book/
I know this is old post but since I ended up here with a related google search - someone else might also.
I needed to make a long url breakable, and since wasn't usable for my site (i.e not in html5 standards, and ie8 seems to ignore it)
<style>.wbr { display: inline-block; width: 0px;}</style>
Since i generated the url I was able to insert <span class="wbr"> </span> before the slashes.
So I ended up with :
www.example.com<span class="wbr"> </span>/somepath<span class="wbr"> </span>/blah.php
which looks normal in the browser but allows from word wraping at the / marks
www.example.com/somepath/blah.php
Hope that helps the next person who visits
Related
I am currently new to HTML and CSS and do not have much knowledge about them. Recently, I came across a problem where my text-cursor is not visible when the background-color of a <div> element is darkish.
Here is an example:
<style>
.PreCode {
font-family: Georgia, 'Times New Roman', Times, serif;
font-size: initial;
color: rgb(28,26,26);
background-color: grey;
border: 1px solid black;
text-transform: capitalize;
font-weight: 100;
margin-top: 20px;
text-align: center;
padding: 10px;
}
</style>
Now when ever I try to focus the text written inside of a <div> element with this as the class my text cursor becomes transparent.
Is there any way to prevent this from happening? Is there a way to change the color of the text-cursor to the color of the cursor i.e red?
Here is the <div> code:
<div class="PreCode">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla necessitatibus dolorem suscipit. Quibusdam dolorem eos sunt voluptate neque, unde expedita, error modi, assumenda quisquam repudiandae iste provident rerum vel blanditiis.
</div>
The caret-color property is only supposed to apply to input elements and similar - elements that are intended to be user editable. So, if you apply is to a div (as here), you'll get unexpected results. (And, I suspect that you mean "invisible" rather than "transparent" - unless you actually see transparency being applied, but I suspect it's just that you can't see it against the dark background.)
Do you mean that you want the background colour of the highlighted text to be different from the default? In which case you need to set the background-color property for .PreCode::selection in your CSS.
Also, bear in mind that the way the cursor is rendered on screen depends on your browser and also your operating system. There are ways to set a custom cursor, but I don't think that's your problem here. The default cursor shapes and colours depend ultimately on the reader (i.e. your user's browser and OS). On my system, for example, the pointer is a black arrow with a white outline, and the text marker similarly has an outline. So, whatever background it's on, it remains visible.
It also depends what you mean by "cursor": the mouse pointer? The text-position marker? The actual cursor (the often-flashing vertical line that marks the text-input position)? Because the actual cursor will only be displayed in an editable element (as above), because it marks a text-input position and there isn't one of those at all if the text element doesn't accept user input.
you face that issue because you don't make changes on that line the caret-cursor property is used when you wanna make changes on any text, para, input, and etc.
Caret-Cursor : Set the color of the cursor in input elements.
if you wanna make your cursor color change in the div or see work or not you can add the contenteditable before the class then your code work properly and you also edit your text.
follow the code for the desired output.
<div contenteditable class="PreCode">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nulla necessitatibus dolorem suscipit. Quibusdam dolorem eos sunt voluptate neque, unde expedita, error modi, assumenda quisquam repudiandae iste provident rerum vel blanditiis.
now your code work properly if you want any help then ping me.
Thanks
I have a code below that does word wrap, but the problem is, it cuts off the word just like an example output. Expected output, the second "head" should be in the next line and not cut.
Here is the code.
<div className="relative mt-px-14 mx-px-8 p-px-25">
<div className="relative">
<div className="absolute w-full text-20 whitespace-pre-line break-words">
Head shoulder knees and toes head
</div>
.... more codes here
</div>
</div>
Tailwind css documentation
> break-all ==> word-break: break-all;
> whitespace-pre-line ===> white-space: pre-line;
As you can see in the snippet below, the value for word-break you were looking for is break-word, not break-all.
As per the link,
break-all To prevent overflow, word may be broken at any character
break-word To prevent overflow, word may be broken at arbitrary points
.one {
word-break: break-all;
white-space: pre-line;
}
.two {
margin-top: 20px;
white-space: pre-line;
word-break: break-word;
}
<div class="one">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Accusamus deserunt consectetur iste obcaecati nam placeat adipisci beatae explicabo dolorem cum magnam a officiis nihil repudiandae eligendi, tempore ducimus maxime veniam.
</div>
<div class='two'>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Accusamus deserunt consectetur iste obcaecati nam placeat adipisci beatae explicabo dolorem cum magnam a officiis nihil repudiandae eligendi, tempore ducimus maxime veniam.
</div>
Actually the styles are working fine.
I found out that my custom keyboard does not returning " " space if I tap spacebar. It instead return which causes the problem.
What I did is I replace to space(" "), and it solves the problem. Replacing from javascript dom text node
Please use overflow-wrap: break-word; for .
article {
max-width: 500px;
margin: 0 auto;
width: 100%;
text-align: justify;
}
article p {
overflow-wrap: break-word;
}
<article lang="en">
<p>As designers attempting to creating functional work, oftentimes we are required to make our designs look as finished as possible.</p>
<p>For example, if you are designing a brand new website for someone, most times you will have to make sure the prototype looks finished by inserting text or photos or what have you. The purpose of this is so the person viewing the prototype has a chance to actually feel and understand the idea behind what you have created.</p>
</article>
Also You can use CSS hyphens property.
This is a quick demo:
article {
max-width: 500px;
margin: 0 auto;
width: 100%;
text-align: justify;
}
article p {
-webkit-hyphens: auto;
-moz-hyphens: auto;
-ms-hyphens: auto;
hyphens: auto;
}
<article lang="en">
<p>As designers attempting to creating functional work, oftentimes we are required to make our designs look as finished as possible.</p>
<p>For example, if you are designing a brand new website for someone, most times you will have to make sure the prototype looks finished by inserting text or photos or what have you. The purpose of this is so the person viewing the prototype has a chance to actually feel and understand the idea behind what you have created.</p>
</article>
I've noticed that Chrome and Safari handle position: sticky on elements slightly differently.
Specifically, when a sticky element is made taller, and the window is currently scrolled such that the sticky element is offset from its initial position, Chrome will alter the scrollTop position by the same amount - giving the appearance of the content staying still while the sticky element grows over the top.
In Safari, the scrollTop position is unchanged in this scenario, giving the appearance of the content moving down to accommodate the sticky element's increased height.
I've created a code snippet below to demonstrate how the browser behaves in this situation. The screenshots above show how this demo behaves on each browser, but you can try it for yourself here.
function grow() {
const header = document.getElementById("header");
document.getElementById("header").classList.toggle("large-header");
updateScrollText();
}
function updateScrollText() {
const container = document.getElementById("container");
const scrollParent = getScrollParent(container);
document.getElementById("scrollbarpos1").innerHTML = scrollParent.scrollTop;
document.getElementById("scrollheight1").innerHTML = scrollParent.scrollHeight;
document.getElementById("containerheight1").innerHTML = container.offsetHeight;
document.getElementById("scrollbarpos2").innerHTML = scrollParent.scrollTop;
document.getElementById("scrollheight2").innerHTML = scrollParent.scrollHeight;
document.getElementById("containerheight2").innerHTML = container.offsetHeight;
}
function getScrollParent(node) {
if (node == null) {
return null;
}
if (node.scrollHeight > node.clientHeight) {
return node;
} else {
return getScrollParent(node.parentNode);
}
}
window.onscroll = updateScrollText;
window.onload = updateScrollText;
#header {
background-color: #CACACA;
position: sticky;
top: 0;
padding: 20px;
}
.large-header {
height: 100px;
}
.content {
background-color: #a2a6c4;
height: 1500px;
}
.shift-down {
margin-top: 50px;
}
<div id="container">
<div id="header">
<button type="button" onclick="grow()">Grow/Shrink</button>
</div>
<div class="content">
<br>
Scrollbar position: <span id="scrollbarpos1">0</span>
<br>
Scroll height: <span id="scrollheight1">0</span>
<br>
Container height: <span id="containerheight1">0</span>
<br>
<br>
Voluptatibus omnis perspiciatis consequatur magni error exercitationem saepe qui. Ipsa sint non labore voluptates. Asperiores aut non ullam aut sit omnis ducimus in. Aut enim nihil unde ad expedita. Ratione necessitatibus quasi dolorem sunt aperiam nobis ducimus.
Sequi quasi maiores eos aut non. Ipsam delectus sit facilis aut. Dolor facilis eum dignissimos. Vero reiciendis odio quis blanditiis.
Error nesciunt rem facilis. Neque labore et qui sequi eos corrupti dolorem. Reprehenderit qui voluptatem et neque ducimus ipsum similique fugit. Ea sint alias qui laborum nesciunt. Nihil ex repellendus odit sint unde fuga.
A eum nulla ut cumque necessitatibus culpa exercitationem unde. Corrupti sit minima eveniet et aut possimus sapiente. Est accusantium aut ut numquam illo.
Praesentium fugit pariatur eum ad velit distinctio culpa id. Quia voluptatum dignissimos consequatur. Eaque nihil voluptas in voluptas voluptas eius voluptas.
<br>
<br>
<div class="shift-down">
Scrollbar position: <span id="scrollbarpos2">0</span>
<br>
Scroll height: <span id="scrollheight2">0</span>
<br>
Container height: <span id="containerheight2">0</span>
</div>
</div>
</div>
I looked at the W3C spec on Positioned Layout but couldn't find anything specifically defining how this is supposed to work.
So my questions are:
Why is this behaviour different on these two browsers?
Which one, if any, is "correct"?
Is there any way to make both browsers behave identically (either way)?
Why is this behaviour different on these two browsers?
To understand this, you first need to understand how a sticky element takes up space on a page. As you scroll past the sticky element, the rendered part of the sticky element follows the top of your viewport, but the element still physically takes up space where it was originally placed:
This puts the browser in a bit of a weird situation when you resize the header, because it's actually an element that you have already scrolled past. There are two approaches to solving this. You can do like Safari and Firefox and always keep the same distance to the top of the document, or you can do like Chromium and move the viewport so that it follows the element you are currently looking at:
I believe Safari and Firefox do it their way, because it's the easiest solution, and that's just how every browser has always done it.
I believe Chromium has changed it's approach recently because it has a distinct advantage when a user is reading articles with slow loading ads that change size after they've loaded:
As you can see above, when the ad loads in Safari and Firefox, it causes a major shift in the page content, which annoys and disorients the user. This can especially be bad if there are several ads that load shortly after one another.
With the Chromium approach, the viewport is adjusted so that the user doesn't even notice that anything has happened.
I was not able to find any spec or discussion to back up my claims, but i'm pretty sure that this is the reasoning behind. I am not sure if Firefox or Safari has had a reason to not implement Chromiums approach, or if they just didn't feel it was that important.
Which one, if any, is "correct"?
Which solution is best is probably a very complicated and somewhat subjective discussion that i won't go into, although the benefits of Chromiums approach is undeniable.
Is there any way to make both browsers behave identically (either way)?
When you press the Grow/Shrink button, you can always detect if the scroll height changes, and then set it back right after it was changed. You can also do the opposite and change the scroll height yourself so all browsers behave like Chromium. Here is an old article from someone who did exactly that:
https://simonerescio.it/en/2017/03/chrome-changes-its-center-of-gravity-reference-is-not-the-document-but-the-viewport
I want to change theme when uses click on change theme button dynamically.
When users click on a checkbox (checkbox is checked)
these commented theme has to be applied
/**
$theme1-background:white;
$theme1-font-color:black;
$theme1-btn-primary:rgba(243,241,0,0.1);
$theme1-btn-secondary:#2ab1e4;
**/
otherwise the default one has to be applied
I don't know any way to do it, but have seen this feature quite often
Here is complete codepen: https://codepen.io/eabangalore/pen/XPqoBK
$theme1-background:rgba(0,0,0,0.8);
$theme1-font-color:white;
$theme1-btn-primary:green;
$theme1-btn-secondary:orange;
//below setting has to be applied based on theme 2
/**
$theme1-background:white;
$theme1-font-color:black;
$theme1-btn-primary:rgba(243,241,0,0.1);
$theme1-btn-secondary:#2ab1e4;
**/
.main{
margin-top:34px;
background:$theme1-background;
border:1px solid orangered;
width:90%;
color:$theme1-font-color;
.btn-primary{
background:$theme1-btn-primary;
color:$theme1-font-color;
}
.btn-secondary{
background:$theme1-btn-secondary;
color:$theme1-font-color;
}
}
<label>change theme:<input type="checkbox"></label>
<div class="main">
<button class="btn-primary">button primary</button>
<button class="btn-secondary">button secondary</button>
<p>text color ------>>> Lorem, ipsum dolor sit amet consectetur adipisicing elit. Iure delectus officiis ea in deserunt blanditiis at, ratione recusandae asperiores pariatur perspiciatis voluptate accusantium aperiam, harum accusamus quis veritatis quisquam aliquid.</p>
</div>
You can easily restyle an entire page dynamically by doing two things:
First, create a duplicate stylesheet and add a body class selector such as body.other-theme to the beginning of every selector you want to change. So your two stylesheets might look like this:
/* main-theme.css */
#content {
background: white;
}
/* other-theme.css */
body.other-theme #content {
background: black;
}
Then when the user checks the checkbox, simply add the other-theme class to the body of the document. This will trigger all other-theme styles to display.
In each stylesheet, you can set the theme colors and other variables that will be specific to that theme.
Quick points, having trouble aligning a text in a table as it wraps the second line. I have treid justifying and block and in-line etc Appreciate any suggestions. What I need is that the second line aligns exactly under the first line eg: starts at vfdbd....
put the text inside a span element with display: inline-block;. That way the text start on the same line.
The wrapper needs to have text justification applied via CSS:
text-align:justify;
text-justify:inter-word;
In general, browsers do a crappy job as fully-justified text compared to "typesetting" applications for print. In general, full-justification on browsers makes text HARDER to read and should generally be avoided.
No need for an extra element if you know the width of the symbol (text or image) you're adding to the left of your first line.
The trick is to add a negative text-indent counter-balanced by a positive margin-left. Say you add a 40px-wide internet kitten via :pseudo + 8px of padding between image and text: the element then needs following first CSS rule:
/* Image is 40px-wide and we want it at 8px from text */
.txt-indent {
margin-left: 48px;
text-indent: -48px;
}
.txt-indent:before {
content: url(https://placekitten.com/40/40);
padding-right: 8px;
}
body {
width: 200px;
line-height: 1.5;
}
<p class="txt-indent">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut, natus soluta! Itaque, corporis veritatis quisquam ut debitis sed incidunt enim sit ratione sint repellat aliquid sunt rerum commodi asperiores ipsa!</p>
Ended up increasing line-height to make it work.