I did a day trip from Algeciras having arrived from Morocco the day before. There are regular buses to La Linea (last stop before the Spanish-Gibraltar border) from Algeciras - duration maybe 20-30 mins. From the bus station in La Linea you can walk to and cross the border within 5 minutes. It's a bit of a thrill to walk across Gibraltar's runway. A further 20 minute walk and you're in downtown Gibraltar and can access a few entrances to the Rock of Gibraltar, a protected area that requires a small entrance fee. Lots of wartime attractions and of course the macaques (monkeys) at the top of the rock are entertaining. You can take driven tours of the rock if you wish, but I found it better to spent 4-5 hours walking around myself. Much better.