Home >Web Front-end >HTML Tutorial >Ask for advice! Problem with images automatically adapting to size_html/css_WEB-ITnose
#div_left_sidebar{
margin:10px auto 10px 10px;
border:0px #00ff00 solid;
background: url(images/side_beijing.jpg) #CCC no-repeat left top;
width: 200px;
height:600px;}
The size of side_beijing.jpg is 364X775. How can I make this background image automatically adapt without changing the image size? The size of the div, what should I do if the image size is smaller than the size defined by the div? Thank you for your advice!
background-size: cover;
background-size: cover;
Success, Thank you so much, I have another question,
I have three layers nested in a div_main. How can I achieve the effect of arranging them side by side? Secondly, I used absolute positioning for the three layers but it still doesn’t work. Please advise, thank you!
css code:
#div_main{
padding:0px;
width:1000px;
background:url(images/div_main_beijing.jpg) #CCC no-repeat left top;
margin:20px auto auto auto;
border: 1px #CCC solid;
}
#div_left_sidebar{
margin:10px auto 10px 10px;
border:0px # 00ff00 solid;
background: url(images/side_beijing.jpg) #CCC no-repeat left top;
background-size:cover;
width: 200px;
height:600px;
}
#div_zhongjian_sidebar{
position:absolute;
left:220px;
top:10px;
margin:10px auto 10px auto;
border:0px #00ff00 solid;
background: url(images/zhongjian_beijing.jpg) #CCC no-repeat left top;
background-size:cover;
width: 560px;
height:600px;
}
#div_right_sidebar{
position:absolute;
left:790px;
top:10px;
margin:10px 10px 10px auto;
border: 0px #00ff00 solid;
background: url(images/side_beijing.jpg) #CCC no-repeat left top;
background-size:cover;
width: 200px;
height:600px;
Page code:
float:left;
}
position:absolute; Get away
float:left;
}
position:absolute; Go away
Is this written on a separate line in the style sheet? Sorry, I'm new to css and I don't know much about it. Could you please explain it to me? Thank you!