Answer the question
In order to leave comments, you need to log in
How to set automatic width of DIV and dynamically change the width when the browser window is reduced?
There is such a page.
We want the red DIV to be 200px and the green to the rest of the width. Both DIVs in one row.
Here is the code:
<div class="wrapper">
<div class="content left">
<div>asd
</div>
</div>
<div class="content right">
<div>asd
</div>
</div>
</div>
.wrapper {
text-align: center;
width:100%;
background:blue;
vertical-align:top;
}
.left {
width:200px;
display:block;
background:red;
height:200px;
}
.right {
width:80%;
display:block;
background:lime;
height:200px;
}
@media (min-width: 500px) {
.content {
display: inline-block;
}
}
.wrapper {
text-align: center;
width:100%;
background:blue;
vertical-align:top;
}
.left {
width:200px;
display:block;
background:red;
height:200px;
}
.right {
width:80%;
display:block;
background:lime;
height:200px;
}
@media (min-width: 500px) {
.content {
display: inline-block;
}
.left {
width:100%;
}
.right {
width:100%;
}
}
Answer the question
In order to leave comments, you need to log in
vertical-align:top; you can remove it, it doesn’t work for block elements anyway,
and if there is a width, don’t automatically specify it at all, the block will stretch to full screen and of course it will shrink
, you can set a common margin: 20px; for example, it will be completely 20px sides, but it can collapse on top
https://codepen.io/topicstarter/pen/Ldzjpy
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question