He was born Guibert of Ravenna in the 1020s. Family connections helped get him appointed to the Imperial chancellorship of Italy in 1058. The appointment came from Holy Roman Empress Agnes, mother and regent for the young Henry IV. In 1061, he supported Honorius II as pope instead of Alexander II. When Germany and Empress Agnes decided to support Alexander II as the one true pope, Guibert's support of Honorius was condemned and he was dismissed from the chancellorship.
Guibert was not completely out of favor: he kept contact with the German court, and when Henry IV became Holy Roman Emperor, he made Guibert Archbishop of Ravenna. Pope Alexander II was a little reluctant to confirm to a high position in the church a man who had opposed his papacy, but to keep peace with Germany he confirmed Guibert in 1073.
In that same year, Alexander died and Gregory VII became pope. Gregory tried instituting several reforms, among which were eliminating simony (purchasing appointments), making the clergy independent of secular courts and influence, and denying secular authorities the right to appoint clergy. Archbishop Guibert spoke out against these reforms, no doubt endearing him to Henry IV. Guibert refused to attend Gregory's Synod on these matters in 1075, so Gregory suspended him.
Emperor Henry IV was opposed to Gregory's reforms; his Synod of Worms in 1076 resolved that Gregory was deposed; several Transalpine bishops agreed. Gregory excommunicated them, including Guibert. The Transalpine bishops and prelates gathered in April 1076 with Guibert presiding and declared pope Gregory himself excommunicated.
In 1080, at a further synod in June, Henry declared Gregory deposed (again) and Guibert elected as Pope Clement III. Henry promised his new pope that he would march with his army to Rome and make the papal election official. He failed at first, but ... well, let's continue this tomorrow.