Limiting utilized area within textbox using CSS - css

I have a small image placed within the right side of my text box and I am trying to prevent my text from running behind that image. However, I do not want to limit the amount of characters by doing this. Any suggestions?
<div id="searchContainer">
<!--Search Bar-->
<input id="searchBar" type="text" placeholder="Type here to search" onfocus="placeholder = ' '"/>
<!--Microphone-->
<img id="mic" src="*Super long URL*"/>
</div>
/*Search Bar*/
#searchBar {
opacity: 0.6;
position: relative;
display: block;
height: 24px;
font-size: 16px;
font-family: Arial, sans-serif;
width: 550px;
}

What people typically do is put the text input, and image inside of a container. They remove the border of the input so it appears to be a white input box. They stylize the container with a border and such to make it look like THAT is the input. Then they put the (in your case) microphone image floated to the right, and add a margin right to the input. so the text does not hide behind the image.
Here is the basic idea: http://codepen.io/anon/pen/pJdMJB
HTML:
<div id="searchContainer">
<img src="http://i.imgur.com/w5j4E5O.png"/>
<input id="searchBar" type="text"/>
</div>
CSS:
#searchBar {
opacity: 0.6;
position: relative;
display: block;
height: 24px;
font-size: 16px;
font-family: Arial, sans-serif;
width: 500px;
border:none;
}
#searchContainer{
border:1px solid #ddd;
width:520px;
}
img{
width:20px;
height:20px;
float:right;
}

Related

Is it possible to place absolut positioned elements automatically among themselves?

Is it still possible to automatically place for examples div elements among themselves if they are positioned absolut?
In the code snippet there are three divelements which are placed among themselves. Is it somehow possible to delte the css style instructions for #elem2 and #elem3 and construct a general rule that the div elements should placed among themselves with an margin of e.g. 10px? So that I can easily add new div elements (variable height) with the css class column1 and don't have to worry about the margin-top respectively margin-bottom.
#containerGraph {
position: relative;
width: 700px;
height: 400px;
border: 1px solid black;
overflow:scroll;
}
/* set the position attribute for all div elements inside the mainContainer*/
#containerGraph > div {
position: absolute;
}
.paramElement {
width: 200px;
max-height: 90px;
border-radius: 18px;
text-align: center;
background-color: #e6e6e6;
color: #4d4d4d;
font-family: Verdana, Helvetica, sans-serif;
padding-bottom:5px;
font-size: small;
}
.column1{
margin-left:10px;
}
#elem2{
margin-top : 40px;
}
#elem3{
margin-top : 117px;
}
<div id="containerGraph" class="relative">
<div class="paramElement column1" id="elem1">
first
</div>
<div class="paramElement column1" id="elem2">
second with very large text text text text text text text text text text text text text
</div>
<div class="paramElement column1" id="elem3">
third
</div>
</div>
This is a strange need, and I don't see how to solve it the way the problem is posed.
However it seems that, if an absolute position is needed, it should be relevant (and so useful) only against the containerGraph, but clearly not for each one among others.
So a solution might be to:
insert a child <div> of your containerGraph, with an absolute position
it will contain the (formerly absolute) other <div>s
You can see it working in this snippet:
$('body').click(function() {
$('#elem2').remove();
$('#sub-container').append('<div class="paramElement column1" id="elem4">fourth</div>');
});
#containerGraph {
position: relative;
width: 700px;
height: 400px;
border: 1px solid black;
overflow:scroll;
}
/* set the position attribute for all div elements inside the mainContainer*/
#containerGraph > div {
position: absolute;
}
.paramElement {
width: 200px;
max-height: 90px;
border-radius: 18px;
text-align: center;
background-color: #e6e6e6;
color: #4d4d4d;
font-family: Verdana, Helvetica, sans-serif;
padding-bottom:5px;
font-size: small;
}
.column1{
margin-left:10px;
margin-bottom: 10px;
}
/*
#elem2{
margin-top : 40px;
}
#elem3{
margin-top : 117px;
}
*/
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Click anywhere to change
<hr />
<div id="containerGraph" class="relative">
<div id="sub-container">
<div class="paramElement column1" id="elem1">
first
</div>
<div class="paramElement column1" id="elem2">
second with very large text text text text text text text text text text text text text
</div>
<div class="paramElement column1" id="elem3">
third
</div>
</div>
</div>

Place image next to text in a DIV

