I'm currently working on the following website design:
I have two sections (top and bottom) that are both divided into two sections (icon and content). I'm trying to use a centered svg image in the icon section although the image gets cut off whenever the size of the viewing area/browser window changes. How can I prevent this from happening?
Here is what I am currently using:
Example - js fiddle link
SVG Image - svg image
HTML -
<div id="main1">
<div id="icon1"> </div>
<div id="links1">
<p>Content</p>
<p>Content</p>
<p>Content</p>
</div>
</div>
<br/>
<div id="main2">
<div id="icon2"></div>
<div id="links2">
<p>Content</p>
<p>Content</p>
<p>Content</p>
</div>
</div>
<div class="ms-rtestate-read ms-rte-wpbox" contenteditable="false">
<div class="ms-rtestate-notify ms-rtestate-read a64b9522-0ca6-4ff7-a9fc-67a7a27d3071" id="div_a64b9522-0ca6-4ff7-a9fc-67a7a27d3071" unselectable="on">
</div>
<div id="vid_a64b9522-0ca6-4ff7-a9fc-67a7a27d3071" unselectable="on" style="display: none;">
</div>
</div>
CSS -
<style>
#main1 > div { min-height: 100px; }
#main1 {
/* overflow to handle inner floating block */
overflow: hidden;
border-radius: 25px;
border: 2px solid #73AD21;
padding: 20px;
margin-right: 5%;
margin-left: 5%;
}
#icon1 {
float: left;
width: 29%;
border-right:thin solid red;
}
#links1 {
float: right;
width: 70%;
}
#main2 > div { min-height: 100px; }
#main2 {
/* overflow to handle inner floating block */
overflow: hidden;
border-radius: 25px;
border: 2px solid #73AD21;
padding: 20px;
margin-right: 5%;
margin-left: 5%;
}
#icon2 {
float: left;
width: 29%;
border-right:thin solid red;
/* background: url('/support/Shared%20Documents/065__calendar.svg') no-repeat center; */
background-image: url('/support/Shared%20Documents/065__calendar_crop.svg');
background-repeat: no-repeat;
background-size: cover;
}
#links2 {
float: right;
width: 70%;
}
</style>
Use background-size: contain
instead of cover
and use background-position: center center
to keep it centered.
Review the documentation from W3schools:
Cover
Scale the background image to be as large as possible so that the background area is completely covered by the background image. Some parts of the background image may not be in view within the background positioning area
Contain
Scale the image to the largest size such that both its width and its height can fit inside the content area
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments