我有一个显示元素:inline-block,但它似乎不接受margin-top.这是因为元素仍被视为内联元素吗?
如果是,有没有人有解决方法?
编辑#1:
我的CSS非常简单:
.label {
background: #ffffff;
display: inline-block;
margin-top: -2px;
padding: 7px 7px 5px;
}
Run Code Online (Sandbox Code Playgroud)
我最终将内容包装在另一个div中并给出了一个优势.但这会导致大量额外的标记,并使我的代码不那么清晰.
编辑#2:
margin-top&margin-bottomon inline-block元素似乎只与正值一起使用.
我正在创建一个横向分为三个部门的示例网站.我希望最左边的div为25%宽度,中间一个为50%宽度,右边为25%宽度,以便分区水平填充所有100%空间.
<html>
<title>
Website Title
</title>
<div id="the whole thing" style="height:100%; width:100%" >
<div id="leftThing" style="position: relative; width:25%; background-color:blue;">
Left Side Menu
</div>
<div id="content" style="position: relative; width:50%; background-color:green;">
Random Content
</div>
<div id="rightThing" style="position: relative; width:25%; background-color:yellow;">
Right Side Menu
</div>
</div>
</html>
Run Code Online (Sandbox Code Playgroud)
当我执行此代码时,div显示在彼此之上.我希望他们出现在彼此旁边!
我怎样才能做到这一点?
我试图强制节点的位置.我有我的节点的x和y坐标及其有向图.我可以使用rank = same来处理行(y坐标),但无法弄清楚我如何处理列(x坐标).
我正在使用一个Scrollview无限的"Time Picker Carousel"并发现它不是最好的方法(最后一个问题)
现在,我找到了Recycler View,但是我无法在recyclerView的X方向上获得当前的滚动偏移量?(假设每个项目的宽度为100px,第二个项目只有50%可见,因此滚动偏移量为150px)
recyclerView.getScrollX()返回0(文档说:初始滚动值)LayoutManager有findFirstVisibleItemPosition,但我不能算出X与偏移UPDATE
我刚刚找到了一种方法来跟踪X-Position,同时使用onScrolled回调更新值,但我更喜欢获取实际值而不是一直跟踪它!
private int overallXScroll = 0;
//...
mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
overallXScroll = overallXScroll + dx;
Log.i("check","overallXScroll->" + overallXScroll);
}
});
Run Code Online (Sandbox Code Playgroud) 我想创建我的第一个网页,但我遇到了一个问题.
我有以下代码:
<img src="img/logo.png" alt="logo" />
<h1>My website name</h1>
Run Code Online (Sandbox Code Playgroud)
我想知道如何使徽标和H1在同一行.谢谢!
我从数据属性创建以下数组,我需要能够从中获取最高和最低值,以便稍后将其传递给另一个函数.
var allProducts = $(products).children("li");
prices = []
$(allProducts).each(function () {
var price = parseFloat($(this).data('price'));
prices[price] = price;
});
console.log(prices[0]) <!-- this returns undefined
Run Code Online (Sandbox Code Playgroud)
我的列表项看起来像这样(我已经减少了可读性):
<li data-price="29.97"><a href="#">Product</a></li>
<li data-price="31.00"><a href="#">Product</a></li>
<li data-price="19.38"><a href="#">Product</a></li>
<li data-price="20.00"><a href="#">Product</a></li>
Run Code Online (Sandbox Code Playgroud)
一个快速的console.log价格显示我的数组看起来是排序的所以我可以抓住我假设的第一个和最后一个元素,但目前数组中的名称和值是相同的,所以每当我尝试做价格[0 ],我得到了不确定
[]
19.38 19.38
20.00 20.00
29.97 29.97
31.00 31.00
Run Code Online (Sandbox Code Playgroud)
有一种感觉这是一个非常简单的问题,所以请善待:)
当我们应用于position:fixed一个元素时,它被取出文档的正常流程,因此它不尊重它的父元素宽度.如果将其声明为百分比,是否有办法使其继承父级的宽度?(下面的工作用例)
let widthis = $('.box').width();
$('.dimensions').text(`width is ${widthis}`);
$('button').on('click', function() {
$('.box').toggleClass('fixed');
let widthis = $('.box').width();
$('.dimensions').text(`width is ${widthis}`);
});Run Code Online (Sandbox Code Playgroud)
.container {
max-width: 500px;
height: 1000px;
}
.box {
background-color: lightgreen;
}
.fixed {
position: fixed;
}
.col-1 {
border: 1px solid red;
float: left;
width: 29%;
}
.col-2 {
border: 1px solid pink;
float: left;
width: 69%;
}Run Code Online (Sandbox Code Playgroud)
<link href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Click this to toggle position fixed for the …Run Code Online (Sandbox Code Playgroud)据我所知,移动safari在固定元素周围有很多错误,但在大多数情况下,我已经设法让我的布局正常工作,直到我在底部的固定导航中添加了一个非常需要的文本输入.现在,当用户关注文本输入元素并出现虚拟键盘时,我的导航(否则始终固定在页面底部)会跳到页面中间的一个非常奇怪的位置.

我会在这篇文章中添加一些代码,但我不确定从哪里开始.导航固定在底部,位于左侧和底部0,宽度为100%.从那里,我不知道发生了什么,我只能假设它是一个移动的safari bug.
只有当文本输入元素被聚焦并且虚拟键盘打开时,它似乎也会失去它的位置固定并变得相对.
如何使用jQuery找到html元素与浏览器(或窗口)一侧(左侧或顶部)之间的距离(以像素为单位)?
我想知道Java中是否有一个本机方法来获取给定值的表索引?
假设我的表包含以下字符串:
public static final String[] TYPES = {
"Sedan",
"Compact",
"Roadster",
"Minivan",
"SUV",
"Convertible",
"Cargo",
"Others"
};
Run Code Online (Sandbox Code Playgroud)
假设用户必须输入汽车类型,然后在后台程序获取该字符串并获取它在数组中的位置.
因此,如果该人进入:轿车它应该采取位置0并将其存储在我的程序创建的汽车对象中...