change the height of background-color - css

I'm trying to change the height of background-color in class.
#myclass{
background-color: #FFF;
padding: 25px;
border: 1px solid #e1e1e1;
height:auto;
}
<div id="myclass">
<div class="col-md-4">image</div>
<div class="col-md-4">text</div>
<div class="col-md-4">button</div>
</div>
In CSS height:420px working but i don't want something like this

Sounds like you're having an issue with floating elements. As the .col-md-* elements are floated, your #myclass element has no height (thus no background will display). Bootstrap's .col-md-* elements are supposed to be wrapped in an element with a class of "row", and I believe this will solve your problems:
<div id="myclass" class="row">
<div class="col-md-4">...</div>
<div class="col-md-4">...</div>
<div class="col-md-4">...</div>
</div>
If that isn't an option, you'll need to add an element to clear the floats on those .col-md-4 elements:
<div id="myclass" class="row">
<div class="col-md-4">...</div>
...
<br style="clear: both">
</div>

Solution 1) If it is a solid background-color - you can add the background as a image
#myclass {
background-image:url('pathtoimage/background-image.png');
background-size: 100% 450px;
background-position: left top;
}
Solution 2)
Add a fake-background image/color by adding a div inside #myclass.
<div id="myclass">
<div class="fake-bg"></div>
<div class="col-md-4">image</div>
<div class="col-md-4">text</div>
<div class="col-md-4">button</div>
</div>
Add this to your css:
#myclass {
position:relative;
}
.fake-bg {
position:absolute;
left:0;
top:0;
width:100%;
height:450px;
z-index:-1;
}

.clearfix:before, .clearfix:after {
content: "";
display: table;
line-height: 0;
}
.clearfix:after {
clear: both;
}
please use this css and just put .clearfix with .ror class.
it would work defiantly

Related

div to take remaining space whose neighbor has transform translate

I have two divs as shown in the image below:
In above image:
grey rectangle is the container div.
white rectangle is a div with transform: translateX(somevalue),
this rectangle is draggable. So, when dragging its translateX and translateY will be changed in the code.
blue rectangle is a div which should take up all the available width. Its height is fixed.
I don't have any code as I am trying to do this in react using react-draggable which uses translateX and translateY to drag an element.
I want a pure css solution because I don't want to re-render the component just for increasing the width of the div.
Note:
The blue rectangle is considered as div for the demo purpose only to make the example simpler to understand. In actual project the blue box will be a line and on that line I will put the distance between left edge of the container and left edge of the moving object. Something like a ruler.
Update:
Here is my code:
<div className="cover-print-area-settings-container">
<div style={{ background: 'black', height: 10, width: 'auto' }} />
<Draggable
bounds={{
left: 0,
top: 0,
right: 300,
bottom: 150
}}
>
<div id="cover-print-area-draggable-content" className="cover-print-area-settings-content">
<div className="contact-name">Contact Name</div>
<div className="side-by-side-start-center">
<PhoneIcon className="contact-detail-icon" />
<span>Mobile No</span>
</div>
<div className="side-by-side-start-center email-wrapper">
<EmailIcon className="contact-detail-icon" />
<span>Email</span>
</div>
<div className="side-by-side-start-center">
<LocationIcon className="contact-detail-icon contact-location-icon" />
<div className="contact-address-wrapper">
<p className="contact-address"> Address Line 1 </p>
<span className="contact-address-details"> Address Line 2 </span>
</div>
</div>
</div>
</Draggable>
</div>
Draggable element in the code is imported from react-draggable. Here is the documentation of react-draggable: https://github.com/mzabriskie/react-draggable
The css related to the above html looks like:
.cover-print-area-settings-container
height: 300px;
width: 600px;
overflow: auto
// height: 100%
background-color: #fff8dc
.cover-print-area-settings-content
border: 1px solid black
display: inline-block
vertical-align: top
.contact-name
font-size: 36px
text-align: left
.contact-detail-icon
margin-right: 7px
.contact-location-icon
padding-top: 12px
align-self: flex-start
.email-wrapper
margin-top: 5px;
margin-bottom: -8px;
.contact-address-wrapper
display: flex
flex-direction: column
justify-content: flex-start
.contact-address
text-align: left
align-self: flex-start
.contact-address-details
margin-top: -12px
text-align: left
align-self: flex-start
I would consider CSS variable in this case where you simply adjust the variable that will be used for the translate and the width:
.container {
padding:20px 0;
height:100px;
background:grey;
}
.blue {
height:100%;
background:blue;
display:inline-block;
width:var(--c);
margin-right:calc(var(--c) * -1);
}
.white {
height:100%;
width:100px;
background:white;
display:inline-block;
transform:translateX(var(--c));
}
<div class="container" style="--c:50px">
<div class="blue"></div><div class="white"></div>
</div>
<div class="container" style="--c:100px">
<div class="blue"></div><div class="white"></div>
</div>
<div class="container" style="--c:200px">
<div class="blue"></div><div class="white"></div>
</div>
Another idea would be to consider the blue part as a pseudo element of the white box and it will be easier to consider X/Y translation:
.container {
padding:20px 0;
height:100px;
background:grey;
overflow:hidden;
}
.white {
height:100%;
width:100px;
background:white;
display:inline-block;
transform:translateX(var(--c));
position:relative;
}
.white:before {
content:"";
position:absolute;
top:0;
left:-100vw;
right:100%;
bottom:0;
background:blue;
}
<div class="container" style="--c:50px">
<div class="blue"></div><div class="white"></div>
</div>
<div class="container" style="--c:100px">
<div class="blue"></div><div class="white"></div>
</div>
<div class="container" style="--c:200px">
<div class="blue"></div><div class="white"></div>
</div>

