Control over the composition, shape, spatial location and/or geometrical configuration of semiconductor nanostructures is important for nearly all applications of these materials. Here we report a mechanical strategy for creating certain classes of three-dimensional shapes in nanoribbons that would be difficult to generate in other ways. This approach involves the combined use of lithographically patterned surface chemistry to provide spatial control over adhesion sites, and elastic deformations of a supporting substrate to induce well-controlled local displacements. We show that precisely engineered buckling geometries can be created in nanoribbons of GaAs and Si in this manner and that these configurations can be described quantitatively with analytical models of the mechanics. As one application example, we show that some of these structures provide a route to electronics (and optoelectronics) with extremely high levels of stretchability (up to approximately 100%), compressibility (up to approximately 25%) and bendability (with curvature radius down to approximately 5 mm).