【问题标题】:how to set the width of left div based on the width of the screen如何根据屏幕宽度设置左div的宽度
【发布时间】:2018-09-13 00:23:46
【问题描述】:

首先,我使用容器流体引导类来设置主 div id='content' 的宽度。在主 div 里面,我有两个 div。 id='content_right' 的右 div 必须具有 330px 的固定宽度,无论它所在的媒体查询如何,id='content_left' 的左 div 必须灵活地适应父 div 的可变宽度。

<div class='container-fluid'>
  <div class='row'>
    <div id='content' class='col-xs-12'>
      <div id='content_left'>
         The width must be flexible with the width of the parent div. 
      </div>
      <div id='content_right'>
         330px width all the time in all bootstrap media queries
      </div>
    </div>
  </div>
</div>

我知道上面使用 jQuery 的解决方案。但我不想使用任何脚本,而是想要使用 HTML 和 CSS 的解决方案。

$(document).ready(function(){
	var parentWidth=$("#content").width();
	var left_width=parentWidth-330;
	$("#content_left").width(left_width);
});

【问题讨论】:

    标签: html css


    【解决方案1】:

    试试这个:

    #content_left{
          width: calc(100% - 330px);
          box-sizing: border-box;
     }
    

    这可能是您必须添加!important 才能持续(width: calc(100% - 330px) !important;)。

    【讨论】:

    • 一个小查询...'calc' 是否也适用于旧浏览器?
    • 欢迎您@Preetham。我很高兴帮助了你。它适用于 ie9 和其他著名的浏览器。
    • 是的,我确实赞成。但收到以下消息:“感谢您的反馈!声望低于 15 人的投票将被记录,但不要更改公开显示的帖子得分”。
    • 这不重要我的朋友 :) 我以为你忘记了。
    猜你喜欢
    • 1970-01-01
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    • 2021-07-13
    • 2015-07-16
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    相关资源
    最近更新 更多