如何在我的文字下方和右侧定位我的图像?

时间:2016-01-12 09:55:04

标签: html css

我有以下设计: enter image description here

注意引号底部的签名。它非常好地放在右边与文本对齐。

到目前为止,这是我的html css版本:

enter image description here

我无法找到正确的方法来将签名向右移动并与报价右侧对齐。

这是我的HTML:

<!DOCTYPE html>
    <html>
        <head>
            <link rel="stylesheet" href="main.css">
        </head>

        <body>
            <div class="header">
                <div class="logo">
                    <img src="images/top-logo.png" alt="ProvenWord Logo">
                </div>
                <ul class="nav">
                    <li>Home</li>
                    <li>Proofreading</li>
                    <li>Editing</li>
                    <li>About</li>
                    <li>How it works</li>
                    <li>FAQ</li>
                    <li>Contact</li>
                </ul>
            </div> <!--close header -->
            <div class="tagline">
                <div class="section-container">
                    <h1><span>Transform your written</span> work into a <strong>masterpiece<strong></h1>
                    <a href="freequote.html" class="button">Free Quote</a>
                    <p class="first-quote">"Your proofreading assistance has enabled me to successfully complete my dissertation with greater ease."</p>
                    <img src="images/sudthida-signature.png" alt="Sudthida's Signature">
                    <p class="first-quote school">Sudthida P. Ph.D in Educational Research - King's College University of London</p>
                </div><!--close section-container-->
            </div><!--close tagline-->              
        </body>
    </html>

这是我的css:

html, body, h1, h2, h3, h4, p, ol, ul, li, a, div {
    padding: 0px;
    border: 0px;
    margin: 0px;
    font-size: 100%;
    font: inherit;
}


/*----------------------------*/
/*----- Tag Declarations -----*/
/*--------------------------- */

body {
    font-family: "Sinkin Sans", Verdana, Helvetica, sans-serif;
}


h1{
    font-size: 36px;
    font-weight: 400;
    line-height: 1.2;
}

h2 {
    font-size: 28px;
    padding-bottom: 25px;
    font-weight: 300;
    line-height: 1.3;
    letter-spacing: 1px;
}

h2 strong {
    font-weight: 600;
}

p {
    font-size: 15px;
    line-height: 140%;
    font-weight: 300;
    letter-spacing: 1px;
}

.button {
    display: inline-block;
    line-height: 48px;  /*setting this to the button height makes the text centered */
    height: 48px;
    width: 185px;
    background: #ffd000;
    border: 2px solid #b59400;
    font-size: 18px;
    font-weight: 100;x;
    border-radius: 60px;
}

a.button {
    text-decoration: none;
    color: #000000;
}

a.button:hover {
    background: #feef00;
}


li {
    list-style: none;
    margin-bottom: 0.5em;
    text-indent: 1.5em;
    background-image: url(images/check.png);
    background-repeat: no-repeat;
    letter-spacing: 1px;
    font-weight: 200;
    font-size: 12px;
}

.section-container {
    width: 520px;
    margin: 0 auto;
}

/*--------------------------*/
/*----- Header Section -----*/
/*--------------------------*/

.header {
    padding: 25px 0px 32px 48px;
}


.logo img {
    float: left;
    padding-right: 130px;
}

.nav {
    list-style-type: none;
    padding-top: 32px;
}

.nav li {
    display: inline;
    padding-right: 10px;
    font-size: 12px;
    font-weight: 200;
}


/*---------------------------*/
/*----- Tagline Section -----*/
/*---------------------------*/

.tagline {
    background: #abdfe8 url(images/bg-tagline.png) no-repeat;
    height: 450px;
    text-align: center;
}


.section-container h1 {
    padding-top: 130px;

}

.section-container h1 span {
    letter-spacing: 2px;
}

.section-container .button {
    margin: 40px 0 40px 0;
}


.first-quote {
    font-size: 13px;
    line-height: 1.5;
    color: white;
    margin: 0 25px 10px 25px;
}

.section-container img {
    display: block;
    text-align: right;
}


.section-container .school {
    font-size: 10px;
    letter-spacing: 0.5px;
    text-align: center;
}

