不能将搜索栏放置在标题图像的右侧
cant position search bar on right side of header image
我正在尝试将搜索栏定位在图像的右侧。搜索栏默认位于图像的左侧,我希望它位于右侧。
我认为
searchBar.style.right = "200px";
应该可以工作,但是它没有。
下面是图片和搜索栏的完整代码:
function loadHeader() {
/* Header bar */
var headerImage = new Image();
headerImage.id = "hi";
headerImage.src = "headerBar.jpg";
headerImage.style.position = "absolute";
headerImage.style.top = "0px";
headerImage.style.left = "0px";
headerImage.style.zIndex = -1;
headerImageWidth = (window.innerWidth);
headerImage.width = headerImageWidth;
headerImageHeight = 40;
headerImage.height = headerImageHeight;
document.body.appendChild(headerImage);
/* Search bar */
var searchForm = document.createElement("form");
searchForm.setAttribute("action", "/search");
searchForm.setAttribute("method", "POST");
var searchBar = document.createElement("input");
searchBar.id = "sb";
searchBar.setAttribute("type", "text");
searchBar.setAttribute("placeholder", "Search");
searchBar.position = "absolute";
searchBar.left = "500px";
searchBar.style.zIndex = 0;
searchBar.width = 150;
searchBar.height = 20;
searchForm.appendChild(searchBar);
document.body.appendChild(searchForm);
}
设置right
属性必须与position:absolute
、position:fixed
或position:relative
结合使用。
与absolute
:元素将是相对于第一个定位祖先的位置。
与fixed
:元素将是相对于视窗的位置。
与relative
:元素将相对于它在流中的正常位置的位置。
相关文章:
- 将图像标题存储在selenium IDE中
- 用Javascript替换图像和图像标题/alt文本
- 如何在 javascript 替换新图像/标题后正确显示 css 工具提示
- 将鼠标悬停在图像上时删除图像标题
- 将图像标题区域与图像对齐
- 根据图像标题的搜索输入过滤图像
- 纸夹头像显示图像标题,而不是图像
- 在javascript弹出窗口中显示图像标题
- 单击更改图像标题的Javascrript
- PHP如何更改/添加图像标题
- Wordpress媒体库使用wp.media访问图像标题
- 显示已更改的图像标题
- NyroModal:将图像标题置于底部
- PHP图像标题输出显示
- 获取图像标题,并在当前URL的末尾添加链接
- 更改SRC +图像标题
- 灯箱中的图像标题/注释
- 使用这个.检索图像标题
- 不寻常的Javascript图像标题错误
- 随图像旋转图像标题