[Best recipe is currently at the end of DOCthumbnail] This file is not only about cropping of pics, but also: a) Positions, sizes. b) img clipping, cropping, c) flow, align, .... Postioning d) img size control: see file "DOCimgsize" Also: DOCimgPDF says how to show pdf docs as/like IMGs; perhaps clipped. --------------------------------------------- I will try to distinguish 2 complementary types of doc here: What a CSS construct does e.g. "CSS-clip" How to impl. natural effects / functions e.g. "FN-floating imgs" =========== a) POSITIONS =========== LR (left/right) and top/bot (TB) are quite different. Normally text is wrapped and left/right constraints are mostly about other things (window width etc.), while consuming as much top/bot space as required. So html-ALIGN and css-float are about L-R. css-position: absolute/ fixed/relative/static/inherit static [default] - in text order. I.e. being wrapped. inherit - from parent absolute - rel. to its ancestor fixed - rel. to window relative - rel. to the position it's been put in so far by styles But the space for it is left reserved in the flow/wrap. http://www.w3schools.com/css/css_positioning.asp This (position) is actually really a meta-constraint: affecting mostly wrapping; and really affecting whether constaints on real position are solved BU or TD; actually: outermost (hier-top) inwards [TD] vs. innermost (hier-bot) outwards. i.e. from actual size needed for smallest elements or from fixed sizes passed TD. The 2 big cases are static= part of wrapping; and the rest. They ignore each other and will overlap. Position is typically spec. by CSS- top, right, bottom, left i.e. edges not corners. Height/width are relationships/constraints between 2 properties of the object: height = bottom-top. In my cropping method, I have to spec. the offset (the bit of the IMG to show) using -ve nmbs because this isn't saying: start the img +x, +y rel. to the IMG's ref. frame BUT is saying position the IMG at =-x,-y relative to the container's top,left (i.e. out of sight). CSS-z-index e.g. img { position:absolute; left:0px; top:0px; z-index:-1; } bigger the nmb. the more "over" it is. Only works on objects with "position" i.e. not being wrapped. =========== b) CLIPPING / CROPPING =============== FN-position an IMG: position: absolute; top:0; left:0; Sets pos. rel. to container. FN-scale an IMG: width:50; fixes width, scales proportionally FN-float1 an IMG i.e. have it seem to hover over text: FN-float1a Getting transparency so can see superposed objects. Get them superimposed, probably with transparency. opaCITY:0.6; // for the upper object: an IMG or a text DIV. Set a top IMG with opacity; and perhaps img:hover{ opacity:1.0; } Set a top text-DIVobject with opacity; and bg-color white. (But don't set the text/font as having opacity.) FN-float1b Getting text over an image The demo gets text over an img by having the img as bg to a DIV; and the text inside the DIV (w/w/o its own inner DIV). FN-float1c Getting an image over text. Transparent img. Move it back over the text from its rendered pos. Text first (in html) then img. Img {position: absolute; top:0; left:0;} ; this moves the IMG back to start of container, and over the text. FN-float2 an IMG i.e. have it seem to stay with the window while scroll moves text under it. Solution: set object style='position:fixed;' and it stays in the position rel. to window in which it is first rendered. BUT if that pos. is out of sight you can never scroll down to it. FN-crop an IMG: Usually best answer is to crop it in Preview and save new jpeg. Otherwise: ... Use two nested objects eg. SPAN and IMG inside (For both outer & inner objs: position: [anything not 'static']; Seems default is OK) *For outer/container, set overflow:hidden/auto/scroll; Set container size with width,height: this sets size of crop=visible. Set crop location within the original whole IMG by offsetting inner -- margin-top: -40; margin-left:-50px; This puts top/left of displayed pic 40-50 px down-right of actual pic-file's topLeft; i.e. discards part. You set top-left start of crop with -ve margins in Inner; then set bot-left = size of visible crop with height,width in outerSPAN Can have surrounding href: do A < SPAN < IMG; Leave no space between (or get unwanted UL spaces); Use a border in SPAN with color set to implicitly inherit (from ). Have to do it in SPAN not IMG with cropping (or border would be cropped away). Have to do this in css not HTML because property border not defined for SPAN in HTML? To get link color inherited MUST define border, but must NOT define color explicitly even with 'inherit' value. border: 3px solid; (Set the DIV "display:inline-block;" in order to get the img box to flow with surrounding other objects, text, etc. But have to use SPAN anyway, so no need.) Where I have said DIV use SPAN because that inherits border-color from links, while DIV does not. However it seems to inherit "visited" link color regardless, if you give no colour; but "unvisited" link color regardless if you give it the color "inherit". Can (and usually need to) scale the original image: use width: (say) on innerIMG, and it scales proportionally before the clipping. Can magnify, but of course the resolution isn't worth it. Can have oval not sq. shape by having on outerSPAN border-radius:50%; The full rect. of the clipping remains click-sensitive. Can't do width, height in innerIMG. Can do width, height in outerSPAN; doesn't scale, crops RH,Bot using them BORDER: Can't have border=3 on innerIMG: it just gets pic, adds border THEN does crop, cutting out some or all of border. And this happens too if on div but oval, in Safari not Firefox. So: set the SPAN to have a border but spec no colour and it inherits. EXAMPLE PROCEDURE: Install the following skel code. Progressively activate Q1,2,3,4,5 in steps, adjusting as required. 0) Set SPAN's float: left/right and margin-right/left Del. surrounding DIV (unless inside
  • ) 1) First inspect full pic and decide whether to scale it, by judging whether the area of the pic you want is at the right scale for after cropping: adjust Q1 to get this. 2) Adjust Q2,3 to crop top and left of portion to remain visible 3) Fix bot and right of the crop by (relative) Q4,5. Instrs: *Copy all this. *Delete surrounding DIV unless inside a
  • list. *Don't use the Q10 rotate class for the IMG, only? in SPAN. *The outer HREF may be either an alt. home page or a larger version of the pic; or an alternative pic. *Use the clear:both above and below when doing thumbnails and text beside them. * Use extra
    in front of the text if it's too little to wrap and needs pushing down from upper top edge of pic
    photo
    Note: 1) SPAN not DIV. The border is not from IMG (rounding hides that anyway), but from SPAN. SPAN will inherit color from , at least if you create a border but spec NOTHING not even 'inherit' as a border-color. 2) The cropping doesn't work unless either: a) set SPAN's float: left/right b) set SPAN's display:inline-block SO: it doesn't work within an
  • bullet list. 3) Surround the whole with a
    to make it work in
  • lists. 4) Use my css class .clear to get auto-clearing of floats/text.
    Also: I detect
  • followed by div.clear and suppress LF. 5) What do I have to do to suppress the _underscore prefixing text following the IMG? Seems to have gone with my latest recipe for auto-clearing: dunno why. But alt. technique than above (a): b) -ve margins on the IMG; and a parent element with definite fixed width. c) Parent has definite ht, width; and position:relative; img child has position:abs, and fixed top:, left: d) Actually use 'clip: x'; Inner has position:abs; clip:rect(); top:, left: set. Outer has position:relative, fixed ht/width. Can't change rel. scale of img. e) Outer is div, but set "background: url(file.gif) 50% 50% no-repeat; width:, height: and it crops it. The 50% is how you delect the sub-bit you want. Inner is (not IMG but) , with link if you click; and fixed ht/width (why?) and "display:block;" BUT I think that means no border changing colour? try it. Scaling? probably by rel. fixed sizes of inner,outer Or can't do it with (e)? f) use round
    and instead of img have div-background Doesn't do scaling of img. Click on img works. Border but no color-change with click FN-crop an IMG (2): Should redo above after tests. Should consider sequence in how to tune it manually for each IMG; and consider what units best in each param: %, px, ... Should scale underlying pic first, but with % width?? BUT % width in IMG does scale but leaves width undet., so get border done to full width of window. TEXT FLOW ROUND PICS, AGAIN 3) Text flow round pics: To get text flow round an IMG, use either CSS 'float:left' or HTML ALIGN Can apply CSS to surrounding , or to inside, or to IMG; but ALIGN only to IMG not . Need to do it to ALL imgs you want to go left of text. ALIGN (?not allowed in HTML5) ADDING TEXT LABELS / LEGENDS to IMGs with surrounding I want to suppress the application of link/visited colour and underline to the text, but keep them for the border round the IMG. HTML
    doesn't help. A wrinkle is that css now won't suppress info on visited that isn't on link. 1) Add a style, via a special class, to the to suppress underline (text-decoration:) for both links and visited links. 2) Change text color just in a surrounding the legend-text. style="color:initial;" ================== ROTATE imgs (or DIVs) style="-webkit-transform: rotate(90deg);" FN-bg imgs 'background' is a shortcut CSS property body,div { background: url(./Resources/Images/banner.jpeg) no-repeat scroll center top transparent; height: 100px; } CSS-opacity: (transparency). opacity:0.5; any number 0-1, but must say '1.0' img:hover{ opacity:1.0; } div { opacity:0.5; } =============== c) ALIGN (css-float) ============ FN-text flow round an IMG: 0. Still can't get full control i.e. of vertical centering except by putting in a table (see my flow HTML demo page); though can get table effect by setting container "display:table;" and inner "display:table-cell" without etc. 1. "float: left/right" gets basic ALIGN behav rel. to text. 2. Set margin on IMG on side where text will be to give some separation e.g. "margin-left:1em; float:right; " 3. Do captions not by tables but by:
    caption text
    ; and have DIV do a different text/font style; and do the float: on the DIV not the IMG direct; and set the margin on the DIV not IMG too. 4. Combine the flow text and IMG div in a table cell (virtual or real); and ensure the "cell" has vert. centering set -- "vertical-align: middle". Aligning img right or left is done here not by float but by whether it is textually before or after the flow text. 11. html-CENTER: set left and right margins of the obj/img to 'auto'. margin-left: auto; margin-right:auto; (Doesn't wrap text on both sides.) 12. CSS-vertical-align: middle; If you do this to IMG it controls only how super/sub the img sits in the line of text it is in. But if you do this in container, then ... 13. FN-vertical align: set container 'display:table;' and inside element(s) 'display:table-cell;' (spans, not IMGs so wrap IMG in a span) 14. Text both sides. If you put text - IMG - text AND do (13) then you get text both sides, each separately vert-centered. Wrap each bit of text and the IMG inside a : span {vertical-align:middle; display:table-cell; } And the L-R pos. of the IMG depends on rel. amounts of text in the two lots. ----------- img {margin-right:1em; vertical-align: middle} leaves a problem: following the recipes, doesn't make it work right. At least, the surrounding DIV does not enclose the IMG. Solved by: at the end. If you set img{ vertical-align: middle} you get only one line of text, with IMG sitting in it like a word; and where in text IMG is, is maintained. Recipe:
    text1 ... text 2
    Really, to get the effect of vert. centring AND both IMG and text, then you need to put them in a table, and CSS treats tables differently for vert. centring; float: becomes irrelevant: it's just controlled by having IMG first (left) or last (right) w.r.t. the text. Text flow round pics: [as above] To get text flow round an IMG, use either CSS 'float:left' or HTML ALIGN Can apply CSS to surrounding , or to inside, or to IMG; but ALIGN only to IMG not . Need to do it to ALL imgs you want to go left of text. ALIGN (?not allowed in HTML5) Once you have marked the things you want to cling to one side, all others will flow round.
    lets you mark a later object e.g.

    as preventing any more flow and claiming full-width for itself. ----- ========= CSS-float,clip,.... right: xpx. It calculates where right border should be; then moves it left by xPX! or right by -xPX. So: a) bizarre reversal of +/- b) not use for normal align because it is rel. to parent win; and doesn't take account of width of IMG itself. css-FLOAT This is actually about (html-align) positioning an object left/right w.r.t. text being rendered. css-float: left/right/none/inherit [default none] css-clear: both/left/right/none/inherit Must put text to be wrapped AFTER the img/object which is floated. HTML-align (ALIGN is not allowed in HTML5, at least for IMG.) ALIGN can anyway probably only apply to DIV type objects e.g. to IMG but not to which has no border. CSS-clip: clip:rect (top, right, bottom, left) JAVA-object.style.clip="rect(0px,50px,50px,0px)" Must have position:absolute or fixed (not even relative) ?Actually: must have an ancestor which is fixed somehow. N.B. this will cut off the obj from wrapping, so text will probably overlap it. The visible portion is in the same pos. as it would be if unclipped. (Must?? have overflow: not visible? w3schools says so, but my browsers don't do that.) So it seems less good than my sol. for cropping because can't ctrl. pos. on screen so sensibly. ........... Actually clip isn't useful as you expect. It takes an object including borders etc., then clips. To actually clip an img: see FN-crop above. Answer is to crop it in Preview and save new jpeg. Get size from the jpeg and freeze it into the HTML to stop scaling. ........... CSS-overflow: hidden / scroll / auto / inherit / visible [default] hidden-> crop scroll-> Add 2 scrollbars even if not needed auto-> Add scroll iff needed. The browser that then determines this. inherit-> from DOM parent ----- =========== More URLs: http://www.w3schools.com/css/css_positioning.asp http://cssglobe.com/3-easy-and-fast-css-techniques-for-faux-image/ http://stackoverflow.com/questions/1156776/css-clip-and-absolute-positioning http://spigotdesign.com/crop-any-size-image-with-css/ https://css-tricks.com/snippets/css/clear-fix/ https://css-tricks.com/crop-top/ https://css-tricks.com/almanac/properties/f/float/