Wrapping text around an image - html

I'm having some trouble wrapping text on a web application I'm designing for a client. Below you can see where I am having trouble:
So ideally I would like this text to wrap underneath the text above it, in a uniform manner. Not underneath the image. Below you can see the HTML code I am using for this:
<ul>
<div class="grid">
<div class="col-1">
<li class="howDoPadding">
<label for="id_delivery_0">
<img src="{{ STATIC_URL }}rd/images/message_icon.png" class="byAppointment" />
<input checked="checked" type="radio" id="id_delivery_0" value="chat" name="delivery" />
Answer<div class="lightBlueText">Chat</div> By Appointment (Fastest)
</label>
</li><!-- .howDoPadding -->
</div><!-- .col-1 -->
<div class="col-1">
<li>
<label for="id_delivery_2">
<img src="{{ STATIC_URL }}rd/images/message_fly_right.png" class="mailASAP" />
<input type="radio" id="id_delivery_2" value="email" name="delivery" />
Answer<div class="lightBlueText">Mail</div> ASAP (Within 1-2 days)
</label>
</li>
</div><!-- .col-1 -->
</div><!-- .grid -->
</ul>
And all of the CSS is below:
/* Form */
.col-1 li.howDoPadding { padding-bottom: 10px!important; }
.byAppointment { margin: 0 0 -4px 10px;}
.offlineForm .lightBlueText {
color: #80A9BD;
display: inline;
}
.mailASAP { margin: 0 0 -4px 18px; }
/* Grid */
*, *:after, *:before {
box-sizing: border-box;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
}
.grid:after {
clear: both;
content: "";
display: table;
}
/* Grid Gutters */
[class*='col-'] {
float: left;
padding-right: 20px;
}
[class*='col-']:last-of-type { padding-right: 0; }
.col-1 { width: 100%; }
You can also check out a working example of this at: http://jsfiddle.net/Mjs2u/
Thank you very much for any and all help. I really appreciate it! Let me know if you guys need me to elaborate on anything else or you need/want more code.

Your HTML code is ill-formed. Forget ol, ul listing if there isn't a list. ol should only have li as its children elements. <ol><div><li></li></div></ol> is bad practice.
Basically, if you want to put something under sth, you can group them into a div or other block element. Do not use float layout for the div or you will have similar layout as your example if the previous element is shorter than your div.
You can use some flexible layout patterns. Use a wrapper div with a wide padding-left, where the image and radio button will be placed. And put the label and text in the main body of the div. Something like this:
<div class="flexible-layout">
<div class="left-content">
Image
</div>
<div class="main-content">
You text goes here<br />
Second line goes here
</div>
</div>
<style type="text/css">
.flexible-layout {
padding-left: 80px;
position: relative;
}
.flexible-layout .left-content {
position: absolute;
left: 0;
top: 0;
width: 80px;
}
</style>
For your specific code sample, I made some refactoring based on the content you've given, and you can check jsFiddle to see if it's what you want.
Hope it helps.