floating a list of divs of variable height in 3 column format

I have a list of product divs containing two more divs each displayed vertically within - top one containing an image and bottom one text. The text is variable in size so the outer divs size also is variable. These outer divs float left and go 3 to a row until a div with long text happens then the next row starts immediately after that column, leaving a gap.
So if I have a row where the 2nd div has 3 lines of text to the other two's 1, the 4th div will start not in the first position on the next line but in the 3rd.
Here is an image demonstrating what I see now vs a second what I would like to do:
And what I'm aiming to do
Do not use float. Take a look at this fiddle:
JSFiddle Demo
CSS:
.block {
width: 33.33%;
display: inline-block;
vertical-align: top;
margin-right: -3px;
}
.inner {
min-height: 100px;
margin-bottom: 10px;
background: #000;
}
You can create a row for the div elements, this will produce the layout you need! I have also provided a CSS only solution where the class clearfix will do the same thing as row class!
CSS3:
.row{
display:flex;
}
.box{
background-color:grey;
float:left;
margin:3px;
width:100px;
height:100px;
}
<div class="row">
<div class="box">1</div>
<div class="box" style="height:200px;">2</div>
<div class="box">3</div>
</div>
<div class="row">
<div class="box">4</div>
<div class="box">5</div>
<div class="box">6</div>
</div>
CSS:
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}
* html .clearfix { zoom: 1; } /* IE6 */
*:first-child+html .clearfix { zoom: 1; } /* IE7 */
.box{
background-color:grey;
float:left;
margin:3px;
width:100px;
height:100px;
}
<div class="clearfix">
<div class="box">1</div>
<div class="box" style="height:200px;">2</div>
<div class="box">3</div>
</div>
<div class="clearfix">
<div class="box">4</div>
<div class="box">5</div>
<div class="box">6</div>
</div>
HTML
<div class="flex-container">
<div class="box">img</div>
<div class="box">img</div>
<div class="box">img</div>
</div>
<div class="flex-container">
<div class="box">txt</div>
<div class="box">txt</div>
<div class="box">txt</div>
</div>
CSS
.flex-container{
background:red;
display:flex;
width:100%;
height:auto;
margin:0% auto;
padding:1% 0;
}
.box{
min-width:100px;
height:auto;
padding:1%;
margin:0 1%;
flex-grow:1;
background:green;
}
Also, Please chech whether you have cleared all floats
Please see Using CSS Flexible Boxes MDNweb docs

Placing other elements below the two div elements which were placed side-by-side

the code i have tried is
CSS Code
#tools
{
float:left;
}
#sketch
{
border: 10px solid grey;
float:left;
width: 700px;
height: 500px;
position: relative;
}
HTML code:
<div id="tools">
<p>These are my tools</p>
</div>
<div id="sketch">
<p>This is my sketch</p>
</div>
<button type="button">Click</button>
I am placing the two divs side-by-side
the button is geting displyed side to the divs
but I want the button below the div
Fiddle here
Clear the float:
button { clear: both; }
Add wrapper with a clearfix:
<div class="wrapper cf">
<div id="tools">
<p>These are my tools</p>
</div>
<div id="sketch">
<p>This is my sketch</p>
</div>
</div>
<button type="button" >Click</button>
http://jsfiddle.net/brutusmaximus/5KmK6/3/
Try to use "clear: left;" for the button to cancel the "float: left" of the previous div element.
See http://www.w3schools.com/cssref/pr_class_clear.asp for more details.
You can use any of the two :
1) button {
clear : both;
}
2) Add a class clearfix to the Div - "sketch" that adds a pseudo element to the DOM after it to clear the float added.
<div id="sketch" class="clearfix">
<p>This is my sketch</p>
</div>
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: " ";
clear: both;
height: 0;
}

