ma

Basque country: a culinary journey through a food lover's paradise / Marti Buckley ; photographs by Simon Bajada

Browsery TX723.5.B36 B83 2018




ma

Genetics in the madhouse: the unknown history of human heredity / Theodore M. Porter

Browsery HQ755.35.P67 2018




ma

The chicken: a natural history / Joseph Barber with Janet Daly, Catrin Rutland, Mark Hauber & Andy Cawthray

Browsery SF487.B185 2018




ma

How to smash garlic & the patriarchy: a modern womxn's field guide

Browsery HD6073.H8 H69 2019




ma

On the future: prospects for humanity / Martin Rees

Browsery Q175.4.R44 2018




ma

Hanging out, messing around, and geeking out: kids living and learning with new media / Mizuko Ito, Sonja Baumer, Matteo Bittanti, danah boyd, Rachel Cody, Becky Herr-Stephenson, Heather A. Horst, Patricia G. Lange, Dilan Mahendran, Katynka Z. Martín

Browsery HQ799.2.M352 H36 2019




ma

The new mind readers: what neuroimaging can and cannot reveal about our thoughts / Russell A. Poldrack

Browsery RC349.D52 P65 2018




ma

Negative margins in CSS

I’m writing the Box Model chapter of the new book and came to the point where I had to treat negative margins. To my surprise, I found that there is no systematic treatment of negative margins anywhere. So I had to figure it out for myself. Below is my initial draft of the negative margin section.

The latest specification only says: “Negative values for margin properties are allowed, but there may be implementation-specific limits.” and leaves it at that. Not extremely helpful. MDN is mostly silent as well, and Rachel Andrew’s big overview article doesn’t mention negative margins at all.

That’s odd, especially since negative margins are a very old functionality that I might even have used in my very first CSS test somewhere back in 1998. (Unless I used position: relative; I can’t remember.)

But anyway, here is, apparently, the first-ever systematic treatment of negative margins in simple situations.

Negative margins in CSS

It is possible to give margins a negative value. This allows you to draw the element closer to its top or left neighbour, or draw its right and bottom neighbour closer to it. Also, there is an exception we’ll get to in a minute.

Here is our test element: a simple container with three paragraphs in it. Note that the paragraphs have a width of 250px. This is extremely important, due to the exception we’ll get to in a minute.

First paragraph with a bit of text in it to provide some content.

Second paragraph with a bit of text in it to provide some content.

Third paragraph with a bit of text in it to provide some content.

Negative margin-top and -bottom

To start, let’s give the first paragraph a -15px margin-bottom. Essentially, when the browser calculates the point where the second paragraph should start, it moves that point 15px upward. From then on the browser lays out all paragraphs as normal.

First paragraph with margin-bottom: -15px.

Second paragraph with a bit of text in it to provide some content.

Third paragraph with a bit of text in it to provide some content.

Therefore the second paragraph, being the bottom neighbour of the first one, is draw 15px closer to the first paragraph. The margin between the second and third paragraphs remains intact; the browser calculates it normally. Thus, the rest of the vertical rhythm is preserved.

This trick is useful for subtle tweaks, where the content of one element should slightly overlap the content of the one above it.

Now let’s give the second paragraph a -15px margin-top. As you see, this yields exactly the same effect. Again, the second paragraph is moved upward by 15px, and the subsequent paragraphs follow.

First paragraph with a bit of text in it to provide some content.

Second paragraph with margin-top: -15px.

Third paragraph with a bit of text in it to provide some content.

Margin collapsing

Also note that margin collapsing behaves different when you use negative margins. This, at least, is specified in CSS 2.1:

In the case of negative margins, the maximum of the absolute values of the negative adjoining margins is deducted from the maximum of the positive adjoining margins. If there are no positive margins, the maximum of the absolute values of the adjoining margins is deducted from zero.

In the last example, the first paragraph still has its default margin-bottom of 1em (Chrome; can’t find Firefox’s value).

Normally, the browser would take the first paragraph’s margin-bottom and the second one’s margin-top, figure out which one is larger, and apply that margin between the two, which would yield max(-15px,1em) = 1em. That’s not how it works, though.

In case of negative margins we take the absolute values of the two adjoining margins (15px for the second paragraph; 1em for the first), and deduct the smaller (15px) from the larger (1em). This yields about 1px (depending on the font size, of course).

Thus, negative margins are actually allowed to pull elements closer to their neighbours without being hindered by regular margin collapsing.

Now we treated negative margin-top and -bottom fully. It’s an occasionally useful effect.

Negative margin-left and -right

Negative margin-left and -right work the same, provided the element has a width. Here we apply margin-left: -10px and margin-right: 10px.

First paragraph with margin-left: -10px.

Second paragraph with margin-right: -10px.

Third paragraph with a bit of text in it to provide some content.

