Should I give the first element a right margin or the second element a left margin? - alignment

This is a very basic CSS design question.
When I have two block-elements
+----------+ +----------+
|~~~~~~~~~~| |**********|
|~~~~~~~~~~| |**********|
|~~~~~~~~~~| |**********|
+----------+ +----------+
and I want to set the space between them, there are three possibilities:
Left block with right margin
Right block with left margin
Margin for both blocks
What are the pros and cons for each one and—most importantly—what is considered
best practice?

It is generally a good idea to choose a direction (margin-left OR margin-right) and to stick to it on the whole project so designing will be easier and more consistent.
For more on the subject you can read this blog post: Single-direction margin declarations
That said, margin-left on boxes means "I do not want to be too close to the box before me" while margin-right means "I do not want other boxes to be too close to me".
So on designs where boxes have a margin by default, use margin-right (and margin-bottom) and on designs where boxes have no margin by default, use margin-left (and margin-top) on the few boxes with a margin. If it is mixed, choose the direction that seems the most coherent to you and stick to it.

No pros and cons, it is totally on your design, what you want to go for, using margin-right will make the last element have margin-right for no good reason, so say for example, you have three boxes, floated to the left, or they are displayed inline-block so because of the right margin, the last box won't touch the extreme right of the template, instead it will wrap and move down.
Do you see the red space, it's margin-right for the last element, which you won't need. shifting it more will result your div to move down.
Solution?
If you are willing to support legacy browsers, assign a class to the last element and write margin-right: 0;, say you are having 3 li elements floated, so you will write
ul.class_name li.class_name {
margin-right: 0;
}
Else, you can use :last-child pseudo to get rid of the extra margin.
So it will be
ul.class_name li:last-child {
margin-right: 0;
}
Same thing will go for the left, but instead of using :last-child and margin-right you need to use margin-left and :first-child respectively.
Last but not the least, using margin on both sides, will create a space on both the sides, again, resulting in disorientation of your layout.
In the above case, you will have to use both, either assign class to first and last element, or you need to use :first-child and :last-child to get rid of margin on the left for first element and margin on the right for last element.
Conclusion: For the two boxes you have, you should use margin-right
and use a class or :last-child to remove the extra margin on the
last element.

It depends where you will use it and how you will use it there is no exact rule for this. However if you will use some grid system for elements it is best practice. If your element cannot be suitable for grid system you can use any approach.
P.S. And there is another possibility to use pseudo element after or before I guess.

Simple Answer: It depends
It all depends on what you are trying to do, and what elements are those.
For example, if your site is oriented to the left, and those are two floating divs, with the same class, you wouldn't want to use margin-left, because that will introduce some space on the left of the first block.
It obviously makes no sense to add margin to both elements, unless you have dynamic content that may appear in between.
So, other than the obvious styling manner that you want your page to have, there is no difference in performance, but mostly readability of your code

Related

What do "s" and "e" stand for in the Bootstrap 5 spacing utility classes?

Bootstrap 5 documentation for the spacing utility classes states:
Where sides is one of:
t - for classes that set margin-top or padding-top
b - for classes that set margin-bottom or padding-bottom
s - for classes that set margin-left or padding-left in LTR, margin-right or padding-right in RTL
e - for classes that set margin-right or padding-right in LTR, margin-left or padding-left in RTL
So, for a small bit of left padding, you'll use the class ps-1 in Bootstrap 5, where it used to be pl-1 in Bootstrap 4.
I assume they changed this so it would be less confusing for RTL languages, but I can't for the life of me think of what s or e would stand for. I'm never going to remember "s is left" without actually understanding what metaphor the s/e stand for.
So, what do s and e stand for?
Start
and
End
This is so to make using RTL simpler. In default LTR, Start is Left, and End is Right.
"I assume they changed this so it would be less confusing for RTL
languages, but I can't for the life of me think of what s or e would
stand for. I'm never going to remember "s is left" without actually
understanding what metaphor the s/e stand for."
As explained in Bootstrap docs...
"...replace direction properties like left and right in favor start
and end. That makes the class names and values appropriate for LTR and
RTL"

What is the meaning of "topmost" in the alMostTop alignment in TAlignLayout?

