Quinton de Kock struck his maiden Test half-century to leave South Africa on 331-7 at lunch on day two of their second Test against Sri Lanka.
The Proteas started the day on 268-5, with four wickets being lost in the evening session as Sri Lanka hit back.
De Kock (17) and Dale Steyn (0) resumed play for South Africa, but Steyn was only able to make three runs before Suranga Lakmal sent him packing at 290-6.
JP Duminy was brought in to partner De Kock, with the left-handed batsman striking a half-century off 86 balls, before being undone by Dilruwan Perera four balls later.
De Kock, meanwhile, left the field following a catch from Mahela Jayawardene, with Duminy and Vernon Philander at the crease when play resumes after lunch.