Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS jQuery Basics (2014) Creating a Spoiler Revealer Perform: Part 2

Jim McQuarrie
Jim McQuarrie
10,597 Points

Button question

I am using this technique to hide and display in a slide down jQuery function. I have a button defined in jQuery as the class, but when I try and center the div it centers the button and my H3 and P text which I don't want as they are list items. What is the best way to target and center the button in the div element (I have a class) and only center the button while leaving the other things alone. I would add classes to each element but there must be an easier way. Here is the website http://www.myjamsite.com/education.html, I gave the button a width of 100% for now as you will see, but I have another issue as well, and that's the footer. The footer works great except for the JQuery prior to clicking the button wher it then rides up against the section. where it now comes up . Thanks,

//1, Hide courses
$(".courses section").hide();
//2, Add a button
$(".courses").append("<button>Click Here to Reveal My Courses</button>");
//3, When button pressed
$("button").click(function(){
  //3.1, Show courses next to the button clicked
  $("section").slideDown().show();
  //3.2, Get rid of button
$(this).remove();
});

button {
border:1px solid #25729a;
  -webkit-border-radius: 3px;
  -moz-border-radius: 3px;
  border-radius: 3px;
  padding: 55px 350px;
  margin-top: 50px;
  font-size: 2em;
  cursor: pointer;
  width: 100%;
  text-decoration:none; 
  display:inline-block;
  text-shadow: -1px -1px 0 rgba(0,0,0,0.3);
  font-weight:bold; color: #FFFFFF;
  background-color: #3093c7; 
  background-image: -webkit-gradient(linear, left top, left bottom, from(#3093c7), to(#1c5a85));
  background-image: -webkit-linear-gradient(top, #3093c7, #1c5a85);
  background-image: -moz-linear-gradient(top, #3093c7, #1c5a85);
  background-image: -ms-linear-gradient(top, #3093c7, #1c5a85);
  background-image: -o-linear-gradient(top, #3093c7, #1c5a85);
  background-image: linear-gradient(to bottom, #3093c7,#1c5a85) ;filter:progid:DXImageTransform.Microsoft.gradient
 (GradientType=0,startColorstr=#3093     c7, endColorstr=#1c5a85);
 }

Jim McQuarrie

can you paste in your jQuery and the CSS you are using with the button.

1 Answer

Cole Slankard
Cole Slankard
24,997 Points

Hey Jim,

There are many ways to solve this, but one would be to set the button element in your js.css to "display: block;" instead of "display: inline-block;". Then define a width instead of 100%, maybe 50% or use "rem"s to keep the site responsive. After the element is block and has a set width, you can use auto margins for centering. Change "margin-top: 50px;" to "margin: 50px auto;". Again, converting px to rem will allow your site to be more flexible. Consider using rem for font sizing as well. That way when the user's display dimensions change, not only will your container elements scale, your fonts will scale as well.

A good rem calculator would be https://offroadcode.com/prototypes/rem-calculator/ , and be sure to set a base font-size in pixels in your CSS file for the selector html like:

html { font-size: 16px; }

In this example, all rem calculations will be based off 16px.

Jim McQuarrie
Jim McQuarrie
10,597 Points

Thank you this makes sense