幅が7%、少なくとも100pxのマージンが必要ですが、これを行うにはどうすればよいですか?
私は試した
margin:7% 100px;
しかし、それは機能しませんでした
最小証拠金のようなものはありますか?
100pxのマージンを割り当ててから、javascriptを使用してこれをオーバーライドするか(特定の要件が満たされている場合)、またはメディアクエリを使用することができます
たとえば、幅が500px以上の場合、マージンが100pxではなく7%になるようにスタイルを変更します
答えが見つかりました、これは機能するコードです:
<script type='text/javascript'>
window.addEventListener('resize', function(event){
if (GetWidth() < 1373) {
console.log('changed < 1372');
document.getElementById('main').style.marginLeft = '100px';
}else{
console.log('changed > 1372');
document.getElementById('main').style.marginLeft = '7%';
}
}, false);
function GetWidth()
{
var width = 0;
if (self.innerHeight)
{
width = self.innerWidth;
}
else if (document.documentElement && document.documentElement.clientHeight)
{
width = document.documentElement.clientWidth;
}
else if (document.body)
{
width = document.body.clientWidth;
}
return width;
}
</script>
ウィンドウのサイズ変更をすべてチェックし、サイズを変更するたびに、関数GetWidthを実行します。ページ幅が1372未満の場合、IDが「main」のdivのcssが変更されます。