Bootstrap Panel with horizontal scrollbar - html

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>

Related

How to alter my CSS to ensure that the textarea height always matches the height of its div container?

I have a textarea inside a div, and I wish for the text area height to match the height of the div container.
Currently, the width fits perfectly, however the textbox (which begins empty) only fills about 20% of the div height.
And when an ajax call grabs some text and populates the textarea, the textarea height remains at about 20% of the div and provides a scroll bar.
How can I alter my CSS to ensure that the textarea height always matches the height of its div container?
#answerBox {
width: 100%;
height: 100%;
box-sizing: border-box;
margin: 5px auto;
padding: 5px;
font-size: 10px;
text-align: left;
position: relative;
}
#answerBoxDiv {
width: 90%;
min-height: 50%;
margin: 5px auto;
border: 4px solid #00bfb6;
padding: 5px;
font-size: 10px;
text-align: left;
position: relative;
}
<div id="answerBoxDiv">
<textarea id="answerBox"></textarea>
</div>
You need to explicitly set a height of the parent container (whether that is in px or rem etc) - that way the height: 100% of the textarea will fill to the container.
The expand on text content cannot be done with simple css - you need js to determine the heaight of the content and adjust the parent container accordingly.
The only way tyou can keep height: 100% on the parent container is its ancestor has a height set (eg 100vh) - that way the browser can determine the height of each DOM element and size the text area accrodingly.
UPDATE - I have added a js function to automatiucally increae the height of the parent container on the input. (the textarea autoincreases in height since it is 100% of the parentThis will need massaging - but when you type into the textarea the height will auto expand.
function setHeight(element) {
const container = document.getElementById("answerBoxDiv");
const height = element.scrollHeight;
if(height > 100) {
container.style.height = (element.scrollHeight)+"px";
}
}
#answerBoxDiv {
width: 90%;
height: 100px; **// this is needed - but can be in px / rem / vh or other but NOT % unless its parent has its height set.**
margin: 5px auto;
border: 4px solid #00bfb6;
padding: 5px;
font-size: 10px;
text-align: left;
position: relative;
}
#answerBox {
width: 100%;
height: 100%;
box-sizing: border-box;
padding: 5px;
font-size: 10px;
text-align: left;
position: relative;
resize: vertical;
overflow: hidden
}
<div id="answerBoxDiv">
<textarea id="answerBox" oninput="setHeight(this)"></textarea>
</div>
You can use the CSS height: 100%; property on the textarea element to make it fill the entire height of its parent container, the #answerBoxDiv. Additionally, you can remove the min-height property from the #answerBoxDiv to make sure the container's height is always equal to the height of its content.
Here's the updated CSS:
#answerBox {
width: 100%;
height: 100%;
box-sizing: border-box;
margin: 0;/*keep it zero*/
padding: 5px;
font-size: 10px;
text-align: left;
position: relative;
}
#answerBoxDiv {
width: 90%;
margin: 5px auto;
border: 4px solid #00bfb6;
padding: 0px;/*keep it zero*/
font-size: 10px;
text-align: left;
position: relative;
}
And the updated HTML:
<div id="answerBoxDiv">
<textarea id="answerBox"></textarea>
</div>
Percentage height does not work with a min-height parent, you would either need to give your parent a height or you could use flex:
html,
body {
height: 100%;
margin: 0;
}
#answerBox {
flex-grow:1;
width: 100%;
box-sizing: border-box;
margin: 5px auto;
padding: 5px;
font-size: 10px;
text-align: left;
position: relative;
}
#answerBoxDiv {
width: 90%;
min-height: 50%;
margin: 5px auto;
border: 4px solid #00bfb6;
padding: 5px;
font-size: 10px;
text-align: left;
position: relative;
display: flex;
flex-direction: column;
}
<div id="answerBoxDiv">
<textarea id="answerBox"></textarea>
</div>
You can try this
#answerBox {
height: 100%;
resize: none;
}
try keeping the min-height of the textarea as 100% or nearby or try using
object-fit: contain(or cover) on your text area
Give specific height for #answerBoxDiv parent div. So you will get appropriate height for this div.
<div class="parent-div" style="height: 100%;">
<div id="answerBoxDiv">
<textarea id="answerBox"></textarea>
</div>
</div>
#answerBox {
width: 100%;
height: 100%;
box-sizing: border-box;
margin: 0;
padding: 5px;
font-size: 10px;
text-align: left;
resize: none;
border: none;
}
#answerBoxDiv {
width: 90%;
min-height: 50%;
margin: 5px auto;
border: 4px solid #00bfb6;
padding: 0;
position: relative;
}

html, css automatically resize/adjust width to fit content

