想象一下下面的布局,其中圆点代表盒子之间的空间:

[Left box]......[Center box]......[Right box]

当我移除右边的方框时,我希望中间的方框仍然在中间,就像这样:

[Left box]......[Center box].................

如果我移除左边的方框也是一样的。

................[Center box].................

现在,当中心框中的内容变长时,它将根据需要占用尽可能多的可用空间,同时保持居中。左右方框永远不会缩小,因此当没有空格时,overflow:hidden和text-overflow:省略号将生效,破坏内容;

[Left box][Center boxxxxxxxxxxxxx][Right box]

以上都是我的理想情况,但是我不知道如何达到这个效果。因为当我创建一个这样的伸缩结构时:

.parent {
    display : flex; // flex box
    justify-content : space-between; // horizontal alignment
    align-content   : center; // vertical alignment
}

如果左右方框的大小完全相同,我就会得到想要的效果。然而,当其中一个的大小不同时,居中的盒子就不再是真正的居中。

有人能帮我吗?

更新

一个自我证明很好,这很理想

.leftBox {
     justify-self : flex-start;
}

.rightBox {
    justify-self : flex-end;
}

最近我参加了一个面试,面试官要求我“编写一个程序,从一个包含10亿个数字的数组中找出100个最大的数字”。

我只能给出一个蛮力解决方案,即以O(nlogn)时间复杂度对数组进行排序,并取最后100个数字。

Arrays.sort(array);

面试官正在寻找一个更好的时间复杂度,我尝试了几个其他的解决方案,但都没有回答他。有没有更好的时间复杂度解决方案?

使用JQuery或其他类似框架从自定义url /Web服务加载HTML内容非常容易。到目前为止,我已经多次使用这种方法,并发现性能令人满意。

但是所有的书,所有的专家都试图让我使用JSON而不是生成的HTML。它为什么比HTML更优越?

它会快很多吗? 它在服务器上的负载是否非常小?

另一方面,我有一些使用生成HTML的理由。

它是简单的标记,通常和JSON一样紧凑,甚至更紧凑。 它更不容易出错,因为你得到的都是标记,而不是代码。 在大多数情况下,编程会更快,因为你不必为客户端单独编写代码。

你站在哪一边,为什么?

我有一个纬度和经度:“-27.0000,133.0000”。我想在此基础上制作一张地图。

我试着去这个链接

https://maps.googleapis.com/maps/api/geocode/json?latlng= 27.0000, 133.0000关键= * * * * * *

我一直在浏览器上得到这个错误

{
   "error_message" : "This API project is not authorized to use this API. Please ensure that this API is activated in the APIs Console: Learn more: https://code.google.com/apis/console",
   "results" : [],
   "status" : "REQUEST_DENIED"
}

但我想我已经启用了那个API。我登录到我的谷歌控制台,并再次检查。

当我去:https://console.developers.google.com/project/75423435770063/apiui/apis/enabled

我明白了:

启用地理编码+地理定位。

我现在有点卡住了。还有什么我没注意到的吗?

我应该如何在jQuery Ajax请求中传递查询字符串值?我目前是这样做的,但我相信有一种更干净的方式,不需要我手动编码。

$.ajax({
    url: "ajax.aspx?ajaxid=4&UserID=" + UserID + "&EmailAddress=" + encodeURIComponent(EmailAddress),
    success: function(response) {
        //Do Something
    },
    error: function(xhr) {
        //Do Something to handle error
    }
});

我已经见过查询字符串参数作为数组传递的例子,但我所见过的这些例子没有使用$.ajax()模型,而是直接使用$.get()。例如:

$.get("ajax.aspx", { UserID: UserID , EmailAddress: EmailAddress } );

我更喜欢使用$.ajax()格式,因为这是我习惯的格式(没有特别好的理由-只是个人偏好)。

编辑09/04/2013:

在我的问题结束后(因为“太本地化了”),我发现了一个相关的(相同的)问题- 3个赞(我没有发现它是我的错):

使用jquery做一个POST,如何正确地提供“数据”参数?

这完美地回答了我的问题,我发现这样做更容易阅读&我不需要手动使用encodeURIComponent()在URL或数据值(这是我发现不清楚的bipen的答案)。这是因为数据值通过$.param()自动编码。以防这对其他人有用,这是我用的例子:

$.ajax({
    url: "ajax.aspx?ajaxid=4",
    data: { 
        "VarA": VarA, 
        "VarB": VarB, 
        "VarC": VarC
    },
    cache: false,
    type: "POST",
    success: function(response) {

    },
    error: function(xhr) {

    }
});

我最近切换到谷歌Maps API V3。我正在处理一个简单的例子,从数组中绘制标记,但是我不知道如何对标记自动居中和缩放。

我已经搜索了净高和低,包括谷歌自己的文档,但没有找到一个明确的答案。我知道我可以简单地取坐标的平均值,但我如何相应地设置缩放?

