The S&P 500 and the Nasdaq closed lower, easing from record highs as hotter-than-expected inflation data.