I have a simple textbox inside a div, and I want a hover rule to apply when hovering over the div but not the textbox.
Code:
<div id="div1" style="display:inline-block; border:1px solid #777777; padding:16px; background-color:#eeeeee;">
<input type="text" name="txt1" id="txt1" />
</div>
#div1:hover {
background-color:#ffffff !important;
cursor:pointer;
}
JSFiddle
When hovering over the textbox, the div's hover rule must not apply. Is there a way to do this without JavaScript?
Is this what you are looking for..? Please see the fiddle.
HTML
<div id="container" >
<div id="div1" style="">
</div>
<input type="text" name="txt1" id="txt1" />
</div>
CSS
#div1:hover{
background-color:red !important;
cursor:pointer;
}
#container{
position:absolute;
}
#div1{
position:absolute;
display:block;
border:1px solid #777777;
padding:16px;
width: 180px;
background-color:#eeeeee;
}
#txt1{
top:5px;
left:5px;
background-color:white !important;
position:absolute;
}
http://jsfiddle.net/8NRNQ/4/
Is this what you are looking for?
#div1 { display:inline-block;
border:1px solid #777777;
padding:16px;
background-color:#eeeeee;
}
#div1:hover {
background-color:red;
cursor:pointer;
}
Testing Fiddle: http://jsfiddle.net/8NRNQ/3/
I think you need one simple line of JS for that. The problem is, that you can't change the background of the containing div with hover over the input just by CSS. But in jQuery for example, this is pretty easy
$('#div1 input').hover(function(){$(this).parent.css(SET BACKGROUND AND CURSOR BACK TO THE NO-HOVER-STYLE)});
For anyone wondering, I ended up using JavaScript:
$('#div1').mouseover(function () {
var el = $(this).find('input');
if (!(el.hasClass('inputishover'))) {
$(this).addClass('divhover');
}
}).mouseout(function () {
$(this).removeClass('divhover');
});
$('#div1 input').mouseover(function () {
$(this).addClass('inputishover');
}).mouseout(function () {
$(this).removeClass('inputishover');
});
JSFiddle
Related
This is question not more specific. I want to so common, because most of the web developers have this problem.
We all know the camera view which has border in 4 corners but not in the right/left/bottom/top.
How can we make this effect using css?
html
<div id="div1" />
<div id="div2" />
css
#div1 {
position:absolute;
top:9px;
left:9px;
height:100px;
width:100px;
background-color:white;
border:1px solid black;
}
#div2 {
position:relative;
top:-1px;
left:-1px;
height:102px;
width:102px;
background-color:white;
border-radius: 15px;
}
I achieved it like this.Now I want to know how can achieve this using only one div
You should use parent->child logic
For example :
<div class="parent"><div class="child"></div></div>
EXAMPLE :
Codepen
Hello I really need your help. I have been googling around for how to make a tweet box like twitter's "What's happening" box for user to post new content using bootstrap 3 but so far I cannot find anything close.
Anyone have any idea or keyword that could help? Thank you very much!
You may find a lot of plugins to do the same . But If you want do it your own follow the below steps (this contain only basic functionality)
Define a span or div like below
<div class="container">
<div id="mockTextBox">
What's Happening ?
</div></br>
<textarea id="originalTextBox" class="form-control">
</textarea>
</div>
Hide the textarea at first and show the span/div as textbox.
Then define the events
$(document).ready(function(){
$('#originalTextBox').hide()
$('#mockTextBox').click(function(){
$('#mockTextBox').hide()
$('#originalTextBox').show()
})
})
Apply CSS accordingly and you got what you want.
#mockTextBox
{
width:300px;
height:50px;
border:1px solid;
}
#originalTextBox
{
width:300px;
height:50px;
resize:none;
}
Check this sample http://codepen.io/Midhun052/pen/mVByzK
I have add the bootstrap class to text area in the codepen above for that nice look.
Just updated
A few more CSS and Images
$(document).ready(function() {
$('#originalTextBox').hide()
$('#mockTextBox').click(function() {
$('#mockTextBox').hide()
$('#originalTextBox').show()
})
})
#mockTextBox
{
width:300px;
height:50px;
border:1px solid;
display:inline-block;
margin-top:10px;
border: 1px solid #337ab7;
}
#txt
{
border:1px solid;
display:inline;
height:20px;
}
#originalTextBox
{
width: 310px;
height: 100px;
resize: none;
border: 1px solid #337ab7;
background-color: #337ab7;
margin: 10px;
}
#originalTextBox textarea
{
resize:none;
margin:5px;
width:300px;
}
.class2
{
float: right;
margin-top: 12px;
margin-right: 2px;
}
.imgF1
{
width:20px;
height:20px;
margin:5px
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<div class="container">
<div id="mockTextBox">
<img src="http://lorempixel.com/46/46"/>
<div id="txt">What's Happening ?</div>
<img class="class2" src="http://lorempixel.com/16/16"/>
</div>
<div id="originalTextBox">
<textarea class="form-control">
</textarea>
<img class="imgF1" src="http://lorempixel.com/46/46">Post your photo</img>
</div>
</div>
It's simple jQuery application.
Check this out.
Here's a JSFiddle.
Then all you gotta do is initiate the jQuery.
Such as:
$('textarea').autogrow({onInitialize: true});
Check fiddle for more info.
Cheers!
UPDATED ANSWER:
Use CSS to style your textarea, no need for javascrcipt styling here. Prepare your style in CSS under a specific class and when you need to, you can add your element this class and its propeties. This is much cleaner solution. Use focus and blur events to get textarea element. Here is example.
HTML
<textarea rows="4" cols="50" id="txtArea">
<textarea>
JS
$(document).ready(function() {
$('#txtArea').on("focus", function(event) {
if(!$('#txtArea').hasClass('customTextAreaClass')){
$('#txtArea').addClass('customTextAreaClass');
}
});
$('#txtArea').on("blur", function(event) {
if($('#txtArea').hasClass('customTextAreaClass')){
$('#txtArea').removeClass('customTextAreaClass');
}
});
});
CSS
.customTextAreaClass{
background-color: #fff;
width: 565px;
color: #000;
height: 120px;
padding-left: 1px;
padding-top: 1px;
font-family: "Tahoma", Geneva, sans-serif;
font-size: 10pt;
border: groove 1px #e5eaf1;
position: inherit;
text-decoration: none;
}
My goal is to overlay a transparent button on a div. When a user clicks the button, the underlying div should change color. I tried using z-index, but the button is not clickable. Are there any additional CSS properties I could try that would help me achieve the desired functionality?
CSS:
#container{
height:200px;
width:200px;
position:relative;
z-index:auto;
}
#MyHiddenButton{
float:left;
height:100px;
width:200px;
z-index:2;
background-color:transparent;
position: absolute;
top: 0;
outline: none;
border: none;
}
#myContent{
position:absolute;
float:left;
height:200px;
width:200px;
background-color:lightslategrey;
z-index:1;
}
HTML:
<div id="container">
<div id="myContent" runat="server"></div>
<asp:Button ID="MyHiddenButton" runat="server" OnClick="MyHiddenButton_Click" />
</div>
C# Code:
protected void MyHiddenButton_Click(object sender, EventArgs e)
{
myContent.Style.Add("background-color", "red");
}
If you're not opposed to using JQuery, you can just skip the hidden button and make the div clickable
$('#myContent').click(function(){
$('#myContent').css('background-color','red');
});
JSFiddle
Hi i want to make a customized input text box like this image:
I search many articles but found nothing to do this so please help me
This is not a new answer. But some modification to answer of #alvaro-menéndez to make it more compact and generic.
div {
position:relative;
display:inline-block;
margin:50px;
}
input[type="text"] {
width:300px;
padding:10px;
outline:0;
border:0;
background-color: #eee;
}
.preinput {
position:absolute;
z-index:-1;
display:block;
bottom:-1px;
left:-1px;
border-bottom:1px solid #999;
border-right:1px solid #999;
border-left:1px solid #999;
width:100%;
height:20px;
}
<div>
<span class="preinput"></span>
<input type="text" placeholder="Search" />
</div>
You could use this little and simple jquery to add an element after your input:
$(".input").after("<span></span>");
and then you just have to style it like in this FIDDLE
Edited: updated fiddle to put the element UNDER the input and move it slightly bottom and left so it will be visible even if input has a background-color
You can just use a css background image on your input. Use a placeholder attribute for you "search".
HTML
<input type="search" placeholder="Search" />
CSS
input[type="search"]{
background:url(your_image_path) left bottom no-repeat;
}
Strange issue here which I can't see the problem with! I'm setting the width of the entire element using the class sale_container. But it's width is not changing at all!
See JSFiddle Demo
CSS:
/*Sale styles*/
.add_sales input {
background:none;
border:none;
color:#FFF;
}
.sales_toolbar input {
width:30px;
}
.sale_container {
width:500px;
border:2px solid #FFF;
}
.sale_image {
height:200px;
width:200px;
background-size:cover;
border-radius:10px;
}
.sale_image_container {
border:solid #000 1px;
float:left;
border-radius:10px;
background-color:#353535;
}
.sale_image_container p {
margin:10px;
}
.sales_toolbar {
float:right;
}
HTML:
<form class="add_sales" name="add_sales" action="php/process_sales.php" method="post">
<div class="sale_container">
<div class="sale_image_container">
<div style="background-image:url(data/images/20140121/0/image8.jpg)" class="sale_image"></div>
<p>KR</p>
</div>
<div class="sales_toolbar">
<input type="text" readonly value="KRR" id="50_selected" /> <!-- Selected -->
</div>
</div>
</form>
It seems to be working on the JSFiddle, but when I preview it in Chrome, it looks like this:
It's possible that additional styles are being included from an alternate CSS source. Have you tried using Inspect Element to view the div, and see if it has any unexpected styles being applied? Chrome natively has the feature built-in if you right-click any element.
Glad to help.
Set position to absolute of sale_container to change width.
.sale_container{
width: 300px;
position: absolute;
border: 2px solid #E97676;
}
Use firebug (http://getfirebug.com/) to inspect html element and css attributes.