In this document, I use some results of my research activities of the last ten years to show the power of x-ray magnetic dichroism for determining magnetic properties of thin layers, multilayers and nanostructures. The use of sum rules for x-ray dichroism allows a quantitative determination of the spin and orbital contributions to the magnetic moment, for each element of a heterogeneous material separately.Used in a qualitative way, x-ray dichroism allows monitoring the magnetization of the different layers in a multilayer as a function of applied field. In combination with the temporal structure of synchrotron radiation, it is possible to study fast magnetization reversal with element selectivity, which is important for devices like spin valves and magnetic tunnel junctions. Adding the spatial resolution of a photoelectron emission microscope (PEEM), it becomes possible to study all the details of the fast magnetization reversal in complex magnetic systems.