为什么不对齐?

时间:2016-03-10 19:50:22

标签: css html5

My problem.

这是我的代码。我把它全部放进去,因为我不知道问题出在哪里;我知道应该在哪里, 对不起,如果我错了。

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
  display: block;
}
body {
  line-height: 1;
}
ol,
ul {
  list-style: none;
}
blockquote,
q {
  quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
  content: '';
  content: none;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}
/*
  ========================================
  Custom styles
  ========================================
*/

body {
  background: #130b3d;
  color: #888;
  font: 300 16px/22px"Century Gothic", Helvetica, Arial, sans-serif;
}
/*
  ========================================
  Grid
  ========================================
*/

*,
*:before,
*:after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.container {
  margin: 0 auto;
  padding-left: 20px;
  padding-right: 20px;
  width: 960px;
}
.col-1-3 {
  width: 33.33%;
}
.col-2-3 {
  width: 66.66%;
}
.col-1-3,
.col-2-3 {
  display: inline-block;
  vertical-align: top;
}
.grid,
.col-1-3,
.col-2-3 {
  padding-left: 15px;
  padding-right: 15px;
  padding-top: 20px;
  padding-bottom: 20px;
}
.container,
.grid {
  margin: 0 auto;
  width: 960px;
}
.container {
  padding-left: 30px;
  padding-right: 30px;
}
/*
  ========================================
  Clearfix
  ========================================
*/

.group:before,
.group:after {
  content: "";
  display: table;
}
.group:after {
  clear: both;
}
.group {
  clear: both;
  *zoom: 1;
}
/*
  ========================================
  Rows
  ========================================
*/

.row {
  background: #fff;
  min-width: 960px;
  padding: 0;
}
.row,
.row-alt {
  min-width: 100%;
}
/*
  ========================================
  Typography
  ========================================
*/

h1,
h3,
h4,
h5,
p {
  margin-bottom: 10px;
}
h1,
h2,
h3,
h4 {
  color: #7b7b7b;
}
h1 {
  font-size: 46px;
  line-height: 44px;
  margin-bottom: 6px;
}
h2 {
  font-size: 24px;
  line-height: 44px;
}
h3 {
  font-size: 21px;
}
h4 {
  font-size: 18px;
}
h5 {
  color: #a9b2b9;
  font-size: 16px;
  font-weight: 400;
}
strong {
  font-weight: 900;
}
cite,
em {
  font-style: italic;
}
/*
  ========================================
  Buttons
  ========================================
*/

.btn {
  border-radius: 5px;
  display: inline-block;
  margin: 0;
}
.btn-alt {
  border: 1px solid #dfe2e5;
  padding: 10px 30px;
}
/*
  ========================================
  Home
  ========================================
*/

.hero {
  line-height: 30px;
  padding: 18px 60px 46px 60px;
}
.hero h3 {
  font-size: 32px;
  text-align: center;
}
.hero h5 {
  font-size: 20px;
  text-align: center;
  color: #7b7b7b;
  font-weight: 400;
}
.teaser img {
  border-radius: 5px;
  display: block;
  margin-bottom: 22px;
  max-width: 100%;
}
/*
  ========================================
  Primary header
  ========================================
*/

.logo {
  text-align: center;
  font-size: 48px;
  line-height: 44px;
  padding: 40px 0 0 0;
}
.tagline {
  text-align: center;
}
.primary-nav {
  font-size: 18px;
  font-weight: 400;
  text-align: center;
  text-decoration: underline;
}
.primary-header a,
.primary-footer a {
  color: #fff;
}
.primary-header a:hover,
.primary-footer a:hover {
  color: #cdcdcd;
}
/*
  ========================================
  Primary footer
  ========================================
*/

.primary-footer small {
  text-align: left;
}
.primary-footer {
  text-align: center;
  padding-bottom: 10px;
  padding-top: 20px;
}
/*
  ========================================
  Links
  ========================================
*/

a:hover {
  color: #cdcdcd;
}
a {
  color: #7b7b7b;
  text-decoration: none;
}
/*
  =======================================
  Navigation
  =======================================
*/

.nav li {
  display: inline-block;
  margin: 10px 5px;
  vertical-align: top;
}
.nav li:last-child {
  margin-right: 0;
}
/*
  =======================================
  Aside
  =======================================
*/

