简体   繁体   English

如何在全屏模式下使垂直div变为水平

[英]How can i make a vertical div go horizontal in full screen

I have 2 divs side by side inside a main div. 我在主div内并排有2个div。 Lets say- left_div & right_div. 让我们说-left_div和right_div。 When browser is in full screen mode- than left_div is 60% and right_div is 40% in width(as, main_div is 100% width). 当浏览器处于全屏模式下时-left_div为60%,right_div为40%宽度(因为main_div为100%宽度)。

Now if i restore the browser window and reduce its width- than the divs get underneath each other but still remains the same percentage as 60% & 40% of the screen. 现在,如果我还原浏览器窗口并减小其宽度,则div会彼此靠拢,但仍保持与屏幕60%和40%相同的百分比。

What i want is that if the browser width gets underneath a certain amount than the divs will get underneath each other and also fillup the whole screen width-ie become full browser width. 我想要的是,如果浏览器宽度低于某个特定值,则div彼此之间也将低于div,并且还会填满整个屏幕宽度,即成为完整的浏览器宽度。

How can i do it? 我该怎么做? Do i need to do it with JavaScript or jQuery? 我需要使用JavaScript还是jQuery?

HTML: HTML:

<div class="mainDiv">
    <div class="left">
        test
    </div>
    <div class="right">
        test2
    </div>
</div>

CSS: CSS:

div.main
{
    width:100%;
}

div.left
{
    width:60%;
    background-color:red;
    float:left;
    height:100px;
}

div.right
{
    width:40%;
    background-color:blue;
    float:left;
    height:100px;
}

@media (max-width: 350px) {
    div.left, div.right
    {
        float:none;
        width:100%;
    } 
}

check this once may be help you here is demo 检查这一次,可以帮助你在这里演示

HTML 的HTML

<div class="left-div">Left</div>
<div class="right-div">Right</div>

CSS 的CSS

.left-div{width:60%;height:100px;float:left;background-color:#000;color:#fff} 
.right-div{width:40%;height:100px;float:right;background-color:#333;color:#fff}
@media (max-width: 479px) { 
.left-div, .right-div{float:none;width:100%;} 
}

Your problem has been many people's problem. 您的问题一直是很多人的问题。 While you can write your own CSS, but you should consider screens with different DPIs and different devices and different browsers. 虽然您可以编写自己的CSS,但应考虑使用具有不同DPI,不同设备和不同浏览器的屏幕。 But Bootstrap allows you to easily manage these situations. 但是Bootstrap允许您轻松管理这些情况。

http://getbootstrap.com/ http://getbootstrap.com/

once you include bootstrap in your page, you can have two DIVs like this 在页面中包含引导程序后,您可以拥有两个这样的DIV

http://jsfiddle.net/Gt25L/119/ http://jsfiddle.net/Gt25L/119/

<div class="col-md-4"></div>
<div class="col-md-8"></div> 

Also look at the tutorials, and they guide you through how to make responsive websites using bootstrap. 还请看教程,它们会指导您完成如何使用引导程序制作响应式网站。 you will not need any JavaScript. 您将不需要任何JavaScript。 Bootstrap is based on CSS only. Bootstrap仅基于CSS。

This way you have less CSS to maintain and less chance of wrong behaviour in different browsers & devices over time. 这样一来,您需要维护的CSS更少,并且随着时间的推移,在不同的浏览器和设备中出现错误行为的机会也更少。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM