Hi Stefan,
The position of the suggestion list is calculated dynamically and it’s not easy to center it with CSS. I came up with a JavaScript code snippet, that could work for you. I haven’t tested it properly, but it may put you on the right track.
This code snippet works only with the following CSS:
.dgwt-wcas-suggestions-wrapp {
width: 300px !important;
}
@media screen and (min-width: 768px) {
.dgwt-wcas-suggestions-wrapp {
width: 700px !important;
}
}
@media screen and (min-width: 1200px) {
.dgwt-wcas-suggestions-wrapp {
width: 1100px !important;
}
}
If you need to set different breakpoints, then you would have to change them in both CSS and JavaScript.
<script>
var fiboSearchInput = document.getElementById("dgwt-wcas-search-input-1");
var fiboSearchInputWidth = 0;
var currentLeftPosition = 0;
var adjustedLeftPosition = 0;
if (fiboSearchInput) {
fiboSearchInput.addEventListener('keydown', adjustFiboSearchSuggestions);
fiboSearchInput.addEventListener('keyup', adjustFiboSearchSuggestions);
fiboSearchInput.addEventListener('blur', adjustFiboSearchSuggestions);
fiboSearchInput.addEventListener('focus', adjustFiboSearchSuggestions);
fiboSearchInput.addEventListener('change', adjustFiboSearchSuggestions);
fiboSearchInput.addEventListener('input', adjustFiboSearchSuggestions);
}
window.onload = adjustFiboSearchSuggestions;
function adjustFiboSearchSuggestions() {
fiboSearchInputWidth = fiboSearchInput.offsetWidth;
currentLeftPosition = fiboSearchInput.getBoundingClientRect().left;
var fiboSearchSuggestions = document.getElementsByClassName("dgwt-wcas-suggestions-wrapp");
if (typeof fiboSearchSuggestions !== 'undefined') {
var fiboSearchSuggestionsWidth = 300;
if (screen.width >= 768) {
fiboSearchSuggestionsWidth = 700;
}
if (screen.width >= 1200) {
fiboSearchSuggestionsWidth = 1100;
}
var tmp = (fiboSearchInputWidth - fiboSearchSuggestionsWidth) / 2;
if (adjustedLeftPosition == 0) {
adjustedLeftPosition = tmp + currentLeftPosition;
}
fiboSearchSuggestions[0].style.left = adjustedLeftPosition + "px";
}
setTimeout(adjustFiboSearchSuggestions, 10);
}
</script>
You can put this code in your theme’s footer.php file (before the closing </body> tag) or in a plugin that enables you to add JavaScript to your website.
I hope this is helpful!
Regards,
Marta