Having trouble centering an input field with an icon after it in a div. I can center the input text easily using text-align:center, but struggling to center the icon added using ::before.
The search text is centered, but not the icon
https://i.sstatic.net/QPYue.png
How can I center both the search text and icon so they are underneath the CENTER title? Is there a way to achieve this without modifying/adding HTML?
Below is the HTML and CSS code I am currently working with
.search-form {
overflow: hidden;
position: relative;
}
.header-right {
float: right;
position: relative;
text-align: right;
width: 25%;
z-index: 99;
}
.header-left .search-form::before {
color: #fff;
content: "\f375";
display: block;
font-family: "Ionicons"; /* stylelint-disable-line */
padding-left: 1px;
position: absolute;
top: 12px;
}
.header-left .search-form input[type="submit"] {
border: 0;
clip: rect(0, 0, 0, 0);
height: 1px;
margin: -1px;
padding: 0;
position: absolute;
width: 1px;
}
.header-left input[type="search"] {
border-width: 0;
background-color: transparent;
color: #fff;
font-size: 14px;
font-weight: 700;
letter-spacing: 2px;
text-align: left;
text-transform: uppercase;
}
.header-left ::placeholder {
color: #fff;
opacity: 1;
}
.header-left input[type="search"] {
text-align: right;
}
<div class="header-left"><form class="search-form" method="get" action="http://dev.local/" role="search" itemprop="potentialAction" itemscope="" itemtype="https://schema.org/SearchAction"><label class="search-form-label screen-reader-text" for="searchform-1">Search</label><input class="search-form-input" type="search" name="s" id="searchform-1" placeholder="Search" itemprop="query-input"><input class="search-form-submit" type="submit" value="Search"><meta content="http://dev.local/?s={s}" itemprop="target"></form></div>
Update : Unable to modify the form generated by a PHP function, so looking for a pure CSS solution to center position the form input and icon.
Although the search form is centered, the placeholder text named SEARCH and icon are still not centered. How can I center both these elements.