Display scrollbar for div according to media width - html

I am creating a table inside a tab. I want to set the width of tab to the width of media screen but keep the width of table fixed to 630px. The max-width of div should be 400px. When the table does not fit into the div, it should display a horizontal scrollbar.
The div is successfully showing a horizontal scrollbar. But, when I resize the window, the scrollbar along with table is hiding inside the div. I want to display the scrollbar according to media width.
The example will become clear:JsFiddle

Please use tab and tab-content class width 100% may be it will work for you. I am sharing your complete code below with my changes i have done some width changes px to %, and what is the purpose for #model margin-right:1000px it will work find without margin.
#tabs-container {
height: auto;
overflow: hidden;
margin-bottom: 40px;
position: relative;
top: 60px;
border: 1px solid #ddd;
padding-top: 10px;
max-width: 400px;
}
.tab {
border: 1px solid #d4d4d1;
background: linear-gradient(#f8fbea, #fff);
margin: -20px 10px 10px 10px;
float: left;
position: relative;
top: 0;
z-index: 3;
width:100%;
height: auto;
overflow-x: auto;
overflow-y: hidden;
}
.tab-content {
padding: 10px;
width:100%
}
#model {
font-size: 12px;
margin: -10px -10px -10px -320px;
position: relative;
margin: 0 auto;
font-family: tahoma;
}
#model {
margin-right: 1000px;
width: 630px;
}
#model td {
vertical-align: middle;
}
#model tr:first-child td {
font-weight: 600;
text-align: center;
background-color: #ebebeb;
}
#model tr:nth-child(even) {
background-color: #f6f6f6;
}
#model tr:nth-child(odd) {
background-color: #fff;
}

Related

Place border in a 100% height and width div - right and bottom border outside

I'm using Firefox and want to create a div with height and width 100% and a white border with 10px. The right and bottom part of the border seems outside the div and body.
https://jsfiddle.net/tob6g805/
html {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
}
body {
height: 100%;
width: 100%;
padding: 0px;
margin: 0px;
background-color: #ffb0a3;
overflow: hidden;
}
.div-with-border {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
border: 10px;
border-color: #ffffff;
border-style: solid;
}
A workaround was to add border right and bottom and to decrease the width and height of the div... but this becomes especially problematic when resizing the page.
https://jsfiddle.net/1wtjkybm/
html {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
}
body {
height: 100%;
width: 100%;
padding: 0px;
margin: 0px;
background-color: #ffb0a3;
overflow: hidden;
}
.div-with-border {
width: 95%;
height: 95%;
margin: 0px;
padding: 0px;
border: 10px;
border-bottom: 100px;
border-right: 100px;
border-color: #ffffff;
border-style: solid;
}
Thanks for any help.
By default in the CSS box model, the width and height you assign to an
element is applied only to the element's content box. If the element
has any border or padding, this is then added to the width and height
to arrive at the size of the box that's rendered on the screen. This
means that when you set width and height, you have to adjust the value
you give to allow for any border or padding that may be added.
Source: https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing
There's a CSS property called box-sizing which allows you to adjust this property. Adding box-sizing: border-box to .div-with-border should fix this for you!
Take a look at the link above. They have a live example that demonstrates box-sizing.
Here's one solution using flexbox
body,
html {
height: 100%;
width: 100%;
}
body,
html,
html * {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
height: 100%;
width: 100%;
background-color: #ffb0a3;
display: flex;
justify-content: center;
align-items: center;
}
.div-with-border {
width: 90%;
height: 90%;
border: 10px;
border-color: #ffffff;
border-style: solid;
text-align:center;
font-size:7vw;
font-family:Open Sans;
font-weight:bold;
color:#d46a58;
}
Also, always do:
<meta name="viewport" content="width=device-width,initial-scale=1.0">
in the <head> tag.

Bootstrap Panel with horizontal scrollbar