Hover on image not working properly

<div align="center">
<div class="se" style="width:60px;height:60px;"><img src="http://images.smh.com.au/2013/07/10/4558947/english_flag-60x60.jpg"/></div>
<div class="uk" style="width:60px;height:60px;"><img src="http://images.smh.com.au/2013/07/10/4558947/english_flag-60x60.jpg"/></div>
<div class="de" style="width:60px;height:60px;"><img src="http://images.smh.com.au/2013/07/10/4558947/english_flag-60x60.jpg"/></div></div>
<div> i dont want this menu div to jump up and down when hover</div>
css file:
.se {margin-top:-30px;}
.se:hover {margin-top:-15px;}
.uk {margin-top:-60px; margin-left:-150px;}
.uk:hover {margin-top:-45px;}
.de{margin-top:-60px; margin-left:150px;}
.de:hover {margin-top:-45px;}
I just want the flags to slide down when hover. As you see in my fiddle, it's acting strange depending on with flag i hover first.
This could probably be solved in an easier way? http://jsfiddle.net/XScjm/1/
I think you are in the wrong way to acomplish what you want, first you can't offset the image with margin because that affects all arround the element. And the way you are trying to position each <div> with margin is unrecommended.
Try to do it this way:
.center {
text-align:center;
}
.se, .uk, .de {
position:relative;
display:inline-block;
cursor:pointer;
}
.se:hover, .uk:hover, .de:hover {
top:15px;
}
Check this Demo
Have a look at this one :-
DEMO
<div align="center" class="one"></div>
.one{ height: 60px; }
try this:
.se, .uk, .de {
float: left;
margin-right: 5px;
margin-top: -40px;
}
.se:hover img, .uk:hover img, .de:hover img {
margin-top: 20px;
}
This will work. JSFiddle.
HTML
<div id="center" align="center">
<div class="flag" style="width:60px;height:60px;">
<img src="http://images.smh.com.au/2013/07/10/4558947/english_flag-60x60.jpg"/>
</div>
<div class="flag" style="width:60px;height:60px;">
<img src="http://images.smh.com.au/2013/07/10/4558947/english_flag-60x60.jpg"/>
</div>
<div class="flag" style="width:60px;height:60px;">
<img src="http://images.smh.com.au/2013/07/10/4558947/english_flag-60x60.jpg"/>
</div>
</div>
<div> i dont want this menu div to jump up and down when hover</div>
CSS
.flag {margin-top:-30px; position:relative; display:inline-block;}
.flag:hover { top:15px; }
#center { height: 50px; }

align 4 divs in parallel where one of the divs is empty

I'm a newbie with html so please be patient.
I'm trying to align 4 divs in parallel where the first,third and fourth div are static,the second div is empty and i need it to occupy the remain place e.g "width:auto".
I don't want to use table to solve the problem.
Is there a way to solve it using divs?
HTML:
<div class="container">
<div class="content" >
first
</div>
<div class="empty">
</div>
<div class="content">
third
</div>
<div class="content">
fourth
</div>
</div>
CSS:
.container{
strong textwidth:1020px;
height:40px;
}
.content{
position:relative;
background-color:#2cc2e7;
height:40px;
width:142px;
float:right;
margin-right:5px;
}
.empty{
background-color:#f1d486;
height:40px;
width:auto;
margin-right:5px;
}
You will need to change the order of the elements:
<div class="container">
<div class="first content">first</div>
<div class="content">third</div>
<div class="content">fourth</div>
<div class="empty"></div>
</div>
And then just float the first one to the left, other two to the right, and the .empty one, don't float it but set an overflow to auto —or hidden.
.content {
float: right;
width: 142px;
}
.first {
float: left;
}
.empty {
overflow: auto;
}
http://jsfiddle.net/GTbnz/
If you are prepared to add below the empty div then you could use the following:
<div class="empty">
</div>
with a style sheet of:
.container {
width:1020px;
height:40px;
display:table;
width:100%;
}
.container div {
height:40px;
display:table-cell;
}
.content {
background-color:#2cc2e7;
width:142px;
max-width:142px;
}
.empty {
background-color:#f1d486;
}
This was whichever of the 4 div's has a class 'empty' will auto-expand to fill the available space and the other div sizes will all be 142 px.

Resources