As you see, the first paragraph is now offset 10px to the left, while retaining its width. Thus, its right edge also moves 10px to the left.

The second paragraph with the negative margin-right is unaffected. The negative margin-right would influence any element to the right of the second paragraph, but there aren’t any.

To show negative margin-right in its full glory, let’s float the paragraphs, so that they have a right neighbour. Here is the reference element.

First paragraph with a bit of text in it to provide some content.

Second paragraph with a bit of text in it to provide some content.

Third paragraph with a bit of text in it to provide some content.

Now we’re going to sprinkle some negative margins on the paragraphs.

First paragraph with margin-right: -10px.

Second paragraph with margin-top: -10px.

Third paragraph with margin-bottom: -10px.

As you see, the second paragraph is now drawn 10px closer to the first one due to the first’s negative margin-right. This is exactly the same effect as with a negative margin-bottom.

Also note that the second paragraph has a negative margin-top, which means it is offset 10px upward. The third paragraph has a negative margin-bottom, which has no effect, since it does not have a bottom neighbour.

Remember: margin collapsing does not work on margin-left and -right; just on -top and -bottom. Therefore we do not have to worry about it in this case.

If we give the second paragraph a margin-left: -10px, the same happens. Just like with top and bottom, left and right are interchangeable for this effect.

First paragraph with a bit of text in it to provide some content.

Second paragraph with margin-left: -10px.

Third paragraph with a bit of text in it to provide some content.

So far, negative margin-left and -right behave exactly like negative margin-top and -bottom.

width: auto and negative margin-right

Now let’s change the behaviour of negative margin-right by giving the paragraphs width: auto. They do not have a fixed width any more; instead they fill up their parent element completely while respecting its padding. That’s how width: auto works.

The paragraph with margin-left: -10px is still offset 10px to the left, but its width grows. Thus, its right edge is not offset but stays where it is.

Reference paragraph

First paragraph with margin-left: -10px.

Second paragraph with margin-right: -10px.

Third paragraph with margin-left: -10px; margin-right: -10px

The negative margin-right now does the same thing. It offsets the paragraph’s right margin by 10px to the right, and the paragraph’s width increases, causing its left edge to stay where it is. This only happens when an element has width: auto. As we saw before, elements with a fixed width behave quite differently.

Finally, the third paragraph has both. Both its left and its right margins are offset by 10px, essentially negating the container’s padding: 10px;.

This is by far the most common use case for negative margins. You give a container a padding so that its contents have some breathing space. However, you want the header to span the entire container, ignoring the padding. Negative margins are the way to go.

This is a header

This is a regular content paragraph.

This is a regular content paragraph.

These are the header styles; the container has padding: 10px

h5 {
	margin-left: -10px;
	margin-right: -10px;
	padding-left: 10px;
	margin-top: 0;
	margin-bottom: 0;
	background-color: grey;
	color: white;
	/* no width, so defaults to width: auto */	
}

Again, this is only possible if the header has width: auto. Fortunately that’s the case in 99% of real-world use cases.

This is how negative margins behave in simple situations. Now that I established a baseline I can look into how they behave in flexboxes and grids.



  • CSS for JavaScripters

ma

Reports on mathematical physics [electronic resource].

Publisher Oxford ; New York : Pergamon.
Location World Wide Web
Call No. QC19.2




ma

Solar photovoltaic power optimization : enhancing system performance through operations, measurement, and verification / Michael Ginsberg

Ginsberg, Michael (Energy consultant), author




ma

Photovoltaic systems : design, performance and applications / Wassila Issaadi, and Salim Issaadi, editors




ma

Advances in thin-film solar cells / I.M. Dharmadasa

Dharmadasa, I. M., author





ma

Special functions and generalized Sturm-Liouville problems Mohammad Masjed-Jamei

Online Resource




ma

Contributions to mathematical statistics Kei Takeuchi

Online Resource




ma

Mathematical topics on representations of ordered structures and utility theory: essays in honor of Professor Ghanshyam B. Mehta / Gianni Bosi, María J. Campión, Juan C. Candeal, Esteban Indurain, editors

Online Resource




ma

Power in numbers: the rebel women of mathematics / Talithia Williams, PhD

Online Resource




ma

Singularities of mappings: the local behaviour of smooth and complex analytic mappings / David Mond, Juan J. Nuño-Ballesteros

Online Resource




ma

Quantum Riemannian geometry Edwin J. Beggs, Shahn Majid

Online Resource




ma

Subplane covered nets / Norman L. Johnson

Online Resource




ma

Polynomial one-cocycles for knots and closed braids / Thomas Fiedler

Dewey Library - QC20.7.K56 F54 2020




ma

101 careers in mathematics / Deanna Haunsperger, Robert Thompson, editors

Dewey Library - QA10.5.A15 2019




ma