In the documentation for TAlignLayout, a type which addresses visual alignment settings for FireMonkey controls, I'm trying to figure out the difference between the alTop and alMostTop constants, the only difference is that the definition of alMostTop contains the phrase "set to be the topmost".
(The same goes for the constants alMostLeft, alMostRight and alMostBottom, which are distinguished from alLeft, alRight and alBottom with similar phrases using the words
"leftmost", "rightmost" and "bottommost".)
I don't know what "set to be the topmost" means, and none of the guesses I make seem to fit with observed FireMonkey behaviour:
If it means displaying that control on top (at the front of the display) relative to its siblings, then what does leftmost mean?
If "leftmost" means it is the sibling shown furthest to the left, out of all siblings that have a alLeft alignment, then why does the CustomListBox demo use a layout with two elements that have a alMostLeft alignment? How does it decide to place the two elements that particular way round?
The Embarcadero forums don't shed any light on this either.
[Update]
To be clear, experiments do indeed suggest that with two components aligned to the top, you can choose which one is to be further up the screen by setting that one to have alMostTop, and the other to alTop.
However, I thought of another possibility: suppose you have two child components, one to be aligned at the left, another aligned at the top. Then they will fight for ownership of the top-left corner. Experiments seem to suggest that some influence can be obtained by choosing between alTop and alMostLeft alignments for the two controls vs alMostTop and alLeft alignments. I can't see exactly what is going on here, and it's not clear in the documentation. It's also not clear what should/might happen if two child controls are both set to alMostTop.
When you have 2 (or more) controls aligned to top, the alMostTop will be on the top of all others. Same wise with alMostRight, alMostLeft, and alMostBottom.

removing space around components in blackberry

I have a gui that keeps scrolling on the 8520 screen. I have used setPadding(XYEdges) and setMargin(XYEdges) to remove the spaces around the components on the UI but there's still space left in between these components. Are there other API calls i can make to remove spaces around components?
You need to consider the following:
setPadding refers to a boundary inside the border of a field and controls how close the internal content of the field can be to the border.
setMargin refers to a boundary outside the border of a field and controls how close the field can be to an adjacent field on that edge.
BUT note that the margins of adjacent fields overlap, so that if field A has it's right margin set to 0, and right adjacent field B has it's left margin set to 20, then the two fields will still be placed no closer than 20 pixels apart.
i.e. you have to take into account the margins set for the edges of all adjacent fields.
Returning to padding, the same applies for managers if you set their internal padding. This will determine how close to the inside of the manager's border an included field can be placed.
Somewhere in the blackberry documentation and/or support forum, there is a document explaining this pictorially, I just can't find my link to it right now, but will post it here when I find it again.

CSS sprite position problem

I trying to create a fixed border to the site that dynamically change size with the browser window from this sprite (it isn't perfect I know.): http://fc07.deviantart.net/fs70/f/2011/269/7/0/bordersprite_by_nakos-d4ayzne.png
DEMO on jSFiddle
My problem as you can see is the vertical wall part. As the #falJ and #falB are height:100% they include the bottom wall's end too with the space between the two wall sprites. Is there a way to force backround-position to only use vertical wall part without bottom wall's end?
Thanks in advance.
Solution: http://jsfiddle.net/vonkly/Ld43B/
It's not the prettiest thing in the world, but it achieves what you want. Check out the source code & direct link for the background images to see what you'll need to do. It's currently set at 299px wide; I imagine you'll be using something wider.
I'd also suggest adding some padding around your content (either with a p tag, span, another div, etc.) - the way it is currently set up isn't what I'd recommend for readability.
EDIT
The only way I can imagine achieving a fluid width + height box with the borders that you have in the way that you want is to use a second image for the west and east containing divs. This should work with your current method.

How do I prevent LaTeX from padding spaces between paragraphs so that next section begins at top of next page?

I have a two-column paper where space restrictions are very tight.
I just looked at my last version of the manuscript and saw that the upper half contains a figure (as expected), but in the lower half there is a lot of vertical space between paragraphs (enough to squeeze 10 more lines), and that LaTeX probably added it so that in the beginning of the next page a new numbered section will begin at the top of the page.
I know there's a way to adjust this so LaTeX doesn't try so hard, but I'm not sure how. any help? Thanks!
The parameter that controls inter-paragraph spacing is called \parskip(See Paragraph Spacing ). You set it (with "rubber" values) using something like:
\setlength{\parskip}{1cm plus4mm minus3mm}
The defualt value of \parskip is class dependent. The "plus" and "minus" parts tell TeX how much it can adjust the value to improve the layout (that is they make the spacing elastic, thus the "rubber" designation). Reducing (or eliminating) the "plus" part of the rubber might help.
Watch out though, you can cause other layout artifacts if you constrain TeX too much.
Other things to think about:
The widow and club penalties probably apply section headings, and may be affecting TeX's layout choices (see https://stackoverflow.com/questions/512967/how-can-one-keep-a-section-from-being-at-the-end-of-a-page-in-latex for a discussion).
You may also want to consider messing with \baselineskip which controls the allowed spacing between lines of text and can also have rubber values.
This is a common problem, and there are probably some fairly sophisticated treatments already prepared on CTAN.
\vfill before the new section worked perfectly for me.

Resources