Been going round & round in circles. I've got a Bootstrap 3 panel and within the panel-body I'm adding divs dynamically (MVC razor) which are stacked:
.test-result {
float: right;
width: 150px !important;
height: 100% !important;
border: solid 1px;
min-height: 100% !important;
background-color: lightgray;
margin-left: auto;
margin-right: auto;
padding-left: 15px;
padding-right: 15px;
display: inline-block;
white-space: normal;
}
Once these exceed the width of the panel-body they obviously start stacking etc.
I want the panel-body content to stay side by side and to have a horizontal scrollbar. I've added overflow-x: scroll etc and nowrap but had no joy. Please help :)
You can do this with a div like this:
<div class="scroll">
</div>
Then you need to apply the following styles:
.scroll {
overflow: auto;
white-space: nowrap;
}
Once the width inside the div exceeds either the screen width or the div width (you can define), it will apply the horizontal scroll bar.
Update your CSS like below
You can define the with of resultContainer based on the number of child containers you want to scroll through. So if each test-result is 150px in width and you want to accommodate 100 such containers then make the width of resultContainer to be 150 x 100 i.e 15000px.
<style>
.tab-pane{
width:100%;
overflow: auto;
}
.resultContainer{
width:600px; //4 containers x 150px
}
.test-result {
float: left;
width: 150px !important;
height: 100% !important;
border: solid 1px;
min-height: 100% !important;
background-color: lightgray;
margin-left: auto;
margin-right: auto;
padding-left: 15px;
padding-right: 15px;
display: inline-block;
white-space: normal;
}
.new-test-group {
float: left;
width: 150px !important;
height: 100% !important;
border: solid 1px;
min-height: 100% !important;
background-color: lightgreen;
margin-left: auto;
margin-right: auto;
padding-left: 15px;
padding-right: 15px;
display: inline-block;
white-space: normal;
}
.eachNewTest {
border: solid 1px;
cursor: pointer;
}
</style>
UPDATE - Adding with width of .resultContainer dynamically
<script>
$(document).ready(() => {
let resultContainerWidth = 150;
let resultContainerCount = $('.test-result').length;
$('.resultContainer').width(resultContainerWidth * resultContainerCount);
});
</script>

My button's text is not resizing?

My button has following CSS code. When I resize the window the text falls outside of the div in chrome. (usng the mobile layout)
http://www.syntra-limburg.be/voltijds-praktijkleren
a.syntra-green-button {
background-color: #6faf3c;
border: 1px solid #9dcc77;
color: white;
padding: 15px 2%;
margin: 5px auto 0px;
position: relative;
font-size: 1.35em;
width: 190px;
max-width: 100%;
text-align: center;
display: block;
}
I fixed it using following code but I was wondering if there isn't a more elegant solution? I do not understand why this is happening.
.responsive-layout-mobile a.syntra-green-button {
font-size: 1em;
}
Try font-size percent like font-size: 115%;
css
a.syntra-green-button {
background-color: #6faf3c;
border: 1px solid #9dcc77;
color: white;
padding: 15px 2%;
margin: 5px auto 0px;
position: relative;
font-size: 115%;
width: 190px;
text-align: center;
display: block;
}
Set width to auto. You limited it cause of that it overflows
You can change how the width of the button is rendered using the below. First change the width to be percent based for desktop style displays:
width: 30%;
but also add a minimum width for when it it resized for a responsive device that fits the entire word:
min-width: 200px;
So full class would be:
a.syntra-green-button {
background-color: #6faf3c;
border: 1px solid #9dcc77;
color: white;
padding: 15px 2%;
margin: 5px auto 0px;
position: relative;
font-size: 1.35em;
width: 200px;
min-width: 30%;
max-width: 100%;
text-align: center;
display: block;
}
See this JSFiddle: http://jsfiddle.net/8tBQ3/
.responsive-layout-mobile a.syntra-green-button {
font-size: 100%;
}

When browser is resided part of the header background is missing

