我在div中有几个HTML元素,具有固定宽度.内部元素的宽度之和大于容器的宽度.如何使内部元素显示为内嵌(并显示水平滚动),而不是在达到父级宽度后中断?
我可以添加一个包装器并为其指定一个最小宽度,但是如果内容发生变化,我想要一些会改变其大小的东西.
<div id="container">
<div class="contents" id="one"></div>
<div class="contents" id="two"></div>
<div class="contents" id="three"></div>
<div class="contents" id="four"></div>
</div>
#container {
width: 100px;
background-color: #CCC;
overflow: auto;
height: 100px;
}
.contents {
width: 35px;
height: 60px;
float: left;
}
#one {
background-color:#ABC;
}
#two {
background-color:#333;
}
#three {
background-color:#888;
}
#four {
background-color:#AAA;
}
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/elohr/G5YZ6/2/
谢谢!
我正在使用Go开发一个网站并将其连接到Elastic Search.在弹性搜索中,我可以为索引类型提供动态字段.当我从Elastic Search读取文档时,它将返回一个JSON对象作为结果,其中可以包含具有动态名称(或用户定义的字段)的字段.
我可以获得JSON结果并将其解组为Go结构,但我不知道将这些动态字段保留为Go结构的一部分的最佳方法是什么.
这就是我在做的事情.例如,如果我从Elastic Search获得联系人的文档,它可能看起来像这样:
{
"EmailAddress": "test@test.com",
"Name": "Test Contact",
"Phone": "17894785236",
"City": "San Francisco",
"State": "California"
}
Run Code Online (Sandbox Code Playgroud)
接触的Go结构是:
type Contact struct {
EmailAddress string
Name string
Phone string
CustomFields map[string]interface{}
}
Run Code Online (Sandbox Code Playgroud)
我实现Marshaler和Unmarshaler来覆盖对象的Marshaled和Unmarshalled.
func (c *Contact) MarshalJSON() ([]byte, error) {
contactMap := make(map[string]interface{})
contactMap["EmailAddress"] = c.EmailAddress
contactMap["Name"] = c.Name
contactMap["Phone"] = c.Phone
for k, v := range c.CustomFields {
contactMap[k] = v
}
return json.Marshal(contactMap)
}
func (c *Contact) UnmarshalJSON(data []byte) error {
var …Run Code Online (Sandbox Code Playgroud)