This paper focuses on the study of consensus for a team of agents with continuous dynamics in the presence of state constraints. Due to the existence of state constraints, most existing consensus algorithms cannot be applied directly and thus a novel consensus algorithm is proposed to deal with state constraints. The novel consensus algorithm is shown to guarantee consensus when a few conditions are satisfied. Then we study opinion dynamics for a team of stubborn agents. By introducing virtual agents appropriately, it is shown that the study of opinion dynamics for stubborn agents can be reformulated as consensus for cooperative agents in the presence of state constraints. Such a formulation is similar to the existing study on containment control with stationary leaders. Based on the existing results from containment control literature, the final team opinions can be derived efficiently. Finally, a generalized opinion evolution problem is considered when agents are stubborn and have state constraints. Some upper and lower bounds of the team's final opinions are obtained by using the comparison lemma.