The behavior of nematic liquid crystals in spatially varying electrical fields is investigated. Director profiles of nematic-liquid-crystal phase gratings are simulated for different orientations of the liquid-crystal director field with respect to the electrode grating. With increasing spatial frequency of the grating the fringing electric field becomes important and the diffraction pattern changes. The optical properties are analyzed and measurements are performed.