I have a small div with overflow:auto; but when the the scroll bar appears it covers up a great deal of the div. This can be avoided by using overflow:scroll;, but then you get the unsightly faded scroll bar when there is no overflow. Is there a way of putting the scroll bar outside of the div without using overflow:scroll;? Thanks.
here is a demonstration jsfiddle
.alphabet{ display:inline-block;
overflow-y:auto;
overflow-x:hidden;
border:1px solid;
height:50;
}
<div class = "alphabet">abcdefgh<br>
ijklmnop<br>
qrstuvwx
</div>
If it's an option to use a container element around .alphabet, you can set the vertical scroll on that. I've added the <hr> to fake an always-visible bottom border that won't also go under the scrollbar.
HTML:
<div class="container">
<div class="alphabet">
abcdefgh<br />
abcdefgh<br />
abcdefgh<br />
abcdefgh<br />
</div>
</div>
<hr>
CSS:
.container{
overflow-y:auto;
overflow-x:hidden;
height:50px;
width:100px;
}
.alphabet{
width:100%;
overflow:visible;
box-sizing:border-box;
border:1px solid;
border-bottom:0;
}
hr{
margin:0;
height:0;
width:85px;
border:0;
border-bottom:1px solid;
}
With inner border: http://jsfiddle.net/Q32gG/1/
If you don't actually care about the scrollbar showing inside the border, you can drop the <hr> and add a full border to .container instead (http://jsfiddle.net/V3MbV/3/).
Instead of using and outside-scrollbar, why not to use some right padding as so
.alphabet{ display:inline-block;
overflow-y:auto;
overflow-x:hidden;
border:1px solid;
height:50;
padding-right:15px;
}
Or if you prefer, using em units to match a character whatever size you are using
padding-right:1em;
PD: By the way there is a typo in your example. The period should be previous it should be .alphabet {
You can also use a combination of padding right and setting the width to 100% + 10px. Works like a charm.
.alphabet {
width: 100%;
box-sizing: border-box;
border: 1px solid;
border-bottom: 0;
// for outside scrollbar
width: calc(100% + 10px);
overflow-y: auto;
padding-right: 10px;
}
Related
My html is :
<div id="outer">
<header><h1>The Header</h1></header>
<div id="contenttab">
<table>
blablabla
</table>
</div>
</div>
My CSS :
#outer{
height:70%;
width:900px;
left:50%;
margin:0 auto;
position:absolute;
top:20px;
z-index:1001;
transform:translate(-50%, 0);
-webkit-transform:translate(-50%, 0);
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
header{
background-color:#f6f7f9;
padding:10px;
font-size:15px !important;
font-weight:bold !important;
text-align:center;
width:100%;
}
#contenttab{
height:100%;
overflow-y:auto;
}
why my contenttab exceeded the height of #outer div ? how to fix that? I have try adding border-box css to parent div but not solve my problem . . .
I just tried out your posted html/css and your #contenttab div is exceeding the height of it's container because of your css rule of height: 100% on the #contenttab;
It's a lot easier to see/debug the issue using borders on your elements, add the following:
#outer {
border: 1px solid #000;
}
#contenttab {
height: 100%;
overflow-y: auto;
border: 1px solid #ffa500;
}
You are telling the #contenttab to have 100% full height of it's container, however then you are also adding additional content(the header element) which causes the internal elements to have more than 100% height than it's container can hold.
Either change the height rule on the #contenttab to auto or less than 100%. Or add css rule overflow: hidden(or auto) to your #outer css rule.
I am developing a website. Now I am beautifying my website. Now I am having a problem with designing my website.
This is something what I want to achieve
As you can see in the higlighted area, there is a image and textarea in the div. I want to get it responsive. I mean, it will have the max-width, when the user low down the screensize, it will become smaller, but it has min-width. I mean the parent div is not fixed size. It will be changing.
But I always want them stay side by side. But the image will always have fixed size. It will never change no matter screen size is changing. But only the text input field will be responsive according to the parent. Here is my code:
This is my HTML
<div>
<div class="comment-form">
<img class="comment-avatar" src="/Images/user_avatar.png" />
<textarea placeholder='Please log in first' class="comment-textarea"></textarea>
</div>
</div>
This is my CSS
.comment-form{
padding:5px;
border:1px solid #CFD8DC;
width:100%;
min-width:280px;
max-width:490px;
}
.comment-avatar{
width:60px;
height:54px;
object-fit:cover;
border:1px solid #CFD8DC;
}
.comment-textarea{
width:86%;
display:inline-block;
border-radius:0px;
height:54px;
}
As you can see in the css, I am making comment-form responsive setting width to 100% with min-width and max-width. The avatar image will have the fixed size. The problem is setting the width of the textarea. I always want image and textarea side by side. I want textarea takes the rest of the form area. So I set its width with percentage. As you can see, now width is 86%. If I set it to 100%, form became something like below.
But with current code, I get like the first image. But when I resize the screen, it becomes something like this.
They are not side by side any more. So my current code is not responsive. What I want to make is I want image always fixed side and want textarea takes the rest or remaining area of form-container no matter what screen size is changed to.
Maybe , this helps... i just added box-sizing and used calc to calculate width of text area
.comment-form{
padding:5px;
border:1px solid #CFD8DC;
width:100%;
min-width:280px;
max-width:490px;
box-sizing: border-box
}
.comment-avatar{
width:60px;
height:54px;
display: inline-block;
border:1px solid #CFD8DC;
box-sizing: border-box;
}
.comment-textarea{
width: calc( 100% - 70px);
display:inline-block;
border-radius:0px;
height:54px;
display: inline-block;
box-sizing: border-box;
}
<div>
<div class="comment-form">
<img class="comment-avatar" src="https://upload.wikimedia.org/wikipedia/en/7/71/SmallTownSouthernMan.jpg" />
<textarea placeholder='Please log in first' class="comment-textarea"></textarea>
</div>
</div>
Working Fiddle
I have deleted the irrelevant css parts. The magic happens with border-box and padding from the outer container.
.comment-form{
position: relative;
width:100%;
padding-left: 62px;
min-width:280px;
max-width:490px;
box-sizing: border-box;
}
.comment-avatar{
position: absolute;
width:60px;
height:54px;
left: 0;
}
.comment-textarea{
width:100%;
height:54px;
}
With the avatar taken out of the normal flow by position: absolute you are able to set the textarea width to 100% and simulate the offset with padding on the outer form element.
Three steps:
Apply display:flex to the parent container
Give the img a fixed width
Give the textarea a flexible width using calc()
See:
.comment-form {
display: flex;
width: 60vw;
height: 84px;
border: 1px solid rgb(191,191,191);
}
.comment-avatar {
width: 60px;
height: 60px;
margin: 12px;
background-color: rgb(127,127,127);
}
.comment-textarea {
width: calc(100% - 96px);
margin: 12px 12px 12px 0;
border: 1px solid rgb(63,63,63);
}
<div>
<div class="comment-form">
<img class="comment-avatar" src="/Images/user_avatar.png" />
<textarea placeholder='Please log in first' class="comment-textarea"></textarea>
</div>
</div>
I guess display: flex should do the job just fine!
Btw. flexbox is a good thing looking into: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
.comment-form{
padding:5px;
border:1px solid #CFD8DC;
width:100%;
min-width:280px;
max-width:490px;
display: flex; /* <-- right here :) */
}
.comment-avatar{
width:60px;
height:54px;
object-fit:cover;
border:1px solid #CFD8DC;
}
.comment-textarea{
width:86%;
display:inline-block;
border-radius:0px;
height:54px;
}
<div>
<div class="comment-form">
<img class="comment-avatar" src="/Images/user_avatar.png" />
<textarea placeholder='Please log in first' class="comment-textarea"></textarea>
</div>
</div>
This work for me, try:
<div>
<div class="comment-form">
<div class="comment-avatar">
<img src="/Images/user_avatar.png" />
</div>
<div class="textareawrap">
<textarea placeholder='Please log in first' class="comment-textarea"></textarea>
</div>
</div>
</div>
and in your css:
.comment-form{
padding:5px;
border:1px solid #CFD8DC;
width:100%;
min-width:280px;
}
.comment-avatar{
width:60px;
height:54px;
object-fit:cover;
border:1px solid #CFD8DC;
position: absolute;
}
.comment-textarea{
width:86%;
display:inline-block;
border-radius:0px;
height:54px;
margin-left: 80px;
}
try also to add to the comment-from display attribute like this:
.comment-form{
padding:5px;
border:1px solid #CFD8DC;
width:100%;
min-width:280px;
max-width:490px;
display:inline-flex
}
but notice that The values "flex" and "inline-flex" requires a prefix to work in Safari. For "flex" use "display: -webkit-flex", for "inline-flex" use "display: -webkit-inline-flex;".
Hi everyone my tutorial has a tree div for now. Header,container and footer. header is fixed. but if you check it in JSFiddle you see container div has a problem lags behind the header div i can not solv the problem. what can i do in my css code?
This is HTML code:
<div class="globalHeader">
<div class="globalheader-in"></div>
</div>
<div class="global_container">
<div class="container">
1 <br>2 <br>3 <br>4 <br>5 <br>
</div>
</div>
And CSS code:
.global_container {
clear:both;
width:981px;
height: auto;
margin-left:auto;
margin-right:auto;
border-right:1px solid #d8dbdf;
overflow:hidden;
background-color:#f8f8f8;
}
.container {
float:left;
width:981px;
height:100px;
background-color:red;
}
.globalHeader {
width:100%;
height:40px;
position:fixed;
background-color:#2a3542;
z-index:99999;
}
.globalheader-in {
width:981px;
height:40px;
margin-left:auto;
margin-right:auto;
border-right:1px solid #fff;
border-left:1px solid #fff;
}
Using a spacer
You can push the content of container down by adding a spacer element as the first child of the container.
.container:before {
content: ' ';
display: block;
height: 40px; /* equal to the height of the header */
}
WORKING DEMO.
Using top padding
You can also use padding-top for the container to achieve that:
.container {
width:981px;
height:100px;
/* other styles... */
padding-top: 40px;
}
WORKING DEMO.
However If you want to keep the height of the container as 100px, you should use box-sizing: border-box to calculate the height of the container including paddings and borders, as follows:
.container {
width:981px;
height:100px;
padding-top: 40px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
WORKING DEMO
I would do it like this:
http://jsfiddle.net/8eSAU/5/
.global_container{
clear:both;
position: relative;
top: 40px;
}
It was not working, because you simply hid the text beneath the fixed element.
Kolay gelsin :)
Why not add:
position:relative;
top:40px;
To .global_container {
Demo Fiddle
This assumes you wish the header to scroll with the content, in which case all you need to do per the demo is offset the top of the content by the height of the header, so it initially displays below it.
A simple padding-top will take care of that.
JSFiddle
.global_container{
clear:both;
width:981px;
height: auto;
margin-left:auto;
margin-right:auto;
border-right:1px solid #d8dbdf;
overflow:hidden;
background-color:#f8f8f8;
padding-top:40px; /* heigt of fixed header */
}
you can add padding-top to the .global_container or body
padding-top should be same as height of header.
Please find the link below for the Fiddle
Add the following to global_container class
position:absolute;
top:47px;
FIND FIDDLE HERE
I have a bodyMain div of 100% width. Inside it is a body div 800px with auto margin(can I use 'body' as id ?). Inside this are two divs bodyLeft and bodyRight 200px and 600px wide respectively. When I add content to inner divs neither bodyMain nor body expands in height . All heights are auto.
Here is the code: http://jsfiddle.net/TqxHq/18/
HTML:
<body>
<div id="bodyMain">
<div id="body">
<div id="bodyLeft"> left text goes here<br />
</div>
<div id="bodyRight">Right text goes here
</div>
</div>
</div>
</body>
CSS:
#bodyMain{
border:1px solid red;
width:100%;
height:auto;
}
#body{
border:1px solid green;
width:804px;
height:auto;
margin:auto;
}
#bodyLeft{
border:1px solid blue;
float:left;
width:200PX;
height:auto;
}
#bodyRight{
border:1px solid orange;
float:right;
width:600PX;
height:auto;
}
You must add
<div style="clear:both;"></div>
at the end of floating div to fix this issue. see
here
Problem happens when a floated element is within a container box and element does not automatically force the container’s height adjust to the floated element. When an element is floated, its parent no longer contains it because the float is removed from the flow. You can use 2 methods to fix it:
clear:both
clearfix
This is a common issue when working with floats. There are a couple of common solutions:
Add a div after the floats with clear: both
Add the two floats into a container with the CSS attribute overflow: auto
Make the parent element a float
Using the :after CSS pseudo element with the CSS: .clearfix:after {content: "."; display: block; height: 0; clear: both; visibility: hidden;}
Adding a set height to the parent element
See this article
The simple solution is to have outer div overflow:hidden (in style attribute).
Thank you
jsFiddle demo
*{
margin:0;
padding:0;
}
#bodyMain{
position:relative;
overflow:hidden; /*added*/
border:1px solid red;
/*removed height:auto;*/
/*removed width:100%;*/
}
#body{
display:table;/*added*/
border:1px solid green;
width:804px;
margin: 0 auto; /*improved*/
}
#bodyLeft{
border:1px solid blue;
float:left;
width:200px;
/*removed height:auto;*/
}
#bodyRight{
border:1px solid orange;
float:right;
width:600px;
/*removed height:auto;*/
}
To avoid confusion with predefined tag names, refrain from using body, html, or head as ID attribute values.
I agree with Muhammed Irfan's idea. I don't agree with his method though. Avoid inline styling except for small snippets. Especially in this case, because it is likely that there will be another case where clear: both is necessary. So, add a div, give it a meaningful class name and apply the additional CSS.
See this fiddle for an example.
I have set up a jfiddle example, and it seems like my height:100%; is not working.
body, html
{
height:100%;
}
#full-wrap {
min-height:100%;
height: auto !important;
height:100%;
margin:0 0 -91px; /* 1 extra px from footer border */
clear:both;
border:thin solid red;
}
.contentCenter {
min-height:100%;
height:100%;
width:300px;
margin: 0 auto;
clear:both;
border:thin solid blue;
}
.footer {
height:90px;width:100%;
border-top:1px #E8E8E8 solid;
clear:both;
}
<div id='full-wrap'>
<div class='contentCenter'>
</div>
</div>
<div class='footer'>
</div>
Can someone help me with the problem? as you can see that the border line (blue) is not going 100%.
height: auto !important;
Remove that line and it works.
The height of your parent #full-wrap div is set to height:auto, you need to specify a height in order for your child div to expand 100%, so set it to 100% or a fixed height. Remember, percentage-based height is relative to its container.