Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center Google Form with CSS

I embedded a google form on my site, which is wrapped inside a div. I try to center it with CSS, but it doesn't work. Is there a way to accomplish this task?

My code:

#googleForm {
	margin-left: auto;
	margin-right: auto;
}
<div id="googleForm">	
  <iframe src="https://docs.google.com/forms....></iframe>
</div>
like image 849
kulan Avatar asked Jan 23 '15 12:01

kulan


People also ask

How do you center align a form in CSS?

You can easily align form elements in the center using flex property in Tailwind CSS. Tailwind uses justify-center and items-center property which is an alternative to the flex-property in CSS.

How do I customize my CSS in Google forms?

Right-click any element in the Google Form and choose Inspect Element . Next, switch to the Styles panel and experiment with different styles for colors, padding, font-size and any other CSS property. You can then copy the CSS and paste it into the custom CSS section.

How do I center an object in CSS?

Like last time, you must know the width and height of the element you want to center. Set the position property of the parent element to relative . Then set the child's position property to absolute , top to 50% , and left to 50% . This just centers the top left corner of the child element vertically and horizontally.


1 Answers

You can add text-align: center to element with id googleForm. Also you can safely remove margin-left and margin-right:

#googleForm {
  /*margin-left: auto;/*
  /*margin-right: auto;*/
  text-align: center;
}
<div id="googleForm">
  <iframe src="https://docs.google.com/forms....></iframe>
</div>

If you want to use margin: 0 auto you have to set the width of the element:

#googleForm {
  width: 304px;
  margin: 0 auto;
}
<div id="googleForm">
  <iframe src="https://docs.google.com/forms....></iframe>
</div>
like image 183
Alex Char Avatar answered Sep 30 '22 05:09

Alex Char