JSFiddle - React, Tailwind, and code Playground
HTML
<div id="test-1" class="tester"></div>
<div id="test-2" class="tester"></div>
<div id="test-3" class="tester"></div>
<div id="test-4" class="tester"></div>
<div id="log"></div>
<div id="log2"></div>
CSS
body {
margin: 20px;
}
.tester {
height: 50px;
background: #999399;
margin-top: 0px;
margin-bottom: 20px;
}
#test-1 {
width: 90%;
margin-right: 5%;
margin-left: 5%;
}
#test-2 {
width: 90%;
margin-right: 5%;
margin-left: 5%;
min-width: 321px;
}
#test-3 {
margin-right: 20px;
margin-left: 20px;
}
#test-4 {
margin-right: 20px;
margin-left: 20px;
min-width: 321px;
}
JavaScript
$(document).ready( function(){
writeMargins();
function writeMargins(){
var s1 = "";
var $log = $('#log');
s1 += "<p>---- jQuery --- <br>";
s1 += $('#test-1').css('marginLeft') + " | " + $('#test-1').css('marginRight') + " <br>";
s1 += $('#test-2').css('marginLeft') + " | " + $('#test-2').css('marginRight') + " <br>";
s1 += $('#test-3').css('marginLeft') + " | " + $('#test-3').css('marginRight') + " <br>";
s1 += $('#test-4').css('marginLeft') + " | " + $('#test-4').css('marginRight') + " <br>";
s1 += "</p>";
$log.append(s1);
var s2 = "";
var $log2 = $('#log2');
var cs1 = window.getComputedStyle( document.getElementById('test-1'), null );
var cs2 = window.getComputedStyle( document.getElementById('test-2'), null );
var cs3 = window.getComputedStyle( document.getElementById('test-3'), null );
var cs4 = window.getComputedStyle( document.getElementById('test-4'), null );
s2 += "<p>---- javascrpt --- <br>" ;
s2 += cs1.marginLeft + " | " + cs1.marginRight + " <br>";
s2 += cs2.marginLeft + " | " + cs2.marginRight + " <br>";
s2 += cs3.marginLeft + " | " + cs3.marginRight + " <br>";
s2 += cs4.marginLeft + " | " + cs4.marginRight + " <br>";
s2 += "</p>";
$log2.append(s2);
}
});