.aside {
  float: left;
  max-width: 200px;
}
.form {
  float: right;
  max-width: 300px;
  margin-top: 40px;
  margin-right: 40px;
}
form {
  margin-bottom: 22px;
}
input,
select,
textarea {
  font: 300 16px/22px"Century Gothic", Helvetica, Arial, sans-serif;
}
.form-style label {
  color: #7b7b7b;
  cursor: pointer;
  font-weight: 400;
}
.form-style input,
.form-style textarea {
  border: 2px solid #eeeeee;
  border-radius: 3.5px;
  color: #888;
  display: block;
  margin: 0 0 5px 0;
  padding: 5px;
}
.form-style input,
.form-style textarea {
  width: 250px;
}
.form-style textarea {
  height: 78px;
}
.form h3 {
  margin-right: 20px;
  margin-top: 10px;
}
.aside h3 {
  margin-left: 50px;
  margin-top: 10px;
}
.aside img {
  border-radius: 5px;
  display: inline-block;
  margin-bottom: 10px;
  max-width: 47%
}
/*
  ==========================================
  About
  ==========================================
*/

.about {
  margin: 30px 30px 50px 30px;
}
.history {
  margin-left: 55px;
  margin-right: 55px;
}
.about h4 {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
}
.about h5 {
  text-align: left;
  line-height: 10px;
}
.about h6 {
  font-size: 16px;
}
.about img {
  border-radius: 5px;
  display: inline-block;
  margin-bottom: 10px;
  max-width: 12.5%
}
.about-img {
  margin-left: 155px;
}
/*
  ===============================
  Contact
  ===============================
*/

}
.map {
  margin-bottom: 33px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Event Technologies Ltd.</title>
  <link rel="stylesheet" href="assets/stylesheet/main.css">
  <meta name="viewport" content="width=device-width, initial-scale=1" />
</head>

<body>

  <header class="primary-header container group">
    <h1 class="logo">
	    <a href="home.html">Event Technologies</a>
      </h1>
    <h5 class="tagline">
	    Interactive Event Multimedia
	  </h5>

    <nav class="primary-nav nav">
      <ul>
        <li><a href="home.html">Home</a>
        </li>
        <!--
		  -->
        <li><a href="aboutus.html">About Us</a>
        </li>
        <!--
		  -->
        <li><a href="services.html">Services</a>
        </li>
        <!--
		  -->
        <li><a href="projects.html">Projects</a>
        </li>
        <!--
		  -->
        <li><a href="contactus.html">Contact Us</a>
        </li>
        <!--
		  -->
        <li><a href="vacancies.html">Vacancies</a>
        </li>
      </ul>
    </nav>
  </header>
  <aside class="aside">
    <h3>Our clients include:</h3>
    <img src="assets/images/home/virgin_logo.png">
    <!--
		  -->
    <img src="assets/images/home/willow_logo.jpg">
    <img src="assets/images/home/hsbc_logo.jpg">
    <!--
		  -->
    <img src="assets/images/home/home_office_logo.jpg">
    <img src="assets/images/home/land_rover_logo.png">
    <!--
		  -->
    <img src="assets/images/home/nissan_logo.jpg">
    <img src="assets/images/home/jaguar.gif">
    <!--
		  -->
    <img src="assets/images/home/capita_logo.jpg">
    <img src="assets/images/home/cancer_logo.png">
    <!--
		  -->
    <img src="assets/images/home/legion.gif">
  </aside>


  <aside class="form">
    <h3>Make an Enquiry</h3>
    <fieldset class="form-style">
      <label>
        Name:
        <input type="text" name="name" placeholder="Full name" required>
      </label>
      <!--
			-->
      <label>
        Email:
        <input type="email" name="email" placeholder="Email Address" required>
      </label>
      <!--
			-->
      <label>
        Company:
        <input type="text" name="company" placeholder="Company" required>
      </label>
      <!--
			-->
      <label>
        Enquiry:
        <textarea name="comments"></textarea>
      </label>
    </fieldset>
    <input type="submit" name="submit" value="Send">
  </aside>

  <section class="row">
    <div class="hero grid">
      <section class="teaser col-1-3">
        <h3>
		        <a href="services.html">Interactive iPads
		      </h3>
        <img src="assets/images/home/interactive.png">
        </a>
        <h5>Real-time audience feedback tools</h5>
      </section>
      <!--
		    -->
      <section class="teaser col-1-3">
        <h3>
		          <a href="services.html">Interactive Fundraising
		        </h3>
        <img src="assets/images/home/fundraising.jpg">
        </a>
        <h5>Maximise revenue potential at fundraising events</h5>
      </section>
      <!--
		      -->
      <section class="teaser col-1-3">
        <h3>
		             <a href="services.html">Bespoke Development
	               </h3>
        <img src="assets/images/home/bespoke.jpg">
        </a>
        <h5>Not looking for an off-the-shelf solution? No problem...</h5>
      </section>
    </div>
  </section>
  <footer class="primary-footer container group">
    <nav class="primary-nav nav">
      <ul>
        <li><a href="home.html">Home</a>
        </li>
        <!--
		  -->
        <li><a href="aboutus.html">About Us</a>
        </li>
        <!--
		  -->
        <li><a href="services.html">Services</a>
        </li>
        <!--
		  -->
        <li><a href="projects.html">Projects</a>
        </li>
        <!--
		  -->
        <li><a href="contactus.html">Contact Us</a>
        </li>
        <!--
		  -->
        <li><a href="vacancies.html">Vacancies</a>
        </li>
      </ul>
    </nav>

    <h5>Event Technologies Ltd.<br> Unit 10 Rotherbrook Court,<br> Bedford Road,<br> Petersfield,<br> GU32 3QG</h5>
  </footer>
</body>

</html>

(我知道如果你想呕吐它,还在学习)

我只是不明白为什么它不会与其他两个对齐。从我的观点来看,我看不出任何差异。

感谢您的帮助!

4 个答案:

答案 0 :(得分:0)

.hero .teaser h3 { min-height: 64px; }

调整像素以使其适合。

答案 1 :(得分:0)

尝试将float添加到您的部分。不要忘记清楚:两者。

float:left

/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 100%;
  font: inherit;
  vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
  display: block;
}
body {
  line-height: 1;
}
ol,
ul {
  list-style: none;
}
blockquote,
q {
  quotes: none;
}
blockquote:before,
blockquote:after,
q:before,
q:after {
  content: '';
  content: none;
}
table {
  border-collapse: collapse;
  border-spacing: 0;
}
/*
  ========================================
  Custom styles
  ========================================
*/

