Recently in the development of the public number in the picture and text center of the problem. For example, we would like to achieve the following effect:
Or.
In the development process, it may be my own code reasons or compatibility reasons, in iOS and Android it is difficult to fully achieve such a center effect.
In order to achieve this, and compatible with iOS and Android, I used the following three ways to implement (the following code I only write the main attributes, the specific style we each add according to their own needs):
First, display:table and Display:table-cell use;
For example:
1 <div style= "display:table;vertical-align:middle;" > 2 <span class= "Display:table-cell;vertical-align:middle" ></span>4 <span class= "Display:table-cell;vertical-align:middle" > Text </span > 5 </div>
Implemented by this combination of CSS styles.
Second, the use of background to achieve;
For example:
<style>
div{background: URL (/images/shop/cpbh.png) no-repeat left;
- Background-size: 14px;
- Display: inline-block;
- Padding-left: 20px;
- Color: #222;
- }
</style>
<div> text </div>
Use the background to refer to the picture, and then take advantage of the Padding-left property to keep the text from obscuring the picture, and we can use the Background-position property to adjust the picture position if the picture deviates.
Third, the use of positioning to solve.
<style>
div{
position:relative;
Padding-left: 20px;
}
Div img{
Position:absolute;
top:0;
Left:4px
}
</style>
<div style= "position:relative" > "
Text </div>
Use the positioning to hold the photo, Padding-left let the text do not cover the photo implementation.
PS: The above CSS style only write the key attributes, the specific style according to the different needs of the self-adjustment.
I only list three ways if there is any doubt or I write the wrong kind of, you are welcome to guide the discussion!
Moving Picture Text Vertical Center implementation method