[英]How do i re-align text in a <span>?
I have an image, followed horizontally by text, followed by an image, followed by text. 我有一个图像,然后水平放置文本,然后是图像,然后是文本。 I want the text to be higher, but
margin-top
doesn't work with span. 我希望文本更高,但是
margin-top
不起作用。
Here's the code I have (and ignore the bits in the {} brackets, those are things for use in tumblr custom themes): 这是我的代码(忽略{}括号中的位,这些是在tumblr自定义主题中使用的东西):
<div class="activities">
<span class="activity"><img src="{image:First Activity Image}"/>
<span class="activityname">{text:First Activity Name}</span>
</span>
<span class="activity"><img src="{image:Second Activity Image}"/>
<span class="activityname">{text:Second Activity Name}<span>
</span>
</div>
I'd change it all over to but that would make each one appear on a new line. 我将其全部更改为,但这会使每个人出现在新行中。
Whoa there. 哇,在那里。 Your CSS should follow the HTML, not the other way around.
您的CSS应该遵循HTML,而不是其他方式。 First mark it up semantically.
首先在语义上进行标记。 It looks like you have a list, so let's use an
ul
: 看起来您有一个列表,所以让我们使用
ul
:
<ul class="activities">
<li>
<img src="...">
<p>...</p>
</li>
...
</ul>
Then you can float your list items to the left: 然后,您可以将列表项浮动到左侧:
.activities {
/* makes sure the container expands to fit the floated material */
overflow: hidden;
}
.activities > li {
float: left;
width: 300px; /* or something; you might want to change this number */
}
You can also float your image to the left: 您还可以将图像浮动到左侧:
.activities > li {
overflow: hidden; /* again, expand the container */
}
.activities > li > img {
float: left;
}
Then you can align the text to the center: 然后,您可以将文本对齐到中心:
.activities > li > p {
text-align: center;
}
Usage of ul li
is the better option. 使用
ul li
是更好的选择。 You can easily place the content as of your wish. 您可以根据需要轻松放置内容。
Please give float:left
to all the inner contents, after that you can easily play with the margin
values. 请给所有内部内容赋予
float:left
,之后您可以轻松地使用margin
值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.