Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Anchor Tags and Style Formatting

Hello! I would like to create the exact same page as the original except for the large car image also being a link to a car start sound. The problem I have with this is the formatting that goes along with the <a> tag. If I want to anchor some images that are big and some are small, but I have to use the same <a> tag for each, it affects the formatting and makes all the images the same size. How can I get around this?

Again, I would like the big car image to also link to a sound, but to remain a bigger size than the other buttons on the page. Thanks!!

1 Answer

Steven Parker
Steven Parker
222,348 Points

You might use a class to style the anchor images differently.

For example, you could create a "full-size" class to give the car a different width (and float setting) than the other links:

index.html
  <!--Car image -->
  <a href="javascript:revEngine();" class="full-size"><img src="images/car1.png" class="car" alt="car"></a>

  <!--Buttons-->
  <a href="javascript:startCar();"><img src="images/key.png" alt="key"></a>
  <a href="javascript:honkHorn();"><img src="images/steering-wheel.png" alt="steering wheel"></a>
  <a href="javascript:peelOut();"><img src="images/nos.png" alt="nos"></a>
style.css
/* Links */
a {
  background: transparent;
  border: 0;
  display: block;
  float: left;
  margin: 0;
  outline: 0;
  padding: 0;
  width: 33%; 
}
.full-size {
  float: none;
  width: 100%; 
}