<form class="offlineForm">
<ul>
<li class="howDoPadding">
<label for="id_delivery_0">
<img src="http://i.imgur.com/RVmh2rz.png" class="byAppointment" />
<input checked="checked" type="radio" id="id_delivery_0" value="chat" name="delivery" />
<div class="label">Answer <span class="lightBlueText">Chat</span> By Appointment (Fastest)</div>
</label>
</li>
<li>
<label for="id_delivery_2">
<img src="http://i.imgur.com/8J0SEVa.png" class="mailASAP" />
<input type="radio" id="id_delivery_2" value="email" name="delivery" />
<div class="label">Answer <span class="lightBlueText">Mail</span>ASAP (Within 1-2 days)</div>
</label>
</li>
</ul>
</form>
body { font-family: Arial, Helvetica, sans-serif; font-size: 12px; }
ul li { list-style: none; }
* { margin: 0; padding: 0; }
*, *:after, *:before { box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; }
form.offlineForm { width: 200px; margin: 0 auto; padding: 30px; }
label { padding-left: 25px; display: block; position: relative; }
label img { position: absolute; left: -25px; }
label .lightBlueText { color: #80A9BD; }
label div.label { display: inline; }
li.howDoPadding { padding-bottom: 20px; }
http://jsfiddle.net/4faQk/
hope it will be helpfull

try this:
add span with class name in the text you want to move then position:relative;
below i add <span class="text">
html:
<li class="howDoPadding">
<label for="id_delivery_0">
<img src="http://i.imgur.com/RVmh2rz.png" class="byAppointment" />
<input checked="checked" type="radio" id="id_delivery_0" value="chat" name="delivery" />Answer
<div class="lightBlueText">Chat</div> <span class="text">By Appointment (Fastest)<span>
</label>
</li>
<li>
<label for="id_delivery_2">
<img src="http://i.imgur.com/8J0SEVa.png" class="mailASAP" />
<input type="radio" id="id_delivery_2" value="email" name="delivery" />Answer
<div class="lightBlueText">Mail</div> <span class="text">ASAP (Within 1-2 days)</span>
</label>
</li>
css:
.text {
position:relative;
left:15px;
}
hope this help you

Related

CSS for different device sizes

I have a simple page that consists of a form. There is a string for what the input box should be, and then the input box.
I want two different behaviors. When a cell phone is accessing the page, I want everything to be stacked on top of each other, but when the page is accessed via a computer I want multiple rows consisting of the the title, followed by the input box on the same row.
I've researched media queries by I still don't understand it enough to get through.
<html>
<head>
<style>
</style>
</head>
<body>
<form>
<center>
<div class="left">
First name:
</div>
<div class="right">
<input type="text" name="firstname"/>
</div>
<div class="left">
Last name:
</div>
<div class="right">
<input type="text" name="lastname"/>
</div>
<div class="left">
Email Address:
</div>
<div class="right">
<input type="text" name="email"/>
</div>
<div class="left">
Address:
</div>
<div class="right">
<input type="text" name="address"/>
</div>
<div class="left">
I've practiced yoga for at least one year:
</div>
<div class="right">
<input type="checkbox" name="oneyear"/>
</div>
<div class="right">
<input type="submit" name="submit" value="submit"/>
</div>
</center>
</form>
</body>
</html>
You have multiple choice: using Bootstrap to easily display your grid in different ways on window resize.
You can also use media queries, combine with a grid layout like Flexbox or Grid.
Or even use Jquery and the windworesize function.
Personnaly, i would choose Flexbox and the flex-direction propriety when the window reach the size of a smartphone or tablet.
To write a media querie, you just have to type something like #media screen and (max-width: 640px) for instance and write your rules inside the curly brackets.
Here is a sample code.
<!DOCTYPE html>
<html>
<head>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
height: 100%;
font-size: 16px;
line-height: 22px;
font-family: Arial, Helvetica, sans-serif;
background-color: #f5f5f5;
}
.clearfix::after {
content: "";
clear: both;
display: table;
}
.my-form {
width: 100%;
max-width: 920px;
margin: 0 auto;
padding: 20px;
}
.my-form .input {
width: 100%;
padding: 10px;
}
.my-form .input .left {
display: block;
width: 100%;
line-height: 24px;
padding: 3px 0;
margin-bottom: 5px;
}
.my-form .input .right {
width: 100%;
}
.my-form .input input[type='text'], .my-form .input input[type='email'], .my-form .input textarea {
display: block;
width: 100%;
height: 30px;
font-size: 16px;
padding: 3px;
line-height: 22px;
border: 1px solid rgba(0,0,0,.3);
}
.my-form .input textarea {
height: auto;
min-height: 60px;
resize: vertical;
}
.my-form .input input[type='submit'] {
display: block;
width: 100%;
padding: 15px;
background-color: navy;
color: #ffffff;
font-size: 16px;
line-height: 22px;
}
#media screen and (max-width: 1024px) {
.my-form .input:after {
content: "";
clear: both;
display: table;
}
.my-form .input .left {
float: left;
width: 35%;
padding-right: 10px;
margin-bottom: 0;
}
.my-form .input .right {
float: right;
width: 65%;
}
}
</style>
</head>
<body>
<form class="my-form">
<div class="input">
<label class="left" for="firstname">
First name:
</label>
<div class="right">
<input type="text" id="firstname" name="firstname" />
</div>
</div>
<div class="input">
<label class="left" for="lastname">
Last name:
</label>
<div class="right">
<input type="text" id="lastname" name="lastname" />
</div>
</div>
<div class="input">
<label class="left" for="email">
Email Address:
</label>
<div class="right">
<input type="email" id="email" name="email" />
</div>
</div>
<div class="input">
<label class="left" for="address">
Address:
</label>
<div class="right">
<textarea cols="10" rows="5" id="address" name="address"></textarea>
</div>
</div>
<div class="input">
<div class="left"></div>
<div class="right">
<label for="oneyear"><input type="checkbox" id="oneyear" name="oneyear" /> I've practiced yoga for at least one year:</label>
</div>
</div>
<div class="input">
<input type="submit" name="submit" value="submit" />
</div>
</form>
</body>
</html>
You need Media Query for this. Media query is basically writing different CSS for devices with different widths. You can learn more from here- https://www.w3schools.com/css/css3_mediaqueries_ex.asp
Also check out this article- https://css-tricks.com/snippets/css/media-queries-for-standard-devices/
You can also use jQuery for the same using matchmedia..
Here is a JSbin example for you- https://jsbin.com/kutacuzece/edit
(function($) {
/*
* We need to turn it into a function.
* To apply the changes both on document ready and when we resize the browser.
*/
function mediaSize() {
/* Set the matchMedia */
if (window.matchMedia('(min-width: 768px)').matches) {
/* Changes when we reach the min-width */
$('body').css('background', '#222');
$('strong').css('color', 'tomato');
} else {
/* Reset for CSS changes – Still need a better way to do this! */
$('body, strong').removeAttr('style');
}
};
/* Call the function */
mediaSize();
/* Attach the function to the resize event listener */
window.addEventListener('resize', mediaSize, false);
})(jQuery);
OR you can use something as simple as this-
if ($(window).width() < 960) {
$(selector).css({property:value, property:value, ...})
}
else if ($(window).width() < 768) {
$(selector).css({property:value, property:value, ...})
}
else {
$(selector).css({property:value, property:value, ...})
}