body {
  background: #130b3d;
  color: #888;
  font: 300 16px/22px"Century Gothic", Helvetica, Arial, sans-serif;
}
/*
  ========================================
  Grid
  ========================================
*/

*,
*:before,
*:after {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.container {
  margin: 0 auto;
  padding-left: 20px;
  padding-right: 20px;
  width: 960px;
}
.col-1-3 {
  width: 33.33%;
  float:left;
}
.col-2-3 {
  width: 66.66%;
}
.col-1-3,
.col-2-3 {
  display: inline-block;
  vertical-align: top;
}
.grid,
.col-1-3,
.col-2-3 {
  padding-left: 15px;
  padding-right: 15px;
  padding-top: 20px;
  padding-bottom: 20px;
}
.container,
.grid {
  margin: 0 auto;
  width: 960px;
}
.container {
  padding-left: 30px;
  padding-right: 30px;
}
/*
  ========================================
  Clearfix
  ========================================
*/

.group:before,
.group:after {
  content: "";
  display: table;
}
.group:after {
  clear: both;
}
.group {
  clear: both;
  *zoom: 1;
}
/*
  ========================================
  Rows
  ========================================
*/

.row {
  background: #fff;
  min-width: 960px;
  padding: 0;
}
.row,
.row-alt {
  min-width: 100%;
}
/*
  ========================================
  Typography
  ========================================
*/

h1,
h3,
h4,
h5,
p {
  margin-bottom: 10px;
}
h1,
h2,
h3,
h4 {
  color: #7b7b7b;
}
h1 {
  font-size: 46px;
  line-height: 44px;
  margin-bottom: 6px;
}
h2 {
  font-size: 24px;
  line-height: 44px;
}
h3 {
  font-size: 21px;
}
h4 {
  font-size: 18px;
}
h5 {
  color: #a9b2b9;
  font-size: 16px;
  font-weight: 400;
}
strong {
  font-weight: 900;
}
cite,
em {
  font-style: italic;
}
/*
  ========================================
  Buttons
  ========================================
*/

.btn {
  border-radius: 5px;
  display: inline-block;
  margin: 0;
}
.btn-alt {
  border: 1px solid #dfe2e5;
  padding: 10px 30px;
}
/*
  ========================================
  Home
  ========================================
*/

.hero {
  line-height: 30px;
  padding: 18px 60px 46px 60px;
}
.hero h3 {
  font-size: 32px;
  text-align: center;
}
.hero h5 {
  font-size: 20px;
  text-align: center;
  color: #7b7b7b;
  font-weight: 400;
}
.teaser img {
  border-radius: 5px;
  display: block;
  margin-bottom: 22px;
  max-width: 100%;
}
/*
  ========================================
  Primary header
  ========================================
*/

.logo {
  text-align: center;
  font-size: 48px;
  line-height: 44px;
  padding: 40px 0 0 0;
}
.tagline {
  text-align: center;
}
.primary-nav {
  font-size: 18px;
  font-weight: 400;
  text-align: center;
  text-decoration: underline;
}
.primary-header a,
.primary-footer a {
  color: #fff;
}
.primary-header a:hover,
.primary-footer a:hover {
  color: #cdcdcd;
}
/*
  ========================================
  Primary footer
  ========================================
*/

.primary-footer small {
  text-align: left;
}
.primary-footer {
  text-align: center;
  padding-bottom: 10px;
  padding-top: 20px;
}
/*
  ========================================
  Links
  ========================================
*/

a:hover {
  color: #cdcdcd;
}
a {
  color: #7b7b7b;
  text-decoration: none;
}
/*
  =======================================
  Navigation
  =======================================
*/

.nav li {
  display: inline-block;
  margin: 10px 5px;
  vertical-align: top;
}
.nav li:last-child {
  margin-right: 0;
}
/*
  =======================================
  Aside
  =======================================
*/

.aside {
  float: left;
  max-width: 200px;
}
.form {
  float: right;
  max-width: 300px;
  margin-top: 40px;
  margin-right: 40px;
}
form {
  margin-bottom: 22px;
}
input,
select,
textarea {
  font: 300 16px/22px"Century Gothic", Helvetica, Arial, sans-serif;
}
.form-style label {
  color: #7b7b7b;
  cursor: pointer;
  font-weight: 400;
}
.form-style input,
.form-style textarea {
  border: 2px solid #eeeeee;
  border-radius: 3.5px;
  color: #888;
  display: block;
  margin: 0 0 5px 0;
  padding: 5px;
}
.form-style input,
.form-style textarea {
  width: 250px;
}
.form-style textarea {
  height: 78px;
}
.form h3 {
  margin-right: 20px;
  margin-top: 10px;
}
.aside h3 {
  margin-left: 50px;
  margin-top: 10px;
}
.aside img {
  border-radius: 5px;
  display: inline-block;
  margin-bottom: 10px;
  max-width: 47%
}
/*
  ==========================================
  About
  ==========================================
*/

.about {
  margin: 30px 30px 50px 30px;
}
.history {
  margin-left: 55px;
  margin-right: 55px;
}
.about h4 {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
}
.about h5 {
  text-align: left;
  line-height: 10px;
}
.about h6 {
  font-size: 16px;
}
.about img {
  border-radius: 5px;
  display: inline-block;
  margin-bottom: 10px;
  max-width: 12.5%
}
.about-img {
  margin-left: 155px;
}
/*
  ===============================
  Contact
  ===============================
*/

}
.map {
  margin-bottom: 33px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Event Technologies Ltd.</title>
  <link rel="stylesheet" href="assets/stylesheet/main.css">
  <meta name="viewport" content="width=device-width, initial-scale=1" />
</head>

<body>

  <header class="primary-header container group">
    <h1 class="logo">
	    <a href="home.html">Event Technologies</a>
      </h1>
    <h5 class="tagline">
	    Interactive Event Multimedia
	  </h5>

    <nav class="primary-nav nav">
      <ul>
        <li><a href="home.html">Home</a>
        </li>
        <!--
		  -->
        <li><a href="aboutus.html">About Us</a>
        </li>
        <!--
		  -->
        <li><a href="services.html">Services</a>
        </li>
        <!--
		  -->
        <li><a href="projects.html">Projects</a>
        </li>
        <!--
		  -->
        <li><a href="contactus.html">Contact Us</a>
        </li>
        <!--
		  -->
        <li><a href="vacancies.html">Vacancies</a>
        </li>
      </ul>
    </nav>
  </header>
  <aside class="aside">
    <h3>Our clients include:</h3>
    <img src="assets/images/home/virgin_logo.png">
    <!--
		  -->
    <img src="assets/images/home/willow_logo.jpg">
    <img src="assets/images/home/hsbc_logo.jpg">
    <!--
		  -->
    <img src="assets/images/home/home_office_logo.jpg">
    <img src="assets/images/home/land_rover_logo.png">
    <!--
		  -->
    <img src="assets/images/home/nissan_logo.jpg">
    <img src="assets/images/home/jaguar.gif">
    <!--
		  -->
    <img src="assets/images/home/capita_logo.jpg">
    <img src="assets/images/home/cancer_logo.png">
    <!--
		  -->
    <img src="assets/images/home/legion.gif">
  </aside>


  <aside class="form">
    <h3>Make an Enquiry</h3>
    <fieldset class="form-style">
      <label>
        Name:
        <input type="text" name="name" placeholder="Full name" required>
      </label>
      <!--
			-->
      <label>
        Email:
        <input type="email" name="email" placeholder="Email Address" required>
      </label>
      <!--
			-->
      <label>
        Company:
        <input type="text" name="company" placeholder="Company" required>
      </label>
      <!--
			-->
      <label>
        Enquiry:
        <textarea name="comments"></textarea>
      </label>
    </fieldset>
    <input type="submit" name="submit" value="Send">
  </aside>

  <section class="row">
    <div class="hero grid">
      <section class="teaser col-1-3">
        <h3>
		        <a href="services.html">Interactive iPads
		      </h3>
        <img src="assets/images/home/interactive.png">
        </a>
        <h5>Real-time audience feedback tools</h5>
      </section>
      <!--
		    -->
      <section class="teaser col-1-3">
        <h3>
		          <a href="services.html">Interactive Fundraising
		        </h3>
        <img src="assets/images/home/fundraising.jpg">
        </a>
        <h5>Maximise revenue potential at fundraising events</h5>
      </section>
      <!--
		      -->
      <section class="teaser col-1-3">
        <h3>
		             <a href="services.html">Bespoke Development
	               </h3>
        <img src="assets/images/home/bespoke.jpg">
        </a>
        <h5>Not looking for an off-the-shelf solution? No problem...</h5>
      </section>
      <div style='clear:both;'></div>
    </div>
  </section>
  <footer class="primary-footer container group">
    <nav class="primary-nav nav">
      <ul>
        <li><a href="home.html">Home</a>
        </li>
        <!--
		  -->
        <li><a href="aboutus.html">About Us</a>
        </li>
        <!--
		  -->
        <li><a href="services.html">Services</a>
        </li>
        <!--
		  -->
        <li><a href="projects.html">Projects</a>
        </li>
        <!--
		  -->
        <li><a href="contactus.html">Contact Us</a>
        </li>
        <!--
		  -->
        <li><a href="vacancies.html">Vacancies</a>
        </li>
      </ul>
    </nav>

    <h5>Event Technologies Ltd.<br> Unit 10 Rotherbrook Court,<br> Bedford Road,<br> Petersfield,<br> GU32 3QG</h5>
  </footer>
</body>

</html>

答案 2 :(得分:0)

简单地说,你在第一张图片上有一行文字,另外两张图片有2行。这就是为什么它没有调整的原因。 现在,如何让它对齐?几乎没有可用的解决方案,我的建议是将您的网格切换到一个表格并将其称为一天(因为您正在进行学习)。因此,您的视图将是一个3x3表,第一行标题,第二行图片,描述排在第三位。

此外,由于您正在学习,我强烈建议您切换到像Bootstrap这样的框架来为您完成工作。它易于使用且易于学习。

祝你好运

答案 3 :(得分:0)

我认为这个例子是从网站上截取的截图 - 是否可以让网址真正看到正在发生的事情。 否则,从新标记开始并逐渐添加它可能会更好。 请不要使用表格 - 你将学习一种弃用的方式。

CSS

div.rowcontainer{
}
div.rowitemcontainer{
    display:inline-block;
    vertical-align:middle;
}
div.rowitem{
    margin:1em;
}

HTML(直接放在<body>标记下,这样就不会受到其他元素的影响)

<div class='rowcontainer'>
    <div class='rowitemcontainer'>
        <div class='rowitem'>
            Item<br />1
        </div>
    </div>
    <div class='rowitemcontainer'>
        <div class='rowitem'>
            I am<br />Item<br />2
        </div>
    </div>
    <div class='rowitemcontainer'>
        <div class='rowitem'>
            This<br />is<br />Item<br />3
        </div>
    </div>
</div>