问题
JSFiddle
body {
background-color: #111111;
color: #ffffff;
/*max-width: 100%;*/
overflow-x: hidden;
}
.row {
max-width: 100rem;
}
.svgrow {
min-width: 70rem;
}
.svgrow svg {
overflow-x: auto;
}
I want to have this svg horizontal scrollable on small screens, without the body being horizontal scrollable. In addition to that I want only relative units to be used.
I already tried to put the overflow property in different positions, but I can't get it to work. I use the foundation framework.
回答1:
In order for the scrolling to happen, you have to give the container a fixed width. The contents (the SVG) needs to have a width that is greater than the container element. Usually that means giving it a specific width, because otherwise it will just resize to its container.
.svgrow {
max-width: 100vw;
overflow-x: auto;
}
.svgrow svg {
min-width: 70rem;
}
/* My CSS */
body {
overflow-x: hidden;
}
.row {
max-width: 100rem;
}
.svgrow {
max-width: 100vw;
overflow-x: auto;
}
.svgrow svg {
min-width: 70rem;
}
svg {
margin-bottom: 2.5em;
}
.off-canvas-toolbar {
position: fixed;
height: 100%;
width: 8%;
}
<div class="container">
<div class="off-canvas position-left" id="sidebar" data-off-canvas>
</div>
<div class="off-canvas-content" data-off-canvas-content>
<div class="off-canvas-toolbar">
<div class="custom-menu-icon" data-toggle="sidebar">
<i class="fa fa-bars">Icon</i>
</div>
</div>
<div class="row svgrow">
<div class="small-12 columns">
<h1>Title</h1>
<svg version="1.2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2000 1000">
<polygon points="0,1000 60,0 2000,0 2000,1000" fill="#fdedbc"></polygon>
<polygon points="70,1000 970,0 1800,1000" fill="#7c5b18"></polygon>
</svg>
</div>
</div>
<div class="row">
<div id="searchResult" class="small-12 columns" style="">
<h2 class="center">Search Results</h2>
<div class="small-12 medium-6 large-4 columns">
<div class="searchResult">
<div class="caption">
Test <span class="creator">by User</span>
</div>
</div>
</div>
<div class="small-12 medium-6 large-4 columns">
<div class="searchResult">
<div class="caption">
Test <span class="creator">by User</span>
</div>
</div>
</div>
<div class="small-12 medium-6 large-4 columns">
<div class="searchResult">
<div class="caption">
Test <span class="creator">by User</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
来源:https://stackoverflow.com/questions/44179418/horizontal-scrolling-in-svg