設(shè)置對象四邊的外延邊距。
站在用戶的角度思考問題,與客戶深入溝通,找到孝南網(wǎng)站設(shè)計與孝南網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站制作、成都網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名與空間、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋孝南地區(qū)。
如果提供全部四個參數(shù)值,將按上-右-下-左的順序作用于四邊。
如果只提供一個,將用于全部的四邊。
如果提供兩個,第一個用于上-下,第二個用于左-右。
如果提供三個,第一個用于上,第二個用于左-右,第三個用于下。
思路就是:獲取屬性和屬性值,拼接字符串,然后通過innerHtml將元素渲染到頁面中。具體代碼如下
!DOCTYPE html
html
head
title/title
style
.block{
display: flex;
margin-bottom: 10px;
}
.block label{
width: 60px;
text-align-last:justify;
text-align:justify;
text-justify:distribute-all-lines;
}
#attr, #value{
width: 220px;
line-height: 20px;
margin-left: 20px;
}
#content div{
width: 200px;
height: 200px;
color:#f00;
text-align: center;
line-height: 200px;
background-color:rgb(109, 203, 240);
}
/style
/head
body
div class="block"
label屬性/label:
input type="text" id="attr" /
/div
div class="block"
label屬性值/label:
input type="text" id="value" /
/div
button onclick="setAttr()" style="margin-bottom: 20px;"設(shè)置屬性/button
div id="content"/div
/body
script
window.onload = function(){
document.getElementById("content").innerHTML = `divJavascript有點意思/div`;
}
var style = "";
function setAttr(){
style += `${document.getElementById("attr").value}:${document.getElementById("value").value};`;
document.getElementById("content").innerHTML = `div style="${style}"Javascript有點意思/div`;
}
/script
/html
js設(shè)置style屬性時。將“-”去掉,“-”后的字母大寫。
如:左邊距 margin-left .用js 寫就是 style.marginLeft='34px';
獲取padding方法如下:
$(document).ready(function () {
var $h1 = $('h1');
console.log($h1);
$h1.after($('divPadding-top: ' + parseInt($h1.css('padding-top')) + '/div'));
$h1.after($('divMargin-top: ' + parseInt($h1.css('margin-top')) + '/div'));
});
獲取margin方法如下
var margT = jQuery(this).css('margin');
css中padding和margin的區(qū)別
margin 外邊距
border 邊框
padding 內(nèi)邊距
也就是說 設(shè)置margin 那么他所占據(jù)的空白地方會是在邊框外面
div id="ddd"
div class="left" img src="img/123.jpg"http://div
div class="left"img src="img/345.jpg"/ /div
/div
////////////////
var divs=ddd.getElementsByTagName("div");
divs[0].style.marginRight = "20px";
divs[1].style.marginLeft = "20px";
分享名稱:javascript邊距,js外邊距
新聞來源:http://jinyejixie.com/article6/dseddig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、微信小程序、標(biāo)簽優(yōu)化、App設(shè)計、網(wǎng)站收錄、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)