如何定位一些文字?

时间:2012-08-30 09:23:45

标签: html css twig

对于noobie和愚蠢的问题感到抱歉,但我只知道一点css,我不知道如何设计我的网站。这是我的代码:

HTML (Twig):

<div class="wrap">
    <div>
        <img class="birthday" src="http://www.clker.com/cliparts/1/d/a/6/11970917161615154558carlitos_Balloons.svg.med.png">
            <div class="try"> 
               This friends have brithday today: 
               {% for bd in birthdays %}

               <p>
                   <a href="{{ path('friend_id', {'id': bd.id}) }}">{{ bd.name }}</a>
                      <span class="years">
                         ({{ bd.years }} years)
                       </span>
               </p>

               {% endfor %}

            </div>

    </div>
</div>

CSS:

body {
    background-color: #FFFFF1;
    text-align: center;
    font-size: 17px;
    font-family: Tahoma, Geneva, sans-serif;  
}

p {
    margin: 10px;
}

a {
    text-decoration: none;
    color: #6a9211;
}

a:hover {
    text-decoration: underline;
}

.wrap {
    width: 700px;
    margin: auto;
}

.birthday {
    width: 49px;
    height: 80px;
    float: left;
    margin-left: 150px;
    display: block;  
}

.try {
    display: block;
    margin-right: 150px;
    margin-bottom: 50px;
}

.years {
    font-size: 12px;
}

this就是我得到的。我要解决的问题是MariaPeter要显示在AnnaJohn下,所有这4个都位于标签This friends have birthday today:下方。我知道这是因为图像,但我不知道如何让它看起来很好。 :(

请帮忙!提前谢谢!

4 个答案:

答案 0 :(得分:2)

仅限CSS Fiddle -

float: right;添加到.try类 -

.try {
    /*display: block;*/ float: right;
    margin-right: 150px;
    margin-bottom: 50px;
}

编辑:

您还可以移除margins并使用width -

管理div
.try {
    /*display: block;*/ float: right; width: 500px;
    /*margin-right: 150px;
    margin-bottom: 50px;*/
}

Updated Fiddle

答案 1 :(得分:2)

试试这个:

.try {
width: 500px;
float: right;
margin-right: 150px;
margin-bottom: 50px;
}

答案 2 :(得分:1)

你只需要在try-class中添加一些margin-left: http://jsfiddle.net/VWY8N/

.try {
    display: block;
    margin-right: 150px;
    margin-bottom: 50px;
    margin-left: 201px;
}

答案 3 :(得分:-1)

将您的css添加到head部分的样式标记中,如下所示

<html>
<head>
<style>
{
    background-color: #FFFFF1;
    text-align: center;
    font-size: 17px;
    font-family: Tahoma, Geneva, sans-serif;  
}

p {
    margin: 10px;
}

a {
    text-decoration: none;
    color: #6a9211;
}

a:hover {
    text-decoration: underline;
}

.wrap {
    width: 700px;
    margin: auto;
}

.birthday {
    width: 49px;
    height: 80px;
    float: left;
    margin-left: 150px;
    display: block;  
}

.try {
    display: block;
    margin-right: 150px;
    margin-bottom: 50px;
}

.years {
    font-size: 12px;
}

</style>
</head>
<body>
<div class="wrap">
    <div>
        <img class="birthday" src="http://www.clker.com/cliparts/1/d/a/6/11970917161615154558carlitos_Balloons.svg.med.png">
            <div class="try"> 
               This friends have brithday today: 
               {% for bd in birthdays %}

               <p>
                   <a href="{{ path('friend_id', {'id': bd.id}) }}">{{ bd.name }}</a>
                      <span class="years">
                         ({{ bd.years }} years)
                       </span>
               </p>

               {% endfor %}

            </div>

    </div>
</div>

</body>
</html>