The SU-27 was designed to counter the F-4 Phantom and to some degree the F-15.
The F-18 extends from the light fighter competition which was the F-16,F-17, and F-20 flyoff. The Navy liked the YF-17 and contracted the F-18.
By this point in time, I believe the first SU-27s were already undergoing trials.
Funny point - the F-5 was actually a shock to the Soviets when they ran trials using captured models from Vietnam, and was a huge influence on both the MiG-29 and the Su-27 project goals. They were not expecting much given their assessment of the expensive and complicated F-4, but the F-5 mopped the floor with the MiG-17.