Serhiy Serhiy - 11 days ago 5
Sass (Sass) Question

How to set div's width equal to another div using sass/css?

I have first element:

<div layout="column" layout-align="start center" class="focusBox flex "></div>


it's css:

.focusBox {
margin-top: 2%;
border: 1px solid $alto;
height: calc(100vh - 182px);
background-color: $white;
}


and second element:

<div flex class="subFolderBox" ></div>


it's css:

.subFolderBox {
margin-bottom: 1%;
border: 1px solid $alto;
}


How to set width of first element to second using sass or css?

Answer

im not sure about css/scss but if you prefer with jquery you can do it like this

$(document).ready(function() {
  $(".second_div").css({
    'width': ($(".first_div").width() + 'px')
  });
});
.second_div,
.first_div {
  border: 1px solid black;
  padding: 2px 4px;
  display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="first_div">First Div some text</div>
<div class="second_div">Second.width </div>

Comments