How do I increase the width of each tab in order for them to occupy the whole width of the content block?

I'm fairly new to programming and this site but I've been studying different codes for vertical and horizontal tabs and there's a questions I want to ask regarding this one https://jsfiddle.net/eu81273/812ehkyf/ :
Basically, I've been trying to change the width of the tabs in order for them to occupy the whole width of the content block below, however I wasn't able to do it, what should i add/change? Adding width: 200px; in .tab or .tab label doesn't seem to work.
.tabs {
position: relative;
min-height: 200px; /* This part sucks */
clear: both;
margin: 35px 0 25px;
background: white;
}
.tab {
float: left;
}
.tab label {
background: #eee;
padding: 10px;
border: 1px solid #ccc;
margin-left: -1px;
position: relative;
left: 1px;
top: -29px;
-webkit-transition: background-color .17s linear;
}
It would be nice if a detailed explanation is provided on the changes or additions so I can understand it well.
A way with the use of javascript was found, however, is it possible to only uses css and html?
See first of your body padding is so high.
so may be i think you have to decrease it.
body {
background: #999;
padding: 20px 2px;
}
.tabs {
position: relative;
min-height: 200px; /* This part sucks */
clear: both;
margin: 35px 0 25px;
background: white;
width:100%;
}
you can set your tabs width to - 33%
function openTab(tabId) {
var i;
var x = document.getElementsByClassName("tab");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
document.getElementById(tabId).style.display = "block";
}
<link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet"/>
<div class="w3-bar w3-black">
<button class="w3-bar-item w3-button" onclick="openTab('TabA')">TabA</button>
<button class="w3-bar-item w3-button" onclick="openTab('TabB')">TabB</button>
<button class="w3-bar-item w3-button" onclick="openTab('TabC')">TabC</button>
</div>
<div id="TabA" class="w3-container tab">
<input type="radio" id="tab-1" name="tab-group-1" checked>
<label for="tab-1">Tab One</label>
<div class="content">
<p>Stuff for Tab One</p>
</div>
</div>
<div id="TabB" class="w3-container tab" style="display:none">
<input type="radio" id="tab-2" name="tab-group-1">
<label for="tab-2">Tab Two</label>
<div class="content">
<p>Stuff for Tab Two</p>
<img src="http://placekitten.com/200/100">
</div>
</div>
<div id="TabC" class="w3-container tab" style="display:none">
<input type="radio" id="tab-3" name="tab-group-1">
<label for="tab-3">Tab Three</label>
<div class="content">
<p>Stuff for Tab Three</p>
<img src="http://placedog.com/200/100">
</div>
</div>
<style> .w3-bar .w3-button{
width:33.3%;
}</style>

