【发布时间】:2015-03-02 12:28:33
【问题描述】:
我需要动态显示 2 个表示开头和结尾引号的图形图像文件,如下面的示例屏幕截图所示。
引号需要出现在上方内容块的左右两侧,如图所示。页面上的内容块宽度会有所不同。
我试过浮动和背景图片。有没有人有提示或技巧来正确、动态和灵活地定位 2 个图像文件?
这是我在与@Utkanos 合作后所得到的答案:
HTML
<div class="postsPage_item_content postsPage_item_quote"><?php the_content();?></div>
CSS
div#maincontentcontainer div#primary div div.postsPage_item_content {
position: relative;
text-align: center;
}
div#maincontentcontainer div#primary div div.postsPage_item_quote::before, div#maincontentcontainer div#primary div div.postsPage_item_quote::after {
background-image: url('../images/QUOTE1.png');
content: '';
display: block;
left: 20%;
height: 28px; /* background-image natural height is 28px */
position: absolute;
top: calc(50% - 50px);
width: 36px; /* background-image natural width is 36px */
}
div#maincontentcontainer div#primary div div.postsPage_item_quote::after {
background-image: url('../images/QUOTE2.png');
left: auto;
right: 20%;
}
显示
期望的结果是 (1) 每个动态渲染的引号都与内容块的顶部对齐,并且 (2) 引号动态定位到内容块的左侧和右侧,边距填充,如红色所示箭头。
【问题讨论】:
-
虽然可以这样做,但使用 css content 属性和 :before 和 :after 创建它们不是更好吗?
-
啊。我不熟悉那些CSS样式。我会调查他们。谢谢@MightyPork
标签: css image css-float background-image css-position