A comprehensive introduction to sub-Riemannian geometry: from the Hamiltonian viewpoint / Andrei Agrachev (Scuola Internazionale Superiore di Studi Avanzati (SISSA), Trieste), Davide Barilari (Université Paris Diderot, Paris), Ugo Boscain (Centre Nat

Dewey Library - QA671.A47 2020




ma

Random matrices / Alexei Borodin, Ivan Corwin, Alice Guionnet, editors

Dewey Library - QA196.5.R3585 2019




ma

Model management and analytics for large scale systems / edited by Bedir Tekinerdogan, Önder Babur, Loek Cleophas, Mark van den Brand, Mehmet Aksit

Online Resource




ma

Probability and statistics for data science: math + R + data / Norman Matloff

Dewey Library - QA273.M38495 2020




ma

An introduction to mathematical proofs / Nicholas A. Loehr

Dewey Library - QA9.54.L64 2020




ma

Mathematical modelling, optimization, analytic and numerical solutions Pammy Manchanda, René Pierre Lozi, Abul Hasan Siddiqi, editors

Online Resource




ma

Morse index of solutions of nonlinear elliptic equations / Lucio Damascelli and Filomena Pacella

Dewey Library - QA614.5.D36 2019




ma

Curves for the mathematically curious: an anthology of the unpredictable, historical, beautiful, and romantic / Julian Havil

Dewey Library - QA483.H39 2019




ma

Understanding advanced statistical methods / Peter H. Westfall, Information Systems and Quantitative Sciences, Texas Tech University, USA, Kevin S.S. Henning, Department of Economics and International Business, Sam Houston State University, USA

Online Resource




ma

The cryptoclub: using mathematics to make and break secret codes / Janet Beissinger, Vera Pless

Online Resource




ma

Nonlinear dynamics of structures, systems and devices: proceedings of the First International Nonlinear Dynamics Conference (NODYCON 2019). / Walter Lacarbonara, Balakumar Balachandran, Jun Ma, J. A. Tenreiro Machado, Gabor Stepan, editors

Online Resource




ma

Decision making theories and methods based on interval-valued intuitionistic fuzzy sets Shuping Wan, Jiuying Dong

Online Resource




ma

Partial differential equations for mathematical physicists / Bijan Kumar Bagchi

Dewey Library - QC20.7.D5 B34 2020




ma

Algebraic graph theory: morphisms, monoids, and matrices / Ulrich Knauer and Kolja Knauer

Dewey Library - QA166.K53 2019




ma

Building Bridges II: mathematics of László Lovász / Imre Bárány, Gyula O.H. Katona, Attila Sali, editors

Online Resource




ma

From Lambda Calculus to cybersecurity through program analysis: essays dedicated to Chris Hankin on the occasion of his retirement / Alessandra Di Pierro, Pasquale Malacaria, Rajagopal Nagarajan (eds.)

Online Resource




ma

Fuzzy hypergraphs and related extensions Muhammad Akram, Anam Luqman

Online Resource




ma

Continuous semigroups of holomorphic self-maps of the unit disc Filippo Bracci, Manuel D. Contreras, Santiago Díaz-Madrigal

Online Resource




ma

Continuous and discontinuous piecewise-smooth one-dimensional maps: invariant sets and bifurcation structures / Viktor Avrutin (University of Stuttgart, Germany), Laura Gardini (University of Urbino, Italy), Irina Sushko (National Academy of Sciences of U

Dewey Library - QA614.8.A97 2019




ma

Reinforcement learning and optimal control / by Dimitri P. Bertsekas

Dewey Library - QA402.5.B465 2019




ma

The method of mathematical induction / I.S. Sominskii. Induction in geometry / L.I. Golovina and I.M. Yaglom

Dewey Library - QA9.S5813 2019




ma

Discrete mathematical structures: a succinct foundation / authored by B.V. Senthil Kumar and Hemen Dutta

Dewey Library - QA297.4.K86 2020




ma

Understanding Mathematical Proof.

Online Resource




ma

Nonlinear dynamics and control: proceedings of the first International Nonlinear Dynamics Conference (NODYCON 2019). / Walter Lacarbonara, Balakumar Balachandran, Jun Ma, J.A. Tenreiro Machado, Gabor Stepan, editors

Online Resource




ma

Zero-sum discrete-time Markov games with unknown disturbance distribution: discounted and average criteria / J. Adolfo Minjárez-Sosa

Online Resource




ma

Worked examples in mathematics for scientists and engineers / G. Stephenson

Dewey Library - QA43.S79 2019




ma

TriMathlon: a workout beyond the school curriculum / Judith D. Sally, Paul J. Sally, Jr

Online Resource




ma

Inverse Problems and Related Topics: Shanghai, China, October 12-14 2018 / Jin Cheng, Shuai Lu, Masahiro Yamamoto, editors

Online Resource