Tab contents are not consuming space, so html tags defined later are not actually rendered after tab contents

I'm trying to build tabs using pure HTML and CSS. I've got the tab functionality working, so when you click a tab label the corresponding content shows.
But in my design I've 2 tab areas, 1 for request and 1 for response. For some reason my request seems to overlap the response area, why is this so?
The <hr> tag that separates the 2 areas should always be below the request area's shown content.
http://jsfiddle.net/bobbyrne01/pgzt6nbf/
Current output (content tab) ..
Current output (header tab) ..
Desired output ..
html ..
<div id="main">
<div class="left w60">
<div class="center">
<h2>Request</h2>
</div>
<div>
<div>
<input id="url" placeholder="Request URL .." class="w100" />
</div>
<br/>
<div>
<select id="method">
<option value="0">GET</option>
<option value="1">HEAD</option>
</select>
<button type="button" id="submit">Submit</button>
</div>
<br/>
<div class="tabs">
<div class="tab">
<input type="radio" id="tab-1a" name="tab-group-1" hidden checked />
<label class="tabLabel" for="tab-1a">Headers</label>
<div class="content">
<div id="headersRequest">
<table id="headersRequestTable" class="w100">
<tr>
<th>Name</th>
<th>Value</th>
<th>
<input type="button" id="newHeaderButton" value="+" />
</th>
</tr>
</table>
</div>
</div>
</div>
<div class="tab">
<input type="radio" id="tab-2a" name="tab-group-1" hidden checked />
<label class="tabLabel" for="tab-2a">Body content</label>
<div class="content">
<div id="bodyRequest">
<textarea id="bodyRequestListItem" rows="10" class="w100"></textarea>
</div>
</div>
</div>
</div>
</div>
<hr>
<div class="center">
<h2>Response</h2>
</div>
<div class="tabs">
<div class="tab">
<input type="radio" id="tab-1b" name="tab-group-2" hidden checked />
<label class="tabLabel" for="tab-1b">Headers</label>
<div class="content">
<div id="headers"></div>
</div>
</div>
<div class="tab">
<input type="radio" id="tab-2b" name="tab-group-2" hidden checked />
<label class="tabLabel" for="tab-2b">Body content</label>
<div class="content">
<button id="clipboard" style="display: none;">Copy to clipboard</button>
<br/>
<div id="bodyContent"></div>
</div>
</div>
<div class="tab">
<input type="radio" id="tab-3b" name="tab-group-2" hidden checked />
<label class="tabLabel" for="tab-3b" id="statusListItem">Status</label>
<div class="content">
<div id="status"></div>
</div>
</div>
</div>
</div>
<div class="right w30">
<div class="center">
<h2>History</h2>
<table id="historyContainer"></table>
</div>
</div>
</div>
css ..
.left {
float: left;
}
.right {
float: right;
}
.center {
text-align: center;
}
.w30 {
width: 30%;
}
.w40 {
width: 40%;
}
.w50 {
width: 50%;
}
.w60 {
width: 60%;
}
.w100 {
width: 100%;
}
.bCollapse {
border-collapse: collapse;
}
/*
* Tabs
*/
.tabs {
position: relative;
height: 100%;
clear: both;
margin: 35px 0 25px;
}
.tab {
float: left;
}
.tabLabel {
background: #eee;
padding: 10px;
border: 1px solid #ccc;
margin-left: -1px;
position: relative;
left: 1px;
top: -20px;
}
.content {
position: absolute;
top: 2px;
left: 0;
right: 0;
bottom: 0;
padding: 20px;
opacity: 0;
}
[type=radio]:checked ~ label {
background: white;
border-bottom: 1px solid white;
z-index: 2;
}
[type=radio]:checked ~ label ~ .content {
z-index: 1;
opacity: 1;
}
Try to add min-height for tabs Demo
.tabs {
position: relative;
height: 100%;
min-height: 200px;
clear: both;
margin: 35px 0 25px;
display:block;
}
I remember a year or 2 back, before I learned JS, when I was heavily invested in creating functioning tabs using only HTML and CSS. They can be done, but at a cost of being unable to use animations on them (you cannot animate from display: none to display: block).
Anyway, the issue you are having if because your element with the class "content" has its position set to "absolute". By definition, you are telling this element to not consume space. Remove this, or change the position to "relative", and you should see a more desired behaviour.

