see also gestation, embryology.
Narrated Anas:Wow! What scientific knowledge! The number of sahih hadiths relating this shows that this must have been a rather accepted fact among Muhammad's followers.When 'Abdullah bin Salam heard the arrival of the Prophet at Medina, he came to him and said, "I am going to ask you about three things which nobody knows except a prophet: ... Why does a child resemble its father, and why does it resemble its maternal uncle" Allah's Apostle said, "Gabriel has just now told me of their answers." 'Abdullah said, "He (i.e. Gabriel), from amongst all the angels, is the enemy of the Jews." Allah's Apostle said, "... As for the resemblance of the child to its parents: If a man has sexual intercourse with his wife and gets discharge first, the child will resemble the father, and if the woman gets discharge first, the child will resemble her." On that 'Abdullah bin Salam said, "I testify that you are the Apostle of Allah." ... (Sahih Bukhari 4.546. also Sahih Bukhari 5.275, Sahih Bukhari 6.7)
Science tells us that the sex of a baby is determined by the Y-chromosome of the father. A male has an XY pair of chromosomes while a female has an XX pair (there are some extreme exceptions like XXY, etc, but these are exceptions), and a sperm cell carries either the X or the Y chromosome, and the female egg carries the X chromosome. Thus, during fertilization, either an X or a Y chromosome of the father combines with an X chromosome of the mother, and the chromosome type of the sperm determines the sex of the baby.