我使用了margin属性来移动图像,但我认为边距用于在块元素之间创建空间。我不想破解我的布局,我想了解它是如何工作的以及在css中使用不同属性的正确方法是什么。

任何帮助都非常感激。

1 个答案:

答案 0 :(得分:0)

您可以使用float将图像向右对齐,并结合边距将其精确放置在需要的位置,然后清除图像下方的文本。

我在下面评论了CSS中的更改。

html,
body,
h1,
h2,
h3,
h4,
p,
ol,
ul,
li,
a,
div {
  padding: 0px;
  border: 0px;
  margin: 0px;
  font-size: 100%;
  font: inherit;
}
/*----------------------------*/

/*----- Tag Declarations -----*/

/*--------------------------- */

body {
  font-family: "Sinkin Sans", Verdana, Helvetica, sans-serif;
}
h1 {
  font-size: 36px;
  font-weight: 400;
  line-height: 1.2;
}
h2 {
  font-size: 28px;
  padding-bottom: 25px;
  font-weight: 300;
  line-height: 1.3;
  letter-spacing: 1px;
}
h2 strong {
  font-weight: 600;
}
p {
  font-size: 15px;
  line-height: 140%;
  font-weight: 300;
  letter-spacing: 1px;
}
.button {
  display: inline-block;
  line-height: 48px;
  /*setting this to the button height makes the text centered */
  height: 48px;
  width: 185px;
  background: #ffd000;
  border: 2px solid #b59400;
  font-size: 18px;
  font-weight: 100;
  x;
  border-radius: 60px;
}
a.button {
  text-decoration: none;
  color: #000000;
}
a.button:hover {
  background: #feef00;
}
li {
  list-style: none;
  margin-bottom: 0.5em;
  text-indent: 1.5em;
  background-image: url(images/check.png);
  background-repeat: no-repeat;
  letter-spacing: 1px;
  font-weight: 200;
  font-size: 12px;
}
.section-container {
  width: 520px;
  margin: 0 auto;
}
/*--------------------------*/

/*----- Header Section -----*/

/*--------------------------*/

.header {
  padding: 25px 0px 32px 48px;
}
.logo img {
  float: left;
  padding-right: 130px;
}
.nav {
  list-style-type: none;
  padding-top: 32px;
}
.nav li {
  display: inline;
  padding-right: 10px;
  font-size: 12px;
  font-weight: 200;
}
/*---------------------------*/

/*----- Tagline Section -----*/

/*---------------------------*/

.tagline {
  background: #abdfe8 url(images/bg-tagline.png) no-repeat;
  height: 450px;
  text-align: center;
}
.section-container h1 {
  padding-top: 130px;
}
.section-container h1 span {
  letter-spacing: 2px;
}
.section-container .button {
  margin: 40px 0 40px 0;
}
.first-quote {
  font-size: 13px;
  line-height: 1.5;
  color: white;
  margin: 0 25px 10px 25px;
}
.section-container img {
  display: block;
  float: right; /* USE FLOAT */
  margin-right: 1.8em; /* WITH MARGIN TO GIVE THE CORRECT POSITION */
}
.section-container .school {
  clear: both; /* CLEAR THE FLOATED IMAGE */
  font-size: 10px;
  letter-spacing: 0.5px;
  text-align: center;
}
<div class="header">
  <div class="logo">
    <img src="images/top-logo.png" alt="ProvenWord Logo">
  </div>
  <ul class="nav">
    <li>Home</li>
    <li>Proofreading</li>
    <li>Editing</li>
    <li>About</li>
    <li>How it works</li>
    <li>FAQ</li>
    <li>Contact</li>
  </ul>
</div>
<!--close header -->
<div class="tagline">
  <div class="section-container">
    <h1><span>Transform your written</span> work into a <strong>masterpiece<strong></h1>
    <a href="freequote.html" class="button">Free Quote</a>
    <p class="first-quote">"Your proofreading assistance has enabled me to successfully complete my dissertation with greater ease."</p>
    <img src="images/sudthida-signature.png" alt="Sudthida's Signature">
    <p class="first-quote school">Sudthida P. Ph.D in Educational Research - King's College University of London</p>
  </div>
  <!--close section-container-->
</div>
<!--close tagline-->