When I use shape-outside: url(anyimage.png) and float it to the right, the text around it wraps nicely as intended, but when I float it to the left, the text to the right wraps around the the edge of a rectangle.
Any idea why this should be so? I have tried with several transparent shapes and the text wraps nicely when the image is floated to the right, but when its floated to the left, the text defaults to a wrapping around a rectangle.
Any idea if this is a known bug? I'm using the latest version of Chrome (46.0.2490.86 m) and only interested in implementation on Chrome.
Here is the image of float issue attached
Also here is the image of the circle png
and here is the CSS:
.element{
width:200px;
height:200px;
float:right;
shape-outside: url("circle_new.png");
shape-image-threshold: 0px;
shape-margin: 10px;
}
**
added after first response: let me clarify, am looking for a reason for the inconsistent behaviour of shape-outside: url. I understand I could very well use circle() as pointed out by the first answer, but I want this to work for all shapes, that is why I am seeking enlightenment specifically on the issue of shape-outside: url.
You have a syntax error
.element{
width:200px;
height:200px;
float:right;
shape-outside: url("circle_new.png");
shape-image-threshold: 0px; /* error */
shape-image-threshold: 0; /* in the range 0 - 1 */
shape-margin: 10px;
}
Since you don't post an example, it's difficult to tell, but this property is subject to cross-origin issues. So another posible problem would be the image being blocked.
Have you checked the console ?
Note that the fact that you are seeing the image does not imply that it isn't being blocked in the shape-outside url
If your aim is to make the text wrap around a circle, you should use circle() for the shape-outside property :
p{
width:400px;
text-align:justify;
}
.element {
width:200px;
height:200px;
float:right;
shape-outside: circle(50%);
shape-image-threshold: 0px;
shape-margin: 10px;
background-image:url('http://i.stack.imgur.com/gtBMS.png');
background-size:contain;
}
p+p .element{
float:left;
}
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis quam ex. Fusce sagittis purus mi, ut volutpat lorem venenatis id. In varius sodales dui ut molestie. <span class="element"></span>
Phasellus pretium metus id massa volutpat, sed gravida nisl fringilla. Quisque eu gravida lacus, in mollis risus. Duis et est sodales, iaculis mi et, scelerisque elit. Vivamus in massa at lectus hendrerit condimentum. Curabitur nec dignissim turpis, elementum viverra urna. In hac habitasse platea dictumst. Nunc eget ullamcorper augue. Aliquam sit amet quam feugiat, finibus lacus ac, luctus mi. In quis leo nec lectus porttitor pulvinar mollis vitae tellus. Fusce turpis quam, fringilla at aliquam sit amet, porta ac purus. Suspendisse ac faucibus dolor. Aliquam erat volutpat. Nam mauris metus, pharetra vitae velit eu, suscipit molestie odio.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur quis quam ex. Fusce sagittis purus mi, ut volutpat lorem venenatis id. In varius sodales dui ut molestie. <span class="element"></span>
Phasellus pretium metus id massa volutpat, sed gravida nisl fringilla. Quisque eu gravida lacus, in mollis risus. Duis et est sodales, iaculis mi et, scelerisque elit. Vivamus in massa at lectus hendrerit condimentum. Curabitur nec dignissim turpis, elementum viverra urna. In hac habitasse platea dictumst. Nunc eget ullamcorper augue. Aliquam sit amet quam feugiat, finibus lacus ac, luctus mi. In quis leo nec lectus porttitor pulvinar mollis vitae tellus. Fusce turpis quam, fringilla at aliquam sit amet, porta ac purus. Suspendisse ac faucibus dolor. Aliquam erat volutpat. Nam mauris metus, pharetra vitae velit eu, suscipit molestie odio.</p>
Note that I also added text-align:justify; so the text wraps closer to the shape on the right
In both situations the text isn’t all aligned to the right. This behavior is normal. The text starts at the same point on the left and ends at different points on the right, since each line has a different length. It doesn’t have much to do with your image really.
The best way around this is to use shape-outside: circle(); and set a proper number arugment inside circle(). Hope that helps.
Related
I need some help with hiding my horizontal scrollbar and still able to scroll. I have used webkit but does not work in IE and firefox. I have seen a lot of help with vertical scrollbar, but does not work with horizontal. Any help?
Update:
I have created a JSFiddle to show my problem. I want to hide the horizontal scrollbar and still able to scroll without using
::-webkit-scrollbar {
display: none;
}
http://jsfiddle.net/o1xoh9w8/1/
Here is how you do it, I have tested this in Chrome, IE, Firefox, Opera, Safari(Windows) and Edge
<h1>You can scroll with mouse wheel</h1>
<div id="box">
<div id="content">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus</p>
</div>
</div>
h1{font-weight:bold;font-size:2em;} /* ignore only for header */
/* *********************** */
div#box{
height:200px;
width:300px;
overflow:hidden;
border:1px solid black;
padding: 10px;
}
div#content{
height:200px;
width:326px;
/*
* Uncomment to see scrollbar
width:300px;
*/
overflow:auto;
}
Here is a JSFiddle: http://jsfiddle.net/JoshMesser/VUSuZ/
Credits go to creator of the JsFiddle
EDIT:
For vertical it is just a matter of changing the height. What you are doing is you are just pushing the scroll bar outside of what user can see, so to them its not there, while in reality it is there hidden behind elements. Here is a JS Fiddle based on my last one. You will see I just forced p to be in single line to get horizontal scrolling and then increased the height to hide the scroll-able bar.
http://jsfiddle.net/VUSuZ/575/
I used a fixed height approach.
Note: this approach can help only in specific cases.
#container1{
height: 50px;
/* Just for presentation. Can be removed */
border: 1px solid red;
/* Hides content outside this container */
overflow: hidden;
}
#container2{
/* Height is significantly greater than the height of container#1 to hide
any possible scroll */
height: 100px;
overflow: auto;
white-space: nowrap;
}
<div id="container1">
<div id="container2">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam hendrerit, ante laoreet mattis blandit, arcu nisi blandit felis, et molestie justo lacus et sem. Nunc tempor tellus sit amet eleifend tristique. Integer eget condimentum lectus, nec viverra risus. Nullam leo lectus, placerat vitae porta eget, auctor et nisi. Suspendisse feugiat in lacus accumsan tincidunt. Fusce pulvinar accumsan sem sit amet finibus. Curabitur volutpat mi vitae eros mattis congue. In ut sem eu tellus egestas lobortis vitae eu felis. Maecenas sodales, nisl eu bibendum vulputate, neque leo finibus odio, sit amet bibendum libero dolor sed diam. In molestie magna vitae dui vulputate, eu consequat dui ullamcorper. In hac habitasse platea dictumst. Vestibulum pulvinar, mi quis mollis pulvinar, metus justo aliquet arcu, vel venenatis ipsum dolor at sapien. Sed ac odio bibendum, feugiat nibh at, viverra mi. Morbi sem nisi, ultricies non nulla pretium, gravida malesuada neque.
</div>
</div>
(My case is horizontal scrollable buttons container for mobile screens - the buttons are stuck to the above block (+ margin) and have fixed height)
I think you do not want to use
::-webkit-scrollbar {
display: none;
}
Because it will hide all the scroll bars.
A better way to hide the scroll bar but still enable scrolling in a particular container will be to follow the following example:
HTML
<div class="container">
<table>
<tbody>
<tr>
<td>Example</td>
<td>Example</td>
<td>Example</td>
<td>Example</td>
<td>Example</td>
<td>Example</td>
<td>Example</td>
<td>Example</td>
</tr>
</tbody>
</table>
</div>
CSS
.container {
overflow-x: auto;
white-space: nowrap;
}
.container::-webkit-scrollbar {
display: none;
}
Is it posible to make text left aligned on a slanted line? it's alignement should follow the slanted slanted image with required support for IE9+?
My example code :
img {
display: block;
float: left;
transform: rotate(-5deg);
margin: 0 15px;
}
<div>
<img src="http://placehold.it/150x250&text=img" alt="image" />
<p>Lorem ipsum dolor sit amet. Vestibulum commodo volutpat a, convallis ac, laoreet enim. Phasellus fermentum in, dolor. Pellentesque facilisis. Nulla imperdiet sit amet magna. Vestibulum dapibus, mauris nec malesuada fames ac turpis velit, rhoncus eu,luctus et interdum adipiscing wisi. Aliquam erat ac ipsum. Integer aliquam purus. Quisque lorem tortor fringilla sed, vestibulum id, eleifend justo vel bibendum sapien massa ac turpis faucibus orci luctus non, consectetuer lobortis quis, varius in, paragraph.</p>
</div>
Using LESS
You guys made me think a bit more outside of the box, so I came out with my own ugly solution.
My idea is to add a bunch of extra square elements and calculate its size:
.loop(#i) when (#i > 0){
.loop((#i - 1));
.space#{i}{
width: floor(#i*#hSize/(1/tan(5deg)));
}
}
#hSize: 15px;
.space {
float: left;
clear: left;
width: #hSize;
height: #hSize;
}
HTML:
<p>
<span class="space space1"></span>
<span class="space space2"></span>
<!-- (...) -->
<span class="space space11"></span>
Lorem ipsum dolor sit amet. Vestibulum commodo volutpat a, convallis ac, laoreet enim. Phasellus fermentum in, dolor. Pellentesque facilisis. Nulla imperdiet sit amet magna. Vestibulum dapibus, mauris nec malesuada fames ac turpis velit, rhoncus eu, luctus et interdum adipiscing wisi. Aliquam erat ac ipsum. Integer aliquam purus. Quisque lorem tortor fringilla sed, vestibulum id, eleifend justo vel bibendum sapien massa ac turpis faucibus orci luctus non, consectetuer lobortis quis, varius in, paragraph.
</p>
Proof of concept: http://codepen.io/Tymek/pen/jEypOX?editors=110
#chipChocolate.py, it was just a matter of principle for me NOT to use JavaScript for this. If anyone wants to write JS/jQuery code based on my solution, you're welcome. Please share it here afterwards.
WARNING: The shape-outside property should not be used in live projects1. This answer is here just to show how the desired output can
be achieved with this property.
Here is an example using the shape-outside property (modern webkit browsers only) :
DEMO
img {
display: block;
float: left;
transform: rotate(-5deg);
margin: 0 20px;
-webkit-shape-outside: polygon(0 3%, 85% -3%, 100% 97%, 15% 103%);
shape-outside: polygon(0 3%, 85% -3%, 100% 97%, 15% 103%);
}
<div>
<img src="http://placehold.it/150x250&text=img" alt="image" />
<p>Lorem ipsum dolor sit amet. Vestibulum commodo volutpat a, convallis ac, laoreet enim. Phasellus fermentum in, dolor. Pellentesque facilisis. Nulla imperdiet sit amet magna. Vestibulum dapibus, mauris nec malesuada fames ac turpis velit, rhoncus eu,
luctus et interdum adipiscing wisi. Aliquam erat ac ipsum. Integer aliquam purus. Quisque lorem tortor fringilla sed, vestibulum id, eleifend justo vel bibendum sapien massa ac turpis faucibus orci luctus non, consectetuer lobortis quis, varius in,
paragraph.</p>
</div>
1The CSS Shapes Module Level 1 actually (mai 2016) has the status of "Candidate Recommendation". As this means it is a work in progress, it may change at any moment and therefore should not be used other than for testing.
The same layout could be achieved with the shape-inside property and specify a containing box for the text but no browser I know of supports this property today.
For a cross browser approach please see Tymek's answer.
img {
display: block;
float: left;
transform: rotate(-5deg);
margin: 0 15px;
}
p {
transform: skew(6deg);
font-style: italic;
}
<div>
<img src="http://placehold.it/150x250&text=img" alt="image" />
<p>Lorem ipsum dolor sit amet. Vestibulum commodo volutpat a, convallis ac, laoreet enim. Phasellus fermentum in, dolor. Pellentesque facilisis. Nulla imperdiet sit amet magna. Vestibulum dapibus, mauris nec malesuada fames ac turpis velit, rhoncus eu,
luctus et interdum adipiscing wisi. Aliquam erat ac ipsum. Integer aliquam purus. Quisque lorem tortor fringilla sed, vestibulum id, eleifend justo vel bibendum sapien massa ac turpis faucibus orci luctus non, consectetuer lobortis quis, varius in,
paragraph.</p>
</div>
I can't give you a code example, this is more complicated than a skew transform.
You must parse the text and the related DOM contained in it and look for each new lines of text (not br or \n but each first character of every rendered line).
With this information you can add a padding-left calculated from the images position and dimension.
How to apply alternate background color to multi column layout based on column count.
In the above link, if u see all the column background is blue, i want to give alternate background color of white & blue
HTML
<div class="container" id="container">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus aliquam commodo vestibulum. Duis in risus auctor, posuere elit a, interdum nunc. Vivamus nisl velit, vehicula ut ornare ac, mollis sit amet lectus. Praesent volutpat erat sem, id accumsan arcu tempor et. Quisque elementum leo sed elit volutpat, cursus dapibus lorem bibendum. Vivamus porta, elit sed facilisis tincidunt, enim diam suscipit metus, sit amet tincidunt ipsum augue id erat. Duis eget mi enim. Donec volutpat metus ut lacus iaculis cursus et eleifend orci. Vestibulum sollicitudin nibh sit amet laoreet dignissim. Pellentesque vulputate, leo eu commodo imperdiet, felis ante faucibus mi, vitae bibendum velit ipsum id arcu. Praesent a rhoncus quam, vel viverra elit. Nullam tellus velit, porta eu interdum quis, porttitor sed elit. Pellentesque egestas nisi odio, eget placerat nibh rhoncus id.</p>
<p>Vestibulum ante risus, placerat at egestas sit amet, interdum rhoncus leo. Donec libero nunc, aliquam aliquet massa non, fringilla consectetur est. Proin sodales vehicula ante pretium mollis. Proin laoreet vel dui a elementum. Pellentesque et ante odio. Cras commodo nisi sit amet mi pharetra, quis rhoncus tortor sodales. Etiam rhoncus orci nibh, id tincidunt nisi semper non. Quisque a imperdiet purus. Maecenas malesuada quis libero eu viverra. Proin eu diam accumsan, rutrum turpis eget, fermentum diam. Integer sem enim, hendrerit rhoncus suscipit sit amet, rutrum id lectus.</p>
<p>Suspendisse potenti. In hac habitasse platea dictumst. Suspendisse potenti. Phasellus leo tortor, vestibulum vel odio sed, tincidunt dictum urna. Ut ullamcorper lobortis lacus, at tristique massa posuere vel. Proin aliquam quam tellus, elementum suscipit mauris elementum nec. Proin aliquet quam ligula, sed vulputate nisl sodales sed. Sed erat turpis, iaculis ac nulla eu, dapibus adipiscing elit. Fusce adipiscing nunc mi, ac tempus nunc interdum gravida.</p>
</div>
CSS
.container {
background-color: blue
color:#000;
margin:20px auto;
padding:20px;
position:relative;
width:800px;
border-radius:5px;
box-shadow:1px 1px 5px #111111;
/* column specific styling */
column-count: 3;
column-gap: 3em;
column-rule: 1px dashed black;
}
This is a SERIOUS HACK, but as long as you have a fixed width container, it should do what you need.
I don't have time to fiddle with the widths, but if you spend the time, you "could" theoretically use a gradient with hard edges to achieve the desired result. It will also help if you use the dashed column-rule to hide/obfuscate the blurred line between containers.
http://jsfiddle.net/r8G2X/2/
.container {
background-image: -webkit-gradient(
linear,
right top,
left top,
color-stop(0.67, #324FA2),
color-stop(0.66, #51C26F),
color-stop(0.33, #7091EA),
color-stop(0.34, #51C26F)
);
color:#000;
margin:20px auto;
padding:20px;
position:relative;
width:800px;
box-shadow:1px 1px 5px #111111;
border-radius:5px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
column-count: 3;
-moz-column-count: 3;
-webkit-column-count: 3;
column-gap: 3em;
-moz-column-gap: 3em;
-webkit-column-gap: 3em;
column-rule: 1px dashed black;
-moz-column-rule: 1px dashed black;
-webkit-column-rule: 1px dashed black;
}
EDIT: So, you have many divs / columns and you want every other one to be a different colour?
Assign the element a class and use similar to what I put below. You then just give every other element the class that dictates the colour
<div id="white">some stuff</div>
<div id="black">some other stuff</div>
CSS:
#white{
background:white;
}
#black{
background:black;
}
Is that what you mean? ONe div is one colour and another is something different or sis you mean something else?
This may not work in your particular case but would you consider applying a background image behind the container? For a three column layout, the background image would consist of three bands of colour (primary colour, alternate colour, primary colour), etc. For a different number of columns, you would use a different background image. Then just use a class on the containing to specify which should be loaded. To keep the image size down and accommodate any height of column, use a vertically repeating background image.
This assumes that you know the width of each column of course, so for a responsive website might not work. But, on paper at least, I think that would work…
I would like to know how to make my text wrap properly when zoomed out in a browser? I mean the page looks fine when normally zoomed but when you zoom out by pressing Ctrl + "+" then it overlaps over the image on the right side of it. I have tried the white-space:nowrap but it doesn't give me the results I want. Can any of you please help me out?? Been trying to solve this for quite a while now also to help you guys better understand I have attached an image of how it looks like.
HTML:-
<p class="aboutus-description">
Integer tristique consequat nulla, sed convallis urna dictum sit amet. Ut at ligula dolor, id cursus sem. Nullam sed dolor eu.
Ut ante nunc, posuere ac varius sit amet, bibendum non est. Morbi in arcu in felis pharetra sodales vitae non.
Sed dictum cursus leo, sit amet semper est commodo in. Etiam.
Nunc elit sem, bibendum ac laoreet quis, accumsan sed neque. Integer lacus nisi, lobortis faucibus ornare non, cursus non augue. Suspendisse.
Vivamus hendrerit laoreet mauris ut molestie. Nullam auctor nulla ac ligula viverra nec adipiscing tellus eleifend. Duis ligula enim, semper eget
Vestibulum erat diam, cursus ut semper sit amet, feugiat a erat. Praesent vestibulum, quam ac.
Maecenas non risus dictum neque sodales commodo sed quis massa. Morbi mollis, odio.
CSS:-
<style>
#content p.aboutus-description
{
font-family:Arial, Helvetica, sans-serif;
font-size:10pt;
color:#656565;
position:absolute;
left:80px;
top:20px;
width:747px;
overflow-style:auto;
white-space:nowrap;
word-wrap:break-word;
}
Image:-
you can do this by float:left; to the content and float:right: to the image
and remove the position:absolute from #content p.aboutus-description
I'm building a 3 row liquid layout. I have a fixed height header and a footer. I also have a minimum width for the wrapper (for these 3 rows).
The problem is, I can't make the middle one (#content) resize vertically. If I make position:absolute then I lose control over scrolling. I thought I could do it using the top,bottom,margin and padding while setting the height to 100% but I couldn't.
Here's the code that I'm using to test it and here's the fiddle link: http://jsfiddle.net/inhan/kUZgY/ You will see that the lighter gray background won't expand when window is resized.
I'm willing to use CSS only and not use HTML5 features. What am I missing? Thanks for any input.
CSS
body {
margin:0;
padding:0;
border:0;
height:100%;
max-height:100%;
}
* html body { /*IE6 hack*/
padding:30px 0;
}
* html #content { /*IE6 hack*/
height:100%;
width:100%;
}
#wrapper {
width:100%;
min-width:800px;
min-height:100%;
position:absolute;
}
#header, #footer {
position:absolute;
left:0;
width:100%;
height:30px;
overflow:hidden;
background-color:gray;
color:white;
}
#header {
top:0;
}
#footer {
bottom:0;
}
#content {
margin:31px 0;
overflow:hidden;
width:100%;
background:rgba(0,0,0,.2);
}
HTML
<body>
<div id="wrapper">
<div id="header">This is header</div>
<div id="footer">This is footer</div>
<div id="content">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi commodo, ipsum sed pharetra gravida, orci magna rhoncus neque, id pulvinar odio lorem non turpis. Nullam sit amet enim. Suspendisse id velit vitae ligula volutpat condimentum. Aliquam erat volutpat. Sed quis velit. Nulla facilisi. Nulla libero. Vivamus pharetra posuere sapien. Nam consectetuer. Sed aliquam, nunc eget euismod ullamcorper, lectus nunc ullamcorper orci, fermentum bibendum enim nibh eget ipsum. Donec porttitor ligula eu dolor. Maecenas vitae nulla consequat libero cursus venenatis. Nam magna enim, accumsan eu, blandit sed, blandit a, eros.<br/><br/>Quisque facilisis erat a dui. Nam malesuada ornare dolor. Cras gravida, diam sit amet rhoncus ornare, erat elit consectetuer erat, id egestas pede nibh eget odio. Proin tincidunt, velit vel porta elementum, magna diam molestie sapien, non aliquet massa pede eu diam. Aliquam iaculis. Fusce et ipsum et nulla tristique facilisis. Donec eget sem sit amet ligula viverra gravida. Etiam vehicula urna vel turpis. Suspendisse sagittis ante a urna. Morbi a est quis orci consequat rutrum. Nullam egestas feugiat felis. Integer adipiscing semper ligula. Nunc molestie, nisl sit amet cursus convallis, sapien lectus pretium metus, vitae pretium enim wisi id lectus. Donec vestibulum. Etiam vel nibh. Nulla facilisi. Mauris pharetra. Donec augue. Fusce ultrices, neque id dignissim ultrices, tellus mauris dictum elit, vel lacinia enim metus eu nunc.
</div>
</div>
</body>
Extra Info
I'm actually not really interested in setting a minimum width for the whole page but some middle content will need that. So if I can, I might wanna make the whole structure respect when there's min-width property in the content that is loaded.
This should be what you're after http://jsfiddle.net/kUZgY/6/
You were just missing html {height:100%;}
I also changed the #header and #footer to position:fixed