Trying to put an image next to a paragraph but it does not seem to work.
This is what I have:
<div class="dhn-info-div">
<p>DEVONSHIRE HOUSE NETWORK IS A <span class="dhn-purple">PEOPLE-FOCUSED</span> MEMBERSHIP CLUB FOR DIRECTOR-LEVEL <span class="dhn-purple">PROFESSIONALS</span> IN LEADERSHIP ROLES WHO HAVE AN INSTINCTIVE FOCUS ON <span class="dhn-purple">THE HUMAN SIDE OF ENTERPRISE..</span></p>
<img src="wp-content/themes/expound/images/dhn-directors.png" alt="Devonshire House Network Directors">
<div style="clear:both"></div>
</div>
and CSS:
.dhn-info-div {
margin-top: 20px;
background-color: #a20e45;
width: 95%;
display: inline-block;
}
.dhn-info-div p {
padding: 20px 40px 20px 40px;
color: white;
font-size: 18px;
line-height: 35px;
word-spacing: 5px;
}
.dhn-info-div img {
float: right;
}
Image has to be on the right of the text. The div shouldn't be 100% in size. Cheers
This is how I want it to look:
http://i.stack.imgur.com/bPxbB.png
Depending on if you want to wrap the text around the image or have 2 columns, here’s both solutions:
If you want to wrap the text around the image it needs to be within the p tag. See example (I have also added 10px padding around the image).
If you want 2 columns you need to define the width of both so they fit in. I have also added float: left; to both and some padding to the image to make it look slightly better. See example
EXAMPLE
You needed to add some width to some elements such as the text
also you had no width or height on your image.
I also added top:40px; to your image to bring it down to the level of the text
Can you put the <img> in your <p> at top? that would fix it:
<div class="dhn-info-div">
<p>
<img src="wp-content/themes/expound/images/dhn-directors.png" alt="Devonshire House Network Directors" />
DEVONSHIRE HOUSE NETWORK IS A <span class="dhn-purple">PEOPLE-FOCUSED</span> MEMBERSHIP CLUB FOR DIRECTOR-LEVEL <span class="dhn-purple">PROFESSIONALS</span> IN LEADERSHIP ROLES WHO HAVE AN INSTINCTIVE FOCUS ON <span class="dhn-purple">THE HUMAN SIDE OF ENTERPRISE..</span>
</p>
<div style="clear:both"></div>
</div>
Edit: is now responsive!
i made this fiddle, check it http://jsfiddle.net/fYh7u/
you can wrap the text in a div, and the image in another div, inside the main div "dnh-info-div", in my example i miss the "div", at end of class, because is obvious.
HTML:
<div class="dhn-info">
<div class="dhn-text">
<p>devonshire house network is a <span class="text-purple">people-focused</span> membership club for director-level <span class="text-purple">professionals</span> in leadership roles who have an <span class="text-purple">instinctive focus</span> on <span class="text-purple">the human side of enterprise.</span></p>
</div>
<div class="dhn-img">
<img src="http://i.imgur.com/kzJiOjx.jpg" alt="" />
</div>
CSS:
.dhn-info {
width: 100%;
background-color: #a20e45;
display: inline-block;
}
.dhn-info .dhn-text {
width: 50%;
height: auto;
float: left;
padding: 20px 10px 0px 35px;
}
.dhn-info .dhn-text p {
font-family: arial;
font-size: 24px;
color: #fff;
line-height: 30px;
text-transform: uppercase;
word-spacing: 5px;
margin: 0;
padding: 0;
display: block;
}
.dhn-info .dhn-img {
width: 40%;
height: 100%;
float: right;
}
.dhn-info .dhn-text p > span.text-purple {
color: #9b59b6;
}
.dhn-info .dhn-img img {
display: block;
height: auto;
max-width: 100%;
}

css aligning menu to the right

This is probably a simple one, but I can't seem to figure it out for the life of me. I'm making a mobile menu and I'm trying to make it sit to the right of the screen. (the search bar and the menu icon)
My problem is that if I float it to the right, the background disappears and if I text-align it the text-indent I have on a link decides to show up.
My html
<div id="subHeader">
<ul class="mobileMenu">
<li>
<form>
<input type="text" name="search" id="search" />
<input type="submit" value="Search" class="sub" />
</form>
</li>
<li class="menLink">MobileMenu</li>
</ul>
</div>
and an example can be seen over here at jsfiddle
http://jsfiddle.net/zazvorniki/9SWbs/1/
Some help would be much appreciated!
I achieved the layout you are after by adding width :100% and float: right to #subHeader. I also added float: right to .mobileMenu li and removed the margin attributes of .menlink. Please see below changes and jsfiddle...
#subHeader{
background: #c1c1ab;
width: 100%;
color: #1a1a15;
float: right;
}
.mobileMenu li{
display: inline-block;
float: right;
font: bold 1.2em/1.5em "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
margin-right: 4px;
}
.menLink {
background:url("http://tinyurl.com/kgd7ayt") no-repeat;
height: 3em;
width: 3em;
}
.menLink a {
text-indent:-9999px;
display:block;
height: 3em;
width: 3em;
}
jsfiddle demo

