I'm trying to float divs for a responsive website and it's not working properly. I need them to be in the order below because when the screen gets smaller, they need to stack with 1 on top, then 2, the 3. The third div is not going nicely underneath the first div. Any help is appreciated!
<div class="1">info</div>
<div class="2">info</div>
<div class="3">info</div>
.1 {
width:23%;
float:right;
}
.2 {
width:76%;
float:left;
}
.3 {
float:right;
width:23%;
}
Again, just to be clear, I need "3" to be underneath "1" but it's going underneath "2". Thanks!
Css Class shouldn't begin with number.
Demo
.one {
width:23%;
float:right;
}
.two {
width:76%;
float:left;
}
.three {
float:right;
width:23%;
}
I guess this is what you want Demo
* {
box-sizing: border-box;
}
.one {
width:23%;
float:left;
background-color: #333;
}
.two {
width:76%;
float:left;
background-color: #666;
}
.three {
float:left;
width:23%;
background-color: #ddd;
}
I guess using inline block will work. Even if you resize the window without the percentage width.
.one {
width:23%;
display: inline-block;
color: yellow;
}
.two {
width:76%;
display: inline-block;
color: orange;
}
.three {
display: inline-block;
color: red;
width:23%;
}
Demo
your code was right, except that css-classes must not start or only contain a number. DIV.two does not nedd to float:
<div class="one">info 1</div>
<div class="two">info 2</div>
<div class="three">info 3</div>
And the css:
.one {
width:23%;
float:right;
background-color: yellow;
}
.two {
width:76%;
background-color: grey;
}
.three {
float:right;
width:23%;
background-color: red;
}
See the fiddle.
Related
I have a container around two inline block elements. However the container collapses (the horizontal dashed line). How do I stop it from collapsing so that I can apply a background colour to the container. The structure is important and I want to avoid using flex-box. It is also important that the two coloured squares are right aligned and next to each other.
The aim is to create an absolutley positioned block element over a canvas element. With a descriptive name on the left and two buttons on the right. I have to work with what is there so a solution that involves as little change as possible would be great.
.header3 {
width: 300px;
background-color: lightgray;
border: 1px dashed grey;
position:relative;
}
.title3{
position:absolute;
top:0px;
left:0px;
display:inline-block;
vertical-align:center;
background-color:#bada55;
}
.list {
list-style:none;
margin:0px;
padding:0px;
border:1px dashed green;
position:absolute;
display:inline-block;
top:0px;
right:0px;
}
.item {
width: 50px;
height: 50px;
display: inline-block;
text-align: center;
}
.item-1 {
background-color: orangered;
}
.item-2 {
background-color: skyblue;
}
<body>
<br>
<div class="header3">
<div class="title3">bollard name</div>
<ul class="list">
<li class="item item-1"></li>
<li class="item item-2"></li>
</ul>
</div>
</body>
Codepen here
This is happening because you absolutely positioned your .title3 and .list elements which remove them from the normal flow.
If you want to achieve this layout use float:right on your ul and insert a clear in your div (in the code below I achieved this using the::after:pseudo element of yourdiv`)
* {
font-family: "Helvetica";
}
/* list */
.header3 {
width: 300px;
background-color: lightgray;
border: 1px dashed grey;
position:relative;
}
.header3::after {
content: '';
display: table;
clear: both;
}
.title3{
display:inline-block;
vertical-align:center;
background-color:#bada55;
}
.list {
list-style:none;
margin:0px;
padding:0px;
border:1px dashed green;
float: right;
}
.item {
width: 50px;
height: 50px;
display: inline-block;
text-align: center;
}
.item-1 {
background-color: orangered;
}
.item-2 {
background-color: skyblue;
}
<div class="header3">
<div class="title3">bollard name</div>
<ul class="list">
<li class="item item-1"></li>
<li class="item item-2"></li>
</ul>
</div>
How can i align the two different sizes lines one by one horizontally with no space between them?
Like
See here i want no space between the lines means the APP downloads exactly after 5M
I tried with the following:
.text
{
color:white;
}
.big
{
font-size:5em;
}
.small
{
font-size:2em;
display:inline-block;
}
<div class="text">
<span class="big">52M</span>
<span class="small">App Downloads</span>
</div>
Maybe you could use 'flex-box' and change the 'line-height' value of the span elements. It's a possible solution.
Example
.text
{
width:20%;
height:20%;
padding:5%;
background:red;
color:white;
display:flex;
flex-direction:column;
}
.big
{
font-size:5em;
line-height:0.8em;
margin:auto;
}
.small
{
font-size:2em;
margin:auto;
}
Try white-space: nowrap
<style>
.text
{
color:white;
white-space: nowrap;
}
.big
{
font-size:5em;
}
.small
{
font-size:2em;
display:inline-block;
}
</style>
With text-align: center.
Try this: http://codepen.io/r3npi2/pen/vKmgZG
.text
{
color:white;
background-color:red;
display:inline-block;
text-align:center;
}
.big
{
font-size:5em;
display:block;
}
.small
{
font-size:2em;
display:block;
}
I'm assuming you want them to be underneath each other... the question isn't very clear regarding that.
All you have to do here is change the span elements to block elements, either by CSS or - the reason I'd prefer for simplicity - changing them to divs. Then, give the surrounding div a text-align:center (and a background-color to see the result), and you're done!
.text {
background-color: #d00;
color: white;
text-align: center;
}
.big {
font-size:5em;
}
.small {
font-size:2em;
}
<div class="text">
<div class="big">52M</div>
<div class="small">App Downloads</div>
</div>
You can do it using display:block and float left:
.text {
color:white;
background-color: red;
float: left;
width: 300px;
text-align:center;
}
span {
display: block;
width:100%;
float:left;
margin: 0px;
}
Try adding a break in between them to space them out like so.
<style>
.text
{
color:white;
}
.big
{
font-size:5em;
}
.small
{
font-size:2em;
display:inline-block;
}
</style>
<div class="text">
<span class="big">52M</span>
<br>
<br>
<span class="small">App Downloads</span>
</div>
I am using this CSS for a really simple image gallery:
.product_container {
width:100%;
display:block;
}
.product_images {
width:45%;
display:inline-block;
border:1px solid black;
}
.product_images .large {
}
.product_images .small img {
display:inline;
float:left;
margin:5px;
width:151px;
}
i want to have a large image and then rows of 3 under that image, i created an example in a fiddle here
https://jsfiddle.net/jdd9hzqo/
when the page is resized, the small images are moving but i want them to stay in rows of 3 and resize themselves but keeping to the same size as the .product_container
Fiddle:https://jsfiddle.net/jdd9hzqo/2/
Changes to be made:
.product_images {
width:100%;
display:inline-block;
border:1px solid black;
}
.product_images .large img {
width:100%;
}
.product_images .small img {
display: inline;
float: left;
width: 33%;
box-sizing: border-box;
}
https://jsfiddle.net/jdd9hzqo/1/
Remove float:left; in .product_images .small img {
And add:
.small {
white-space: nowrap;
}
For the resize add something like width: 30%; in .product_images .small img {
I have 3 divs that I would like to display inline.
2 divs on the left and 1 div on the right most on the screen.
When screen shrinks or the name size increases I want all elements to still stay inline and name to wrap on the new line if it is hitting the right div. Right div has to always be on the right. I would like to avoid using set width/height except for the images.
I cant seem to be able to this correctly.
Also Right div seems to be splitting and not staying inline no matter what I do or even disappearing.
So expected result is: div 1&2 always left, div 3 always right and all three always inline when screen width changes
Here is my html:
<div class="main">
<div class="one">
<img src="http://upload.wikimedia.org/wikipedia/commons/7/74/GeoGebra_icon_geogebra.png" alt="" class="image">
</div>
<div class="two">
<span class="name">Lorem ipsum dolor sit amet, consectetur adipisicing elit</span>
<span class="title">Title</span>
</div>
<div class="three">
<div class="this">
<img src="http://upload.wikimedia.org/wikipedia/commons/7/74/GeoGebra_icon_geogebra.png" alt="" class="this-image">
<span class="this-num">12</span>
</div>
<div class="that">
<img src="http://upload.wikimedia.org/wikipedia/commons/7/74/GeoGebra_icon_geogebra.png" alt="" class="that-image">
<span class="that-num">21</span>
</div>
</div>
</div>
this is my css:
.main {
display: -webkit-inline-box;
}
.this-image, .that-image {
width: 16px;
}
.title, .name {
display: block;
}
.three {
float:right;
position: fixed;
}
.one {
background-color: red;
}
.two {
background-color: green;
margin-left: 15px;
}
.three {
background-color: blue;
}
here is my jsfiddle:
http://jsfiddle.net/r679f840/1/
Thanks
.one with float left, .with margin-right (no float) .three with absolute and no float
.main {
position: relative;
}
.one {
background-color: red;
float:left;
margin-right:15px;
margin-bottom:15px;
}
.two {
background-color: green;
margin-right: 46px;
}
.three {
background-color: blue;
position: absolute;
right: 10px;
top: 0;
}
see fiddle here
try this:
.main {
display:table;
width:100%;
}
.this-image, .that-image {
width: 16px;
}
.title, .name {
display: block;
}
.one, .two, .three {
display:table-cell;
width:30%;
margin:0 1%;
}
.one {
background-color: red;
}
.two {
background-color: green;
margin-left: 15px;
}
.three {
background-color: blue;
}
see fiddle here
Similar answer than Fabio with display : table; as a basis.
Difference is to leave a gap in between second and third cell untill there is enough content to fill it.
DEMO
.main {
display: table;
width:100%;
overflow:hidden;
}
.this-image, .that-image {
width: 16px;
}
.title, .name {
display: block;
}
.one, .two, .three {
display:table-cell;
vertical-align:middle;
}
.one {
background-color: red;
}
.two {
background-color: green;
display:inline-table;
}
.two:after {/* here is the faux-columns revisited to draw your background if needed */
content:'';
display:block;
height:1000px;
margin-bottom:-1000px;
background:green;
}
.three {
background-color: blue;
}
Found solution to my own question myself, but #Barak your answer was almost perfect so I'll keep your answer as the correct.
Here is my jsfiddle: http://jsfiddle.net/r679f840/8/
And here is my CSS:
.main {
display: flex;
}
.this-image, .that-image {
width: 16px;
}
.title, .name {
display: block;
}
.one {
background-color: red;
float:left;
}
.two {
background-color: green;
margin-left: 30px;
padding-right: 60px;
float: left;
width: 100%;
}
.three {
background-color: blue;
float:left;
width: 50px;
}
Why are my Columns not aligning correctly? There seems to be a gap above. Is there away that I can make them automatically set a width of the wrapper its in 892px;
http://jsfiddle.net/pJefg/
HTML:
<div class="leftColParts">
Text Left
</div>
<div class="rightColParts">
Text Right
</div>
CSS:
.leftColParts{
width:215px;
background-color:red;
}
.rightColParts{
float: right;
display: inline-block;
width:440px;
clear:both;
background-color: green;
}
Is this what you need?
http://jsfiddle.net/pJefg/7/
HTML:
<div class="wrapper">
<div class="leftColParts">Text Left</div><!--
--><div class="rightColParts">Text Right</div>
<div>
--
CSS:
.wrapper {
width: 892px;
}
.wrapper:after {
clear:both;
content: ".";
height: 0;
visibility:hidden;
}
.leftColParts {
float:left;
width:215px;
background-color:red;
}
.rightColParts {
float:right;
width:440px;
background-color: green;
}
.leftColParts{
width:215px;
background-color:red;
float: left;
}
.rightColParts{
float: left;
width:440px;
background-color: green;
}
Try this.
Alternatively this:
.leftColParts{
width:215px;
background-color:red;
display: inline-block;
}
.rightColParts{
display: inline-block;
width:440px;
clear:both;
background-color: green;
}
I have edited the fiddle with what I think it is that you want.
What I've done:
Floated both divs left
Added a div with a clearfix (clear: both;)
You can check it here: http://jsfiddle.net/pJefg/2/