The Catholic Church teaches the dogma of the ever-virgin at conception of Christ, His birth, and life of Mary thereafter. The modern idea of whether one has sex or not to define one's virginity was only part of the whole.
The dogma of the ever-virgin Mary centers on the birth of Christ, rather than on her marriage with Joseph and what that might entail.
Scripture is clear that a virgin would conceive and bear (carry to term). All Christians believe that.
Therefore the Lord himself shall give you a sign; Behold, a virgin shall conceive, and bear a son, and shall call his name Immanuel. Isa. 7:14
The Catechism of the Catholic Church says this about the conception.
496 From the first formulations of her faith, the Church has confessed that Jesus was conceived solely by the power of the Holy Spirit in the womb of the Virgin Mary, affirming also the corporeal aspect of this event: Jesus was conceived "by the Holy Spirit without human seed".146 The Fathers see in the virginal conception the sign that it truly was the Son of God who came in a humanity like our own. Thus St. Ignatius of Antioch at the beginning of the second century says:
You are firmly convinced about our Lord, who is truly of the race of David according to the flesh, Son of God according to the will and power of God, truly born of a virgin,. . . he was truly nailed to a tree for us in his flesh under Pontius Pilate. . . he truly suffered, as he is also truly risen.147
497 The Gospel accounts understand the virginal conception of Jesus as a divine work that surpasses all human understanding and possibility:148 "That which is conceived in her is of the Holy Spirit", said the angel to Joseph about Mary his fiancee.149 The Church sees here the fulfillment of the divine promise given through the prophet Isaiah: "Behold, a virgin shall conceive and bear a son."150
The issue of Joseph and Mary's status of husband and wife and whether they consummated their marriage and subsequently who the brothers of the Lord were came third in the line of thinking about the dogma. Before that issue was the one of remaining a virgin even in the act of giving birth. Again, the issue of sex as the definition of virginity found no place here, but the traditional physical definition did.
CCC-499 The deepening of faith in the virginal motherhood led the Church to confess Mary's real and perpetual virginity even in the act of giving birth to the Son of God made man.154 In fact, Christ's birth "did not diminish his mother's virginal integrity but sanctified it."155 And so the liturgy of the Church celebrates Mary as Aeiparthenos, the "Ever-virgin".156
The Bible talks about the brothers of the Lord. To believe in the ever-virgin, one had to explain this. The earliest reference is that they were children of Joseph by a former wife. Later Jerome invented the cousin theory to explain them. In this way, he had both Mary and Joseph remaining virgins. The cousin theory is taught by the Catechism.
CCC 500 Against this [ever-virgin] doctrine the objection is sometimes raised that the Bible mentions brothers and sisters of Jesus.157 The Church has always understood these passages as not referring to other children of the Virgin Mary. In fact James and Joseph, "brothers of Jesus", are the sons of another Mary, a disciple of Christ, whom St. Matthew significantly calls "the other Mary".158 They are close relations of Jesus, according to an Old Testament expression.159
So, the Catholic Church teaches the perpetual virginity of Mary. She conceived and bore to term as a virgin, she gave birth to Christ as a virgin, she lived her whole life as a virgin.