Currently I have a row containing several divs. I'm trying to prevent the contained divs from wrapping. I also do not want a scrollbar. I've tried overflow hidden and set a width on the row.
EDIT: Constraints dictate that this must be done without tables, javascript, or external libraries.
Is there a way to do this with css without resorting to tables?
JSFiddle: http://jsfiddle.net/ozsumdfb/
HTML:
<div class="row">
<div class="square">
</div>
<div class="square">
</div>
<div class="square">
</div>
<div class="square">
</div>
<div class="square">
</div>
<div class="square">
</div>
</div>
CSS:
.square {
width:100px;
height:100px;
float:left;
margin-left:3px;
background-color: #6C6;
}
.row {
width:500px;
overflow:hidden;
}
insteed of float:left you could try display:inline-block then just add:
.row {white-space:nowrap; }
is this what you are looking for?
fiddle
Try this, I added a wrapper after row had them both with 618px since you had 6 squares padding left 3px (that is (100 + 3)*6 = 618). Hope this helps.
HTML
<div class="row">
<div class="wrapper">
<div class="square">
</div>
<div class="square">
</div>
<div class="square">
</div>
<div class="square">
</div>
<div class="square">
</div>
<div class="square">
</div>
</div>
</div>
CSS
.square {
width:100px;
height:100px;
float:left;
margin-left:3px;
background-color: #6C6;
}
.row {
width:618px;
overflow-x:auto;
overflow-y:hidden;
}
.wrapper {
width: 618px;
}
Related
I'm having some trouble with some basic HTML/CSS and would like to know what I'm doing wrong or if there is a smarter way to do things?
I'm basically wanting to create a simple UI and have created this but it doesn't seem to work quite right. Box4 or 6 seem to be misbehaving when I resize the browser window:
<style type="text/css">
.box1
{
width:100%;
height:25%;
background-color:#eee;
}
.box2
{
width:60%;
height:56%;
background-color:#eee;
float:left;
margin-top:1%;
}
.box3
{
width:39%;
height:40%;
background-color:#eee;
margin-left:61%;
margin-top:1%;
}
.box4
{
width:39%;
height:14%;
background-color:#eee;
margin-left:61%;
margin-top:1%;
}
.box5
{
width:50%;
height:14%;
background-color:#eee;
float:left;
margin-top:1%;
}
.box6
{
width:49%;
height:14%;
background-color:#eee;
margin-left:51%;
margin-top:1%;
}
html,body{
height:100%;
//width:100%;
}
</style>
<div class="box1">
box1
</div>
<div class="box2">
box2
</div>
<div class="box3">
box3
</div>
<div class="box4">
box4
</div>
<div class="box5">
box5
</div>
<div class="box6">
box6
</div>
Edited - added screen grab of what I see when resizing the browser window.
Attached Image
Any help please guys, much appreciated.
Slash.
Try this
html,body{height:100%;}
.box1{width:100%;height:25%;background-color:#eee;}
.box2{width:60%;height:56%;background-color:#eee;}
.box3{width:39%;height:40%;background-color:#eee;}
.box4{width:39%;height:15.5%;background-color:#eee;}
.box5{width:50%;height:14%;background-color:#eee;}
.box6{width:49%;height:14%;background-color:#eee;}
body > div {
float: left;
vertical-align: top;
margin: 3px 0 0 3px;
}
<div class="box1">
box1
</div>
<div class="box2">
box2
</div>
<div class="box3">
box3
</div>
<div class="box4">
box4
</div>
<div class="box5">
box5
</div>
<div class="box6">
box6
</div>
Seems to be working alright here. Perhaps you could be more clear about the problem?
html,body{height:100%;/*width:100%;*/}
.box1{width:100%;height:25%;background-color:#eee;}
.box2{width:60%;height:56%;background-color:#eee;float:left;margin-top:1%;}
.box3{width:39%;height:40%;background-color:#eee;margin-left:61%;margin-top:1%;}
.box4{width:39%;height:14%;background-color:#eee;margin-left:61%;margin-top:1%;}
.box5{width:50%;height:14%;background-color:#eee;float:left;margin-top:1%;}
.box6{width:49%;height:14%;background-color:#eee;margin-left:51%;margin-top:1%;}
<div class="box1">
box1
</div>
<div class="box2">
box2
</div>
<div class="box3">
box3
</div>
<div class="box4">
box4
</div>
<div class="box5">
box5
</div>
<div class="box6">
box6
</div>
Have you checked the total sum of the height %? It seems that box 2 has a height of 56% but box 3 and box 4 have a total of 55% (including the margin of 1%).
I have a table with height 100% and three rows, the first and last ones have a fixed height, and the one in the middle has no specific height so it stretches to the necessary height.
The problem is that if you fill that row with too many items, the table will be too big and it will exceeds the 100%.
<div id="wrapper">
<div id="first" class="row">
<div>
first
</div>
</div>
<div id="second" class="row">
<div>
<div style="height:50px">
cont0
</div>
<div style="height:50px">
cont1
</div>
<div style="height:50px">
cont2
</div>
<div style="height:50px">
cont3
</div>
<div style="height:50px">
cont4
</div>
<div style="height:50px">
cont5
</div>
</div>
</div>
<div id="first" class="row">
<div>
last
</div>
</div>
html, body {height:100%; margin:0; padding:0;}
#wrapper{
width:300px;
height:100%;
display:table;
}
.row
{
display:table-row;
}
#first
{
height:50px;
margin-bottom:5px;
background-color:#F5DEB3;
}
#second{
background-color:#9ACD32;
}
#second > div{
height:100%;
border: 1px solid red;
overflow-y: auto;
}
It's difficult to explain, but this fiddle demonstrates it: http://jsfiddle.net/3EjX8/127/
Resize the table with your mouse in chrome and it will behave nice (scrollbar appears inside the table).
But resize it in firefox and it will have this unexpected behavior.
Maybe I'm wrong and I'm taking good part of a chrome's bug.
I'm just wondering if there is a possibility to make this behave in firefox as it does on chrome.
Thanks.
I made it work on both firefox, chrome.
Don't use display: table for this, not necessary
You had the id "first" two times.
You don't need divs inside divs
Use 'calc' it's a life saver.
http://jsfiddle.net/foreyez/p3rcyofk/
<div id="wrapper">
<div id="first" class="row">
first
</div>
<div id="second" class="row">
<div>
<div style="height:50px">
cont0
</div>
<div style="height:50px">
cont1
</div>
<div style="height:50px">
cont2
</div>
<div style="height:50px">
cont3
</div>
<div style="height:50px">
cont4
</div>
<div style="height:50px">
cont5
</div>
</div>
</div>
<div id="last" class="row">
last
</div>
</div>
html, body {height:100%; margin:0; padding:0;}
#wrapper
{
width:300px;
height:100%;
}
#first,#last
{
height:50px;
background-color:#F5DEB3;
}
#second{
background-color:#9ACD32;
}
#second {
height:calc(100% - 100px);
border: 1px solid red;
overflow-y: auto;
}
I know this question has been asked before. However, I do not seem to find my mistake.
I set up a plnkr. I try to align some text vertically, whereas the the stuff that needs to be aligned is nested into multiple divs.
<div class="news col-md-12" id="detailsView" >
<div class="col-md-8 ">
<div class="row">
<div class="col-md-5 widthInDetails">
<div class="row">
<div class="col-md-8" id="newsDetails">
Hello I am fine and how are your (I am good too)
</div>
</div>
</div>
</div>
</div>
</div>
and in my CSS I have this.
.news{
background-color:black;
line-height:200px;
width:200px;
height:200px;
display:table;
}
#newsDetails{
display:table-cell;
vertical-align:middle;
}
So basically I have I lineheight given from the outer div with class="news". I want the the nested div to be aligned vertically. Is there any way to do this?
http://plnkr.co/edit/cMaCrG1Y8Ky48HwtgNPk?p=preview
If you want to use the display: table property, you should set it in the parent node, like:
<div class="news col-md-12" id="detailsView" >
<div class="col-md-8 ">
<div class="row">
<div class="col-md-5 widthInDetails">
<div id="newsParent" class="row">
<div class="col-md-8" id="newsDetails">
Hello I am fine and how are your (I am good too)
</div>
</div>
</div>
</div>
</div>
</div>
.news{
background-color:black;
width:200px;
height:200px;
}
#newsParent {
display:table;
}
#newsDetails{
height: 200px;
display:table-cell;
vertical-align:middle;
}
Give it a try and let me know if it helps!
You can make wrapper display: table and child div display: table-cell; vertical-align: middle;. find the below jsfiddle demo.
HTML
<div class="news col-md-12" id="detailsView" >
<div class="col-md-8 ">
<div class="row">
<div class="col-md-5 widthInDetails">
<div class="row newsDetailswrap">
<div class="col-md-8" id="newsDetails">
Hello I am fine and how are you?</div>
</div>
</div>
</div>
</div>
</div>
CSS
.newsDetailswrap{
background: red;
height: 100px;
display:table;
}
#newsDetails{
display: table-cell;
vertical-align: middle;
}
http://jsfiddle.net/hhbnywq1/
I´m trying to do responsive tiles grid with static tile width.
I don´t speak English well, so I tried to draw my problem.
Image is here
I need have tiles grid in the middle, but don´t centring single tile.
I hope you understand what I need, and thank you for any reply.
I guess this is what you want. Check this Fiddle
HTML:
<div class="wrapper">
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
<div class="box">
</div>
</div>
CSS:
.wrapper{
width:80%;
border:solid 1px #000;
margin-left:auto;
margin-right:auto;
overflow:hidden;
}
.box{
margin:5px;
height:150px;
width:100px;
float:left;
border:solid 1px #000;
}
I am trying to make the Images in "fullwidthbanner" as fully responsive. May be the problem is that it has two images which I want it to transform with size.
This is my HTML
<div class="main-container col1-layout">
<div class="main row-second clearfix">
<div class="col-main">
<div class="std"><div class="sub-container"><div class="fullwidthbanner-container">
<div class="fullwidthbanner>
<div class="item"><img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="Random Collection"></div>
<div class="item"><img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="Random Collection"></div>
</div>
</div>
</div>
</div>
</div>
CSS
.sub-container {overflow:auto;}
.main-container {background:#fafafa; }
.main { margin:0 auto; position: relative; z-index:1; }
.sub-container div.item{ background-color:red; float:left;}
.sub-container div.item:hover{ background-color:green;}
.sub-container div.item img{ width:100% !important; display:block;}
For some reason, it does everything I want it to, but both the Images are fully extending in terms of width. The width always remain the same and when the window size increases, it just shows an empty space in front of both images.
Assuming this is the html:
<div class="main-container col1-layout">
<div class="main row-second clearfix">
<div class="col-main">
<div class="std">
<div class="sub-container">
<div class="fullwidthbanner-container">
<div class="fullwidthbanner">
<div class="item">
<img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="Eid Collection" />
</div>
<div class="item">
<img src="http://127.0.0.1/www/media/wysiwyg/sub-head1.jpg" alt="Eid Collection" />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Does this css do what you want?
.sub-container div.item {
background-color: red;
float: left;
width: 100%;
}
Although I would suggest using max-width, instead of width -- this will make it adapt to smaller screens, and on larger screens it won't get blurry.