function initialize() {
  var myOptions = {
    zoom: 10,
    center: new google.maps.LatLng(-33.9, 151.2),


    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

  setMarkers(map, beaches);
}


var beaches = [
  ['Bondi Beach', -33.890542, 151.274856, 4],
  ['Coogee Beach', -33.423036, 151.259052, 5],
  ['Cronulla Beach', -34.028249, 121.157507, 3],
  ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
  ['Maroubra Beach', -33.450198, 151.259302, 1]
];

function setMarkers(map, locations) {

  var image = new google.maps.MarkerImage('images/beachflag.png',
      new google.maps.Size(20, 32),
      new google.maps.Point(0,0),
      new google.maps.Point(0, 32));
    var shadow = new google.maps.MarkerImage('images/beachflag_shadow.png',

      new google.maps.Size(37, 32),
      new google.maps.Point(0,0),
      new google.maps.Point(0, 32));


      var lat = map.getCenter().lat(); 
      var lng = map.getCenter().lng();      


  var shape = {
      coord: [1, 1, 1, 20, 18, 20, 18 , 1],
      type: 'poly'
  };
  for (var i = 0; i < locations.length; i++) {
    var beach = locations[i];
    var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
    var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        shadow: shadow,
        icon: image,
        shape: shape,
        title: beach[0],
        zIndex: beach[3]
    });
  }
}

如何在ReactNative的水平和垂直中心文本?

我在rnplay.org中有一个示例应用程序,其中justifyContent=“中心”和alignItems=“中心”是不工作的: https://rnplay.org/apps/AoxNKQ

文字应该居中。 为什么在顶部的文本(黄色)和父容器之间有一个边距?

代码:

'use strict';

var React = require('react-native');
var {
  AppRegistry,
  StyleSheet,
  Text,
  Image,
  View,
} = React;

var SampleApp = React.createClass({
  render: function() {
    return (
            <View style={styles.container}>
                <View style={styles.topBox}>
                    <Text style={styles.headline}>lorem ipsum{'\n'}ipsum lorem lorem</Text>

                </View>
                <View style={styles.otherContainer}>
                </View>
            </View>
    );
  }
});

var styles = StyleSheet.create({

    container: {
        flex: 1,
        flexDirection: 'column',
        backgroundColor: 'red',
        justifyContent: 'center',
        alignItems: 'center',
    },

    topBox: {
        flex: 1,
        flexDirection: 'row',
        backgroundColor: 'lightgray',
        justifyContent: 'center',
        alignItems: 'center',
    },
    headline: {
        fontWeight: 'bold',
        fontSize: 18,
    marginTop: 0,
        width: 200,
        height: 80,
    backgroundColor: 'yellow',
        justifyContent: 'center',
        alignItems: 'center',
    },

  otherContainer: {
        flex: 4,
        justifyContent: 'center',
        alignItems: 'center',
    backgroundColor: 'green',
    },


});

AppRegistry.registerComponent('SampleApp', () => SampleApp);

module.exports = SampleApp;

我正在为朋友构建一个小型聊天应用程序,但不确定如何及时获取信息,而不是像强制刷新页面那样手动或基本。

目前,我正在使用简单的AJAX实现这一点,但这有一个缺点,即在短计时器过去时定期撞击服务器。

在研究长/短轮询时,我遇到了HTML5 WebSockets。这似乎很容易实现,但我不确定是否有一些隐藏的缺点。例如,我认为只有某些浏览器支持WebSockets。WebSockets还有其他我应该注意的缺点吗?

既然这两种技术做的是同样的事情,那么在什么样的场景下人们会更喜欢使用其中一种而不是另一种呢?更具体地说,HTML5 WebSockets使AJAX长/短轮询过时了吗,或者有令人信服的理由更喜欢AJAX而不是WebSockets吗?

是否有一份关于在服务器端使用不同基于python的REST框架来编写自己的RESTful api的推荐列表?最好有正反两面。

请随意在这里添加建议。:)

以下是我用来实现上述布局的代码:

.header { height: 50px; } .body { position: absolute; top: 50px; right: 0; bottom: 0; left: 0; display: flex; } .sidebar { width: 140px; } .main { flex: 1; display: flex; flex-direction: column; } .content { flex: 1; display: flex; } .column { padding: 20px; border-right: 1px solid #999; } <div class="header">Main header</div> <div class="body"> <div class="sidebar">Sidebar</div> <div class="main"> <div class="page-header">Page Header. Content columns are below.</div> <div class="content"> <div class="column">Column 1</div> <div class="column">Column 1</div> <div class="column">Column 1</div> </div> </div> </div>

我省略了用于样式化的代码。你可以在笔里看到所有这些。


上述方法是有效的,但是当内容区域的内容溢出时,会导致整个页面滚动。我只想让内容区域本身滚动,所以我在内容div中添加了overflow: auto。

现在的问题是,列本身并没有超出它们的父高度,所以边界也在那里被切断了。

这支笔显示了滚动问题。

如何将内容区域设置为独立滚动,同时仍然让其子区域超出内容框的高度?