Center input type text inside a form inside div inside a wordpress page?

I've created a simple get method form and am having trouble centering the input box. The code works fine out of wordpress, but when I insert into a wordpress page, the input box becomes mis-aligned.
Here's the code I'm inserting on the wordpress page.
<div class="homebox">
<form method="get" action="/home-quote-page.html" form name="quote" rel="nofollow" onsubmit="return ray.ajax()">
<p class="topquotetext">Enter your zip code:</p>
<p><input name="zipcode" class="zipbox" type="text" value="" size="5" maxlength="5"/> </p>
<p><div style="getquote"><input type="image" src="/Photos/startquote.gif" alt="Start Your Quote" name="go" value='Submit'/></div></form></p>
<div id="load" style="display:none;">Finding...Please wait.</div>
</div>
Here's the css. Everything works fine except .zipbox it will allow me to change the color of the box and the height but that's it. No matter what number I input into the width of the box it stays the same width, it also doesn't center inside the div.
.homebox {
text-align: center;
width: 300px;
height: 268px;
background: #2872bd url(/Photos/home-insurance-box.jpg) no- repeat; }
.topquotetext {
font-family: sans-serif, Arial, Verdana;
font-size:16px;
color:#ffffff;
padding-top:70px;
text-align: center;
}
.zipbox {
width: 95px;
height: 25px;
text-align: center;
font-size: 24px;
margin-right: 10px;
margin-left: 10px;
margin-top: 5px;
border: #7F9DB9 1px solid;
background-color: #FFFED2;
}
.getquote {
width: 300px;
text-align: center;
}
Are you pasting this into the default WYSIWYG in WP? If so, WP is stripping out some of your markup. Find a plugin that will allow you to paste in markup, or create a new template and hard-code this section.
Of course it would be centered if you use margin-left: 10px; on the .zipbox and text-align: center would not make element centerd, just text which will be centered. There's nothing wrong with WordPress, it's just how you style the element.
Try this, a bit change of your stylesheet.
.zipbox {
width: 95px;
height: 25px;
display: block;
overflow: hidden;
clear: both;
margin-top: 5px;
margin-left: auto;
margin-right: auto;
font-size: 24px;
border: #7F9DB9 1px solid;
background-color: #FFFED2;
}
And also make sure that the parent element style not affecting the .zipbox and you don't need to wrap the <input /> element in <p></p>, wrap it with <div></div> instead.

CSS: I can't put a button in the middle of a DIV element

I'm using CSS buttons from this tutorial:
http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html
I need to put a button in the middle of a DIV so it's centered. But I can't!
Here's the code of the button:
<a class="button" href="#"><span>Bring world peace</span></a>
And here's CSS:
.clear { /* generic container (i.e. div) for floating buttons */
overflow: hidden;
width: 100%;
}
a.button {
background: transparent url('bg_button_a.gif') no-repeat scroll top right;
color: #444;
display: block;
float: left;
font: normal 12px arial, sans-serif;
height: 24px;
margin-right: 6px;
padding-right: 18px; /* sliding doors padding */
text-decoration: none;
}
a.button span {
background: transparent url('bg_button_span.gif') no-repeat;
display: block;
line-height: 14px;
padding: 5px 0 5px 18px;
}
Here's the code I'm trying to use:
<div align="center"><a class="button" href="#"><span>Bring world peace</span></a></div>
the align attribute for the div element is deprecated. You're better off defining a class for that div, like so:
<div class="centerize">
<a class="button" href="#"><span>Bring world peace</span></a>
</div>
And the CSS:
.centerize {
text-align: center;
}
Note however that setting the text-align will only affect the content inside the div. The div itself (should be) a block element, and depending on where it sits in the document structure, may not be centered itself.
Just to make a little more certain, you can do something like this:
.centerize {
display: block;
margin: 0 auto;
text-align: center;
}
Now you can apply centerize to any element, and that element should take up the entire browser's width and center-align its content.
Modify the button class for these properties:
.button{
margin-left:50%;
margin-right:50%;
position: relative;
}
And wrap your link in the div like this:
<div align="center">
<a class="button" href="#"><span>Bring world peace</span></a>
</div>
The a.button is floated to the left. You could try float: none; on that element. margin: 0 auto; is also useful for center-aligning elements.
Does that help?

Resources