<center> tags will only center text but not image

I'm trying to center a <div> element containing both text and image using <center> tags, but for some reason it only applies on the text and not the image.
HTML:
<body>
<h1 align="center">Search For a Member</h1>
<br>
<br>
<form action="SearchController" method="get">
Enter the member's first name: <input type="text" style="width: 18em;" name="searchBox">
<input style="width:6em;" type="submit" value="Search">
<input style="width:6em;padding-left:7px;" type="submit" value="Back">
</form>
<center>
<div class="profile">
<img style="float:left;" src="default.jpg"height=100 width=100>
First Name
<br>
Last Name
<br>
</div>
</center>
</body>
CSS:
<style>
body {
background-color: #BCD2EE;
margin-left: 20%;
margin-right: 20%;
border: 1px outset #4876FF;
border-width: 5px;
padding: 10px 10px 30px 10px;
}
.profile {
overflow: hidden;
padding-top: 30px;
}
</style>
But if you'll try it, you'll see that only the text "First Name" and "Last Name" gets centered but not the picture. (I know you won't be able to see the picture default.jpg, but it will show you where the image would be).
Why won't the picture get centered? is it because of the float:left; property, which excludes the picture from the <center> tag?
If so, how can it be fixed?
<img style="float:left;"
You shouldn't have style="float:left;"
Remove that, and also add a line break <br> after the img tag
http://jsfiddle.net/jn8zgszy/
Remove float:left inline styling from img tag
Change:
<img style="float:left;" src="default.jpg"height=100 width=100>
To:
<img src="default.jpg" height="100" width="100"><br />
JSFiddle Demo
An alternative idea without the deprecated <center> tag, external CSS and tweaked form elements.
Centering is done via .wrap { display: table; margin: 0 auto; }
Have a jsBin example!
HTML
<div class="wrap">
<form action="SearchController" method="get">
<legend>Search For a Member</legend>
<label for="firstName">Enter the member's first name:</label>
<input name="searchBox" id="firstName" type="text">
<button type="submit">Search</button>
<button type="submit">Back</button>
</form>
<div class="profile">
<img src="http://www.placehold.it/100" />
<dl>
<dt>First Name</dt>
<dd>Greg</dd>
<dt>Last Name</dt>
<dd>Norman</dd>
</dl>
</div>
</div>
CSS
* {
margin: 0;
padding: 0;
}
.wrap {
display: table;
margin: 0 auto;
}
form {
padding: 10px;
}
legend {
margin: 20px auto;
font-weight: bold;
font-size: 1.4em;
display: table;
}
.profile img {
margin: 10px 0 10px;
}
.profile dt {
font-weight: bold;
}
.profile dd {
padding: 10px 0;
}
If you wanted the Image and those text to be center and one below the other then you could simple give text-align:center; to your .profile
.profile{
text-align:center;
}

How to code this form?

Im trying to get away from using the html TABLE tag, but cant figure out how to build, what I want it to look like. I have made a screenshot of me using the table tag,
How would I do this with divs or/and spans etc, and still retain the vertical alignment of the labels (firstname, lastname in this example)?
(font size and color etc is of course irrelevant here)
alt text http://img522.imageshack.us/img522/7857/forme.jpg
thankful for any input,
modano
It's good that you don't want to use the table tag for layout. The thing to keep in mind when switching is to try to make the HTML as semantical as possible. What this means might vary, since there are no real strict rules, but it could look something along these lines:
<form [..]>
<ul>
<li class="hasError">
<em class="feedback">error message here</em>
<div class="attribute">
<label for="firstName">First name:</label>
<em>(required)</em>
</div>
<div class="input">
<input type="text" name="firstName" id="firstName" />
<em class="description">optional description here</em>
</div>
<span class="clearBoth" />
</li>
<li>
<em class="feedback" />
<div class="attribute">
<label for="firstName">Last name:</label>
<em>(required)</em>
</div>
<div class="input">
<input type="text" name="lastName" id="firstName" />
<em class="description">optional description here</em>
</div>
<span class="clearBoth" />
</li>
</ul>
</form>
This achieves the following:
By placing the error feedback message above the divs, you can make an arbitrarily long error message without losing alignment
Each input element (and label) is kept in a single list item, thus grouping them logically. It also reads something like the following in a screen reader: "Form. List of two items. Label [...]". This gives the user a hint of that the form contains two inputs.
By adding the hasError class to a list item, you can easily target the descendant elements with CSS for error specific styling.
A sample CSS file could look something like (note that this is untested):
form li {
width: 300px;
}
form li.hasErrors {
width: 298px;
border: 1px red;
background-color: #C55;
}
form .attribute {
float: left;
clear: left;
width: 60px;
}
form .input {
float: right;
clear: none;
width: 240px;
}
form .feedback {
display: block;
padding-left: 50px;
color: red;
}
form .description {
display: block;
clear: both;
color: #888;
}
.clearBoth { display: block; clear: both; }
A very very good tutorial on creating accessible HTML/CSS forms can be found on A list Apart: Prettier Accessible Forms
Generally a fantastic site for information on how to create good, clean and accessible websites.
Simply give your labels a specific width; this will ensure your fields line up. You can also float your labels and inputs to easily break them into rows. Here's a minimal example:
<style type="text/css">
form { overflow: auto; position: relative; }
input { float: left; }
label { clear: left; float: left; width: 10em; }
</style>
<form>
<label>Field 1</label><input/>
<label>Field 2</label><input/>
<label>Field 3</label><input/>
</form>
I am no CSS expert, but this should get you started. Of course the styles should be in an external style sheet.
<html>
<head>
<style>
html {
font-size: 76%;
}
body {
font-size: 1.0em;
font-family: verdana;
}
div.input {
border: 1px solid white;
clear: left;
width: 25em;
height: 5em;
padding: 2px;
margin-bottom: 1.0em;
}
div.error {
border: 1px solid red;
}
div.label {
float: left;
width: 7em;
}
div.field {
float: left;
}
div.errormessage {
color: red;
}
div.description {
color: #bbb;
}
input.text {
width: 13em;
}
</style>
</head>
<body>
<form>
<div class="input error">
<div class="label">
<div> </div>
<label>First name:<br>(required)</label>
</div>
<div class="field">
<div class="errormessage">error message here</div>
<input type="text" name="FirstName" class="text">
<div class="description">optional description here</div>
</div>
</div>
<div class="input">
<div class="label">
<div> </div>
<label>Last name:<br>(required)</label>
</div>
<div class="field">
<div class="errormessage"> </div>
<input type="text" name="LastName" class="text">
<div class="description">optional description here</div>
</div>
</div>
</form>
</body>
</html>