I have some html content with following structure:
<div class="message-container">
<p class="message-value">someVal</p>
<div class="message-attribute">someUsername</div>
<div class="message-attribute">11-09-2017 12:30</div>
</div>
So, I want to scale my message-container up when it gets long values in message.value and scale it down as far as possible to min-width in the other way.
I also wan't to specify max-width for this props.
I've done this:
.message-container {
resize: both;
margin: 10px;
padding-left: 10px;
padding-right: 10px;
padding-top: 2px;
color: #ffffff;
border-radius: 20px;
min-width: 100px;
max-width: 400px;
width: auto;
height: auto;
background-color: #80CBC4;
}
.message-value {
resize: both;
float: left;
max-width: 380px;
word-wrap: break-word;
height: auto;
}
.message-attribute {
padding-left: 50px;
width: 150px;
display: block;
color: #607D8B;
}
and message-username and message-datetime has fixed width.
Finally, I'm alsways getting max-width in my message-container even when it has free space to cut it down
https://jsfiddle.net/Lwrpegqe/
As you can see in jsfiddle width is too long with following content it could be shorter
Main purpose to resize block automatically
See the solution.
.message-container {
resize: both;
margin: 10px;
padding-left: 10px;
padding-right: 10px;
padding-top: 2px;
color: #ffffff;
border-radius: 20px;
min-width: 100px;
max-width: 400px;
width: auto;
height: auto;
background-color: #80CBC4;
}
.message-value {
resize: both;
float: left;
max-width: 380px;
word-wrap: break-word;
height: auto;
display: inline;
}
.message-attribute {
padding-left: 50px;
width: 150px;
display: inline;
color: #607D8B;
}
https://jsfiddle.net/Lwrpegqe/2/
Add display: inline-block; to your .message-container
Inline elements only take up the space of the content. A div is always a block element unless specified.
Give width and height in percentage (%).
Hope it will work for you.
.your-class {
width:100%;
height:100%;
}
just use w-100 in bootstrap 4 to fit to 100% width of container element

Display scrollbar for div according to media width

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;
}

Why DIVs and Images are not resizing, but being cutted?

Ok, so here we go:
http://judao.com.br/direto-do-epicentro-de-terremoto-a-falha-de-san-andreas/
The content images are huge, 100% width, with a caption. BUT on a 1080p resolution. Anything below that cuts the images, the caption AND the video.
The divs are inside another one, that says max-width: 960px. Here's what I did to make it huge.
#tamanhao {
display: inline-block;
left: -50%;
outline: 0;
overflow: hidden;
position: relative;
text-align: center;
height: auto !important;
width: 200%;
}
#tamanhao img {
max-width: 100% !important;
padding-top: 32px !important;
height: auto !important;
}
.caption {
float: left;
display: inline;
margin-top: -16px;
font-size: 14px;
color: #888;
padding-left: 32px !important;
max-width: 470px;
font-style: italic;
font-family: exo;
text-align: left !important;
line-height: 14px !important;
}
#videozao {
display: block;
left: -50%;
outline: 0;
overflow: hidden;
position: relative;
text-align: center;
width: 200%;
max-height: 744px !important;
}
#videozao iframe {
margin: 0 auto;
display: block;
width: 1280px !important;
height: 720px !important;
position: relative;
}
What am I doing wrong? How can I make it right?
This is because you are using static widths for your content, meaning you're using px instead of percentage. Percentage will make your content to be responsive in smaller screens fiting the screen while resizing the window, while for example 500px will always maintain that same value, unless you use media queries. Here's a example, Resize the window where the images are on this link to see it work.
Code Explanation
<div class="responsiveWidth">
...Conteúdo Responsivo...
<img src="http://i1.wp.com/www.24x7photography.com/wp-content/uploads/2010/08/random2.jpg?w=720" width="500">
</div>
<div class="staticWidth">
...Conteúdo Estático...
<img src="http://i1.wp.com/www.24x7photography.com/wp-content/uploads/2010/08/random2.jpg?w=720" width="500">
</div>
This 2 div's look exaclty the same, but here's where the magic happens
CSS
.staticWidth {
width:500px;
margin:10px;
border:1px solid #000;
}
.responsiveWidth {
width:100%; /* This says the div to stay always 100% of it's parent, in this case it's `body` because we don't have any div container */
margin:10px;
border:1px solid #000;
}
.responsiveWidth img{
width:100%; /* This will make the width of the image 100% as well, the height it's automattic because we didn't set one nor on HTML or CSS */
}
Ok, guys, I solved it. I never heard about the VW thing... And when I did, it worked. Here's the final solution. :)
#tamanhao {
position: relative;
left: 50%;
height: auto !important;
margin: 0px 0 0 -50vw;
width: 100vw;
}
#tamanhao img {
max-width: 100vw !important;
padding-top: 32px !important;
height: auto !important;
}
#videozao {
position: relative;
left: 50%;
max-height: 720px !important;
margin: 0px 0 0 -50vw;
width: 100vw;
}
#videozao .fve-video-wrapper {
margin-left: auto;
margin-right: auto;
max-width: 1280px !important;
max-height: 720px !important;
}
#videozao iframe {
max-width: 1280px !important;
max-height: 720px !important;
}
Thank you / Obrigado! :))))

Div is not centered properly, why?

explainmehow.com
The white boxes in the middle of the screen, which have text in them, are not centered. You can see it extra clear, if you make your screen really small.
White box:
.step {
background-color: white;
width: 90%;
margin: 0 auto;
margin-top: 15px;
margin-bottom: 15px;
padding: 20px;
color: #303030;
display: block;
float: left;
}
Change width: 100%; to width: 90%; so you aren't extending the page by adding margin-right/left:5% and set padding:15px; to padding: 15px 0; so only top and bottom gets padding:
#contentholder {
background-color: #eeeeee;
margin-left: 5%;
margin-right: 5%;
min-height: calc(100vh - 210px);
width: 90%;
}
Then:
Get rid of float:left on the class .step. Boom it is all centered.
The CSS of the main content div is this:
#contentholder {
background-color: #EEEEEE;
padding: 15px;
margin-left: 5%;
margin-right: 5%;
min-height: calc(100vh - 210px);
width: 100%;
}
Take a look at the box model. The width, padding, and margin together make it so that the total width of the element is larger than the width of the screen. The white boxes inside that element are centered properly though.
So, the problem isn't the white boxes, the problem is the parent element.