The header in the pic is styled in 3 parts the top part contains a div with the width 100% and background color and inside the dive there is a div styled as a container which holds all elements at the top. This container has a width of 1000px and min-width of 960px and margin: 0 auto;
but when u re-size the browser and scroll with the scroll-er at the bottom the header appears as follows.
What am I doing wrong here for it to render this way?
CSS
#header {
height: 120px;
width: 100%;
margin-bottom: 15px;
}
#header .nav-content-holder {
width: 1000px;
min-width: 960px;
margin: 0 auto;
}
#header .header-menu-top {
height: 20px;
background-color: #d8d4cf;
color: #Color-Txt-black;
}
#header .header-menu-middle {
height: 70px;
background-color: #Color-FM-brown;
color: #Color-Txt-white;
}
#header .header-menu-bottom {
border-top: 1px solid #d3d3d3;
height: 28px;
background-color: #Color-FM-brown;
margin-bottom: 15px;
color: #Color-Txt-white;
}
HTML
Without code it is impossible to know what is going on but you need to try min-width: 1040px; on body.

How can I make the content scrollable, but not the header and neither the footer?

This question would have been a duplicate of header and footer fixed, content scrollable and Fixed header, footer with scrollable content if not for one detail, which is very important for me - I do not want to specify a fixed height and width for the content.
http://jsfiddle.net/mark69_fnd/PWRDa/ contains a real form with dummy data, demonstrating the problem - resizing the window makes the scrollbars appear, but on the page, rather than on the form. In the current layout the menubar and the statusbar are scrolled out of view and I want them to remain fixed, while the form data gets scrolled.
Please, do not provide a solution with absolute width and/or height. I prefer calculating them in javascript, rather than baking them into the CSS, unless it is 100%. Of course, pure HTML/CSS solution is preferable.
Here is the CSS:
html, body, .yui3-app-views {
height: 100%;
width: 100%;
}
.container {
position: relative; /* needed for footer positioning*/
margin: 0 auto;
height: auto;
min-height: 100%;
background-color: #eee;
}
.content {
background-color: #ddd;
padding: 0em 0em 2em; /* bottom padding for footer */
overflow: auto;
}
#footer {
position: absolute;
width: 100%;
bottom: 0; /* stick to bottom */
background-color: #ccc;
}
#status {
border: solid 1px #000000;
}
#status .error {
color: red;
font-weight: bold;
}
/* ------------------------------------------------------------------------------------*/
.char {
display: inline-block;
vertical-align: top;
}
.line {
white-space: nowrap;
}
/* --------------------------------- fieldset and legend ------------------------------*/
.fieldset {
border: 2px groove threedface;
margin-top: 1em;
}
.fakeFieldset {
padding: 2px;
}
.fieldset > div.legend:first-child {
display: inline-block;
text-align: left;
margin-left: 10px;
background: #ddd;
position: relative;
top: -0.7em;
}
.merge-bottom {
margin-bottom: -2px;
}
/* ------------------------------------ Forms ------------------------------*/
form div {
white-space: nowrap;
}
form select, form input {
margin: 2px;
border: 1px groove;
}
form label:not(.same-line) {
width: 8em;
text-align: right;
display: inline-block
}
#cust-balance {
text-align: center;
}
.ccExpDate {
width: 2em;
}
#cust-salutation {
width: 4em;
}
.postalCode {
width: 7em;
}
#cust-ccAddress {
width: 20em;
}
​
// Updated with input from asker.
This works great. Mine have widths set to 100%, but of course you can do that in JS if you want.
You need to give the header and the footer position:fixed
I also put some padding in the .content div to make room for the top header.
Like the following:
html, body, .yui3-app-views {
height: 100%;
width: 100%;
}
.content {
background-color: #ddd;
padding: 2em 0em; /* padding for footer and header */
}
.menubar {
position: fixed;
top: 0px;
width: 100%;
z-index:1;
}
#footer {
position: fixed;
width: 100%;
bottom: 0; /* stick to bottom */
background-color: #ccc;
}