I am working in Phone Gap using java script,html and css. I have implemented a swipeview using this.
my doubt is how should the CSS be.The CSS i implemented is as follows.
.swiper-threshold {
width:100%;
height:350px;
margin-top:40px;
text-align:left;
line-height:20px;
font-size: 15px;
text-align:justify;
text-justify:inter-word;
}
.swiper-threshold .swiper-slide{
width:auto;
height:350px;
margin-top:2%;
margin-left:0;
padding-right:0%;
text-align:left;
line-height:20px;
font-size: 15px;
text-align:justify;
text-justify:inter-word;
}
the sliding movement is from left to right.when it reaches the last slide.the movement reverses.
when,I change margin-left:0; from 0 to say 5...as and when I slide the left space gets on adding up the last slide is seen for half of the screen.
but,when i give margin-left:0; all are stuck to the left margin.
html coding:
<div id="swipe_body">
<div class="swiper-container swiper-threshold">
<div class="swiper-wrapper" id="swiper-wrapper">
</div>
</div>
</div>
SWIPER-SLIDE creation
var val = k+1;
var superdiv = document.getElementById('swiper-wrapper');
var newdiv = mySwiper.createSlide('div');
newdiv.append();
var divIdName = 'swiper-slide'+val;
console.log("div name: "+divIdName);
newdiv.setAttribute('id',divIdName);
newdiv.className="swiper-slide";
superdiv.appendChild(newdiv);
var cnt = '<div id="container'+val+'" class="container">values</div>';
document.getElementById(divIdName).innerHTML=cnt;
console.log("processsing parameter loop ");
what should i give such that n-number of swipes the slides should be the same position-middle of the screen.
please,guide me!
If I understand correctly, you're trying to get your slider to sit in the middle of the screen, but in doing so you're adding margin to the slider elements itself. Is that correct?
If so, the reason you're having trouble is that the slider implementation itself uses the margins to position the slides during movement left/right.
In order to control the spacing around the slider, the easiest bet is to wrap it in another div which you can traget directly.
So, taking the dimensions/etc that you've set up, your HTML would instead look like this:
<div class="slider-positioner">
<div id="swipe_body">
<div class="swiper-container swiper-threshold">
<div class="swiper-wrapper" id="swiper-wrapper">
</div>
</div>
</div>
</div>
You can then drop this CSS in to target that new div and push it into the middle (either using amrgin: auto as I have done below, or using set margin amounts as you seem to suggest you would like):
.slider-positioner{
display: block;
width: 550px; //set this to the width of your slider
height: 350px;
margin: 0px auto;
}
Related
I'm trying to replace JPG images with some HTML code. The blank outline of the buttons will still be used for the standard button, plus the hover, but I want the text within the button to be handled via code.
But the issue is that some of the buttons have multiple words with multiple lines, where-as others are only a couple words.
I'd like to get the font-size for the buttons to be dynamic and not set and then also word-wrap and adjust accordingly.
I found this which sort-of does what I'd like:
Font-size depends on div width and height
But I need to the text to word-wrap.
Here's my example which I cant seem to get to work properly.
https://jsfiddle.net/5L39xq1n/
<div style="text-align:center;padding:20px 0;">DIV Button Test</div>
<div id="buttoncontainer">
<div id="leftsidebuttons" class="leftsidebuttons">
Multiple lines because of the number of words
</div>
<div id="leftsidebuttons" class="leftsidebuttons">
Single Line
</div>
<div id="leftsidebuttons" class="leftsidebuttons">
This is another multiple line button
</div>
</div>
#buttoncontainer { width:175px; height:46px; line-height:46px; }
#leftsidebuttons { white-space:nowrap; }
.leftsidebuttons { color:#d5a200 !important;
background-color:blue;
font-family: Arial, Helvetica, sans-serif;
font-style:italic;
font-weight:700;
margin:5px 0;
text-align:center;
word-wrap: break-word;
}
.leftsidebuttons:hover { color:#ffcc00 !important;
background-color:red;
text-align:center;
}
var container = $("#buttoncontainer"),
text_container = $("#leftsidebuttons"),
start_size = 16,
container_width = container.width();
text_container.css('font-size', start_size + 'px');
while (text_container.width() > container_width) {
text_container.css('font-size', start_size--+'px');
}
Removing white-space:nowrap should do the job.
you use #leftsidebuttons { white-space:nowrap; } and then {word-wrap: break-word;} for the class .leftsidebuttons!!
There are many problem that you would need to fix:
multiple element with same id
don't use div for button
that approach is very slow, basically it tries each font size until it fits.
if you change the div to button with auto it will work.
https://jsfiddle.net/357d2ka6/1/
Here is a prototype of what I am trying to implement
Here is what I currently have : JsFiddle
I am trying to get the picture of the guy on the laptop to align correctly with and to the right of the paragraph components - Business Traveller, Office Supply Purchases, etc...
What I've tried is using Align attribute, changing my img src code to
<img id="laptop" align="middle" src="zoom-39988392-3.JPG" height = "90" width ="90" />
but that didn't have any effect.
I also tried Float but that messed up my margins and the organization of my left components.
Is there a way I can do this without floating?
See the fiddle
The HTML and CSS that i've used is as follows. Used float:left
HTML
<div class="container">
<div id="choices">
<p class="choice">Business Traveller</p>
<p class="choice">Office Supply Purchases</p>
<p class="choice">Stay at home parent</p>
<p class="choice">Entertainment</p>
<p class="choice">Profile 6</p>
</div>
<div class="image"></div>
</div>
CSS
html, body, .container {
height:100%;
}
#choices {
width:30%;
float:left;
}
.choice {
margin-top:0px;
margin-left:20px;
text-align:center;
width:100%;
background-image: url("http://i.imgur.com/H43sVoi.png");
padding-top:15px;
padding-bottom:15px;
}
.image {
height:100%;
width:65%;
background-color:red;
float:left;
}
You will have to work with the height and width of each divs. I just made it roughly.
You have to create two columns. 1 column for the menu and the second column for the image. If you do this, you wont have trouble floating.
I have some popups whit this structure:
<div id="pop_cont" class="popup_cont" >
<div id="pop" class="popup" >
<div class="xclose" ><img src="images/divclose.png" onclick="closediv('pop_cont');" title="chiudimi" /></div>
<div id="pop_title" class="popup_title" >TITLE</div>
<div id="pop_int" >SOME CONTENT</div>
</div>
</div>
with this css:
#alert_cont, .alert_cont, .popup_cont {
z-index:600;
position:fixed;
top:0px;
left:0px;
width:100%;
height:100%;
background-color:rgba(0,0,0,0.5);
display: none;
}
#alert, .alert, .popup{
position: absolute;
background-color: white;
border: 1px solid black;
border-collapse: collapse;
}
#alert_int, .alert_int, .popup_int{
padding:10px;
}
.xclose {
right: 1px;
top: 1px;
float: right;
cursor:pointer;
border:0px;
}
#alert_title, .alert_title, .popup_title{
background-color:#ffd600;
border:1px solid #ffe666;
color: #000000;
font-weight: bold;
font-family: Arial, Helvetica, sans-serif;
text-align:center;
cursor: move;
}
I later move the popup i get , grabbing the "class='popup_title'" divs and moving around the parent element.
Using this kind of script:
var oDrag = null
var x,y,dx,dy
function mdown(e) {
if (!e) var e = window.event;
oDrag = (e.target) ? e.target : e.srcElement
if (oDrag.className=='popup_title'){
oDrag=oDrag.parentElement;
x = e.clientX;
y = e.clientY;
dx = x - parseInt(oDrag.style.left);
dy = y - parseInt(oDrag.style.top);
document.onmousemove=mdrag_on;
document.onmouseup=mdrag_off;
} else {
oDrag = null;
}
}
function mdrag_on(e) {
if (!e) var e = window.event;
oDrag.style.left = parseInt(e.clientX - dx)+'px';
oDrag.style.top =parseInt(e.clientY - dy)+'px';
return false
}
function mdrag_off(e) {
document.onmousemove=null;
}
Very simple but it works.
The problem is that when i get near the edge of the screen, right edge, the div get i'm moving get compressed instead of going offscreen.
It get compressed till is possible , wrapping text , when not possible anymore it goes offscreen.
When i go back it goes to is standard dimension as soon as possible.
There is any method to avoid this? like setting some css of the div i'm moving?
Ok i solved.
Or really i didn't solve but i found design error and sort of solution.
I have a container that basically is the big shadow that cover everything when the popup comes out.
The popup is child of this shadow, so when i go edge of the screen, really i go edge of the shadow and the web browser of course try to make the popup stay inside it.
So i gave
width:300%
to my "shadow" container and now it looks fine. ( strange on the left and bottom side it was not happening... )
So now real solution would be to make the shadow not parent to popup, but this would require to have to style.display='block' each time i need to show a popup ( big deal? ) or keep this width:300%
Someone as some good suggestion to give me?
Image
I tried this with the following CSS and HTML. It looks fine when the browser is of full width and scrambled when browser is resized. I WANT the elements to be where there and a HORIZONTAL SCROLL has to appear when the BROWSER is RESIZED. Pretty new to web programming. Text-align:center for positioning the center column would not work because, every time a new text is added in the left or right, it gets relocated and also center column element in ROW1(text) and ROW2(Button) do not appear along the same line. That is, text appears a bit right and the button a bit left. Text-align won't work here.
CSS:
#charset "utf-8";
/* CSS Document */
body
{
background-color:#000;
}
.wrapper
{
width:70%;
margin:0 auto;
padding:2px;
background-color:#fff;
}
.second_row
{
padding:2px;
margin-top:10px;
}
.center_container
{
width:30%;
margin:0 auto;
}
.left_container
{
width:33%;
float:left;
}
.right_container
{
width:33%;
float:right;
}
.topelements
{
margin-top:0px;
color:#777;
padding:2px;
}
.topelements a:link
{
color:#29a3cc;
}
.topelements a:active a:hover
{
color:#29a3cc;
}
.logo
{
overflow:hidden;
}
HTML code:
<div class="wrapper">
<span class="topelements float_left" >Mail us: admin#admin.com</span>
<span class="topelements float_right">Left links My xyz</span>
<span class="topelements center_container">Welcome to xyz ! Sign in or Signup.</span>
</div>
<div class="wrapper second_row">
<span class="left_container">Srini</span>
<span class="right_container">Vas</span>
<form class="center_container">
<input type="text" placeholder="Goooooooooooo!" />
<input type="submit" value="Search" />
</form>
</div>
<div class="wrapper">
If you want to align you object in the center, there are a couple of different ways. First of all, there is the text-align:center; which you don't need right now. There is also object-position:center; which basically does the same, but with an object. This way isn't the best, but you could add a certain percentage of padding to either side but that's not recommended. Lastly, there's alignment-adjust:central;. This may not be perfect for your situation but just try out all of these and see if they work. Good luck!
One way that would work is to set your wrapper width to a fixed value (something in 800px for example). As long as this width was longer than all the content you are putting within that wrapper, everything should work as you want. The browser will automatically place a horizontal scroll bar when the window gets smaller than the width of the wrapper.
This is just a small error I found in the CSS and I don't know if this will help too much. The div you added was not referred to as a div, but a class. For example, if you wanted to style a div in CSS, you would do this:
#divname {
CSS for div goes here...
}
On the other hand, if you wanted to add a little style to a class, you would go like this:
.classname {
CSS for class goes here...
}
If you were wondering what the difference for each is, the answer is simple. A class can define multiple objects while the divs are just limited to one object or element.
Morning,
I have the following HTML:
<div id="sah_padding">
<div id="sah_holder">
<div id="sah_name">Hello [agent_name]</div>
<div id="sah_logout">✖</div>
</div>
You are working with [customer_name]
</div>
and I have the following CSS:
#sah_padding{
padding:10px 10px 10px 10px;
}
#sah_holder{
padding-bottom:10px;
clear:both;
}
#sah_name{
float:left;
width:50%;
}
#sah_logout{
text-align:right;
}
#logout_link{
color:#fff;
text-decoration:none;
font-weight:bold;
}
However my login link and Hello message aren't aligning correctly, the logout link is a few pixels below the hello message and I need them to be on the same horizontal line. What am I doing wrong?
if you set line-height :1 to #logout_link element, it should correct the alignment
(of course feel free to choose a different value to adjust it)
Give float to your #sah_logout also. Write like this:
#sah_logout{
float: left;
text-align:right;
}
Check this http://jsfiddle.net/QUNT2/
Check the line-height of your elements!!!
You need to set a float to #sah_logout as well:
#sah_logout{
float: left;
text-align:right;
}
You can even make it say, float: right. It's entirely your choice. Doing only a text-align: right will modify how the inner contents of the container behave, not how the div behaves within the flow.
Also, you might have a few problems with the parent div not wrapping correctly around the children divs (as all children now have float properties), so you might need to add another div, with clear: both set in its style:
<div id="sah_holder">
<div id="sah_name">Hello [agent_name]</div>
<div id="sah_logout">✖</div>
<div style="clear: both"></div>
</div>
Instead of wasting time with block level elements why don't you simply use inline elements for both the "Hello" text and the logout link? That's what inline elements are supposed to do - stay in line with each other.
<div id="sah_padding">
<div id="sah_holder">
<span id="sah_name">Hello [agent_name]</span>✖
</div>
<span>You are working with [customer_name]</span>
</div>
Its is highly unlikely that you would need any of the CSS code you previously used for elements inside sah_holder unless you want to style them differently.
check it your updated html :-
<div id="sah_padding">
<div id="sah_holder">
<div id="sah_name">Hello [agent_name]</div>
<div id="sah_logout">You are working with [customer_name]</div>
</div>
</div>
your updated css:-
#sah_padding{
padding:10px 10px 10px 10px;
}
#sah_holder{
padding-bottom:10px;
border:1px solid red;
overflow:hidden;
}
#sah_name{
float:left;
width:50%;
}
#sah_logout{
float:right;
}
.logout_link{
color:black;
text-decoration:none;
font-weight:bold;
}
or you can see the demo:- http://jsfiddle.net/WnecH/11/