Posts

Showing posts with the label Html

Convert HTML / CSS From Adobe XD

Answer : Adobe XD has a plugin ecosystem where you can download a third-party built plugin to achieve tasks not supported by Adobe XD itself. For web export, I can recommend a plugin called "Web Export." In order to use the plugin, Make sure you have the latest version of XD Go to Plugins > Discover Plugins > Search "Web Export" Click "Install" Hope this helps! Natively, you can't (yet), although some external plugins can help you achieve that. Adobe XD is a prototyping tool, ie it has been designed for producing the designs of websites and app before passing it to a developer that will "manually" build the HTML/CSS/JS out of it. However, the export to HTML/CSS/JS feature has been asked before by the community many times and the Adobe team is currently working on it (check this and this).

Can A Div Have Multiple Classes (Twitter Bootstrap)

Answer : Sure, a div can have as many classes as you want (this is both regarding to bootstrap and HTML in general): <div class="active dropdown-toggle"></div> Just separate the classes by space. Also: Keep in mind some bootstrap classes are supposed to be used for the same stuff but in different cases (for example alignment classes, you might want something aligned left, right or center, but it has to be only one of them) and you shouldn't use them together, or you'd get an unexpected result, basically what will happen is that the class with the highest specificity will be the one applied (or if they have the same then it'll be the one that's defined last on the CSS). So you better avoid doing stuff like this: <p class="text-center text-left">Some text</p> Absolutely, divs can have more than one class and with some Bootstrap components you'll often need to have multiple classes for them to function as you w...

Bootstrap Radio Button "checked" Flag

Answer : Assuming you want a default button checked. <div class="row"> <h1>Radio Group #2</h1> <label for="year" class="control-label input-group">Year</label> <div class="btn-group" data-toggle="buttons"> <label class="btn btn-default"> <input type="radio" name="year" value="2011">2011 </label> <label class="btn btn-default"> <input type="radio" name="year" value="2012">2012 </label> <label class="btn btn-default active"> <input type="radio" name="year" value="2013" checked="">2013 </label> </div> </div> Add the active class to the button ( label tag) you want defaulted and checked="" to ...

Bootstrap Toast Does Not Show Up

Answer : You need to put the valid option. i:e show, hide or a callback function . See - https://getbootstrap.com/docs/4.2/components/toasts/. $('.toast').toast('show'); <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script> <div class="toast" role="alert" aria-live="assertive" aria-atomic="true"> <div class="toast-header"> <img height="200px" width="200px" src="https://upload.wikimedia.org/wikipedia/commons/f/f9/Phoenicopterus_ruber_in_S%C3%A3o_Paulo_Zoo.jpg" class="rounded mr-2" alt="..."> <strong class="mr-auto">Boots...

Css Scrollbar-width Example

The scrollbar-width property allows the author to set the maximum thickness of an element’s scrollbars when they are shown. Initial value auto Applies to scrolling boxes Inherited no Computed value as specified Animation type discrete Syntax /* Keyword values */ scrollbar-width : auto ; scrollbar-width : thin ; scrollbar-width : none ; /* Global values */ scrollbar-width : inherit ; scrollbar-width : initial ; scrollbar-width : unset ; Values <scrollbar-width> Defines the width of the scrollbar as a keyword. It must be one of the following values: auto The default scrollbar width for the platform. thin A thin scrollbar width variant on platforms that provide that option, or a thinner scrollbar than the default platform scrollbar width. none No scrollbar shown, however the element will still be scrollable. Note : User Agents must apply any scrollbar-width value set on the root element to the viewport. Accessibility concerns Use this property with...

Css :first-of-type Example

The :first-of-type CSS pseudo-class represents the first element of its type among a group of sibling elements. /* Selects any <p> that is the first element of its type among its siblings */ p:first-of-type { color : red ; } Note : As originally defined, the selected element had to have a parent. Beginning with Selectors Level 4, this is no longer required. Syntax :first-of-type Examples Styling the first paragraph HTML < h2 > Heading </ h2 > < p > Paragraph 1 </ p > < p > Paragraph 2 </ p > CSS p:first-of-type { color : red ; font-style : italic ; } Result Nested elements This example shows how nested elements can also be targeted. Note that the universal selector ( * ) is implied when no simple selector is written. HTML < article > < div > This `div` is first! </ div > < div > This < span > nested `span` is first </ span > ! </ div > < div > This < em > ...

Css :first-child Example

The :first-child CSS pseudo-class represents the first element among a group of sibling elements. /* Selects any <p> that is the first element among its siblings */ p:first-child { color : lime ; } Note : As originally defined, the selected element had to have a parent. Beginning with Selectors Level 4, this is no longer required. Syntax :first-child Examples Basic example HTML < div > < p > This text is selected! </ p > < p > This text isn't selected. </ p > </ div > < div > < h2 > This text isn't selected: it's not a `p`. </ h2 > < p > This text isn't selected. </ p > </ div > CSS p:first-child { color : lime ; background-color : black ; padding : 5px ; } Result Styling a list HTML < ul > < li > Item 1 </ li > < li > Item 2 </ li > < li > Item 3 < ul > < li > Item 3.1 </ li > ...

Can An Html Element Have Multiple Ids?

Answer : No. From the XHTML 1.0 Spec In XML, fragment identifiers are of type ID, and there can only be a single attribute of type ID per element. Therefore, in XHTML 1.0 the id attribute is defined to be of type ID. In order to ensure that XHTML 1.0 documents are well-structured XML documents, XHTML 1.0 documents MUST use the id attribute when defining fragment identifiers on the elements listed above. See the HTML Compatibility Guidelines for information on ensuring such anchors are backward compatible when serving XHTML documents as media type text/html. Contrary to what everyone else said, the correct answer is YES The Selectors spec is very clear about this: If an element has multiple ID attributes, all of them must be treated as IDs for that element for the purposes of the ID selector.Such a situation could be reached using mixtures of xml:id, DOM3 Core, XML DTDs, and namespace-specific knowledge. Edit Just to clarify: Yes, an...

Bring Element To Front Using CSS

Answer : Add z-index:-1 and position:relative to .content #header { background: url(http://placehold.it/420x160) center top no-repeat; } #header-inner { background: url(http://placekitten.com/150/200) right top no-repeat; } .logo-class { height: 128px; } .content { margin-left: auto; margin-right: auto; table-layout: fixed; border-collapse: collapse; z-index: -1; position:relative; } .td-main { text-align: center; padding: 80px 10px 80px 10px; border: 1px solid #A02422; background: #ABABAB; } <body> <div id="header"> <div id="header-inner"> <table class="content"> <col width="400px" /> <tr> <td> <table class="content"> <col width="400px" /> <tr> ...

Correct MIME Type For Favicon.ico?

Answer : When you're serving an .ico file to be used as a favicon, it doesn't matter. All major browsers recognize both mime types correctly. So you could put: <!-- IE --> <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" /> <!-- other browsers --> <link rel="icon" type="image/x-icon" href="favicon.ico" /> or the same with image/vnd.microsoft.icon , and it will work with all browsers. Note: There is no IANA specification for the MIME-type image/x-icon , so it does appear that it is a little more unofficial than image/vnd.microsoft.icon . The only case in which there is a difference is if you were trying to use an .ico file in an <img> tag (which is pretty unusual). Based on previous testing, some browsers would only display .ico files as images when they were served with the MIME-type image/x-icon . More recent tests show: Chromium, Firefox and Edge are fine with both co...

Bootstrap Row With Columns Of Different Height

Image
Answer : This is a popular Bootstrap question, so I've updated and expanded the answer for Bootstrap 3 and Bootstrap 4... The Bootstrap 3 "height problem" occurs because the columns use float:left . When a column is “floated” it’s taken out of the normal flow of the document. It is shifted to the left or right until it touches the edge of its containing box. So, when you have uneven column heights , the correct behavior is to stack them to the closest side. Note : The options below are applicable for column wrapping scenarios where there are more than 12 col units in a single .row . For readers that don't understand why there would ever be more than 12 cols in a row , or think the solution is to "use separate rows" should read this first There are a few ways to fix this.. (updated for 2018) 1 - The 'clearfix' approach (recommended by Bootstrap) like this (requires iteration every X columns). This will force a wrap every X number...

Converting HTML To Plain Text In PHP For E-mail

Answer : Use html2text (example HTML to text), licensed under the Eclipse Public License. It uses PHP's DOM methods to load from HTML, and then iterates over the resulting DOM to extract plain text. Usage: // when installed using the Composer package $text = Html2Text\Html2Text::convert($html); // usage when installed using html2text.php require('html2text.php'); $text = convert_html_to_text($html); Although incomplete, it is open source and contributions are welcome. Issues with other conversion scripts: Since html2text (GPL) is not EPL-compatible. lkessler's link (attribution) is incompatible with most open source licenses. here is another solution: $cleaner_input = strip_tags($text); For other variations of sanitization functions, see: https://github.com/ttodua/useful-php-scripts/blob/master/filter-php-variable-sanitize.php Converting from HTML to text using a DOMDocument is a viable solution. Consider HTML2Text, which requires PHP5: http://www.howtocreate.co.uk/p...

Bootstrap Select Dropdown List Placeholder

Answer : Yes just "selected disabled" in the option. <select> <option value="" selected disabled>Please select</option> <option value="">A</option> <option value="">B</option> <option value="">C</option> </select> Link to fiddle You can also view the answer at https://stackoverflow.com/a/5859221/1225125 Use hidden: <select> <option hidden >Display but don't show in list</option> <option> text 1 </option> <option> text 2 </option> <option> text 3 </option> </select> dropdown or select doesn't have a placeholder because HTML doesn't support it but it's possible to create same effect so it looks the same as other inputs placeholder $('select').change(function() { if ($(this).children('option:first-child').is(':selected')) ...

Can I Use Javascript To Dynamically Change A Video's Source?

Answer : Sure, You can set the src attribute on the source element: document.querySelector("#myVideoTag > source").src = "http://example.com/new_url.mp4" Or using jQuery instead of standard DOM methods: $("#myVideoTag > source").attr("src", "http://example.com/new_url.mp4"​​​​)​ Then you need to call the load method on the video element: videoElement.load() I have faced this problem several times and based on previous experience and digging I can suggest these options: replace video tag completely yes, just re-insert <video> element with new sources. It's straightforward, but effective approach. Don't forget to re-initialize event listeners. assign video URL to video.src this I saw a lot in answers here, on stackoverflow, and also in sources on github. var video = document.getElementById('#myVideo'); video.src = newSourceURL; It works, but you cannot provide browser opt...

CSS Selector For Child Of Parent's Sibling Element

Answer : In a word: no. Given the current structure of your HTML (and the current state of CSS selectors), this is not possible. Perhaps we will get something like this in CSS4, but traversal like this is best left up to Javascript. You can obviously restructure your markup, and use the sibling selector: HTML <div class="parent"> <a href="#" id="trigger">Trigger</a> <div class="sibling"> <div id="change">Hello</div> </div> </div> CSS #trigger:hover + .sibling #change { color:red; } codepen No. You cannot achieve this using CSS only. Javascript is a good option in this case.. You can however detect the .parent being hovered (which will solve your problem if the parent surrounds exactly the trigger): .parent:hover + .sibling div#change{background:red;} (markup stays the same jsFiddle)

CSS Image Overlay With Color And Transparency

Answer : CSS Filter Effects It's not fully cross-browsers solution, but must work well in most modern browser. <img src="image.jpg" /> <style> img:hover { /* Ch 23+, Saf 6.0+, BB 10.0+ */ -webkit-filter: hue-rotate(240deg) saturate(3.3) grayscale(50%); /* FF 35+ */ filter: hue-rotate(240deg) saturate(3.3) grayscale(50%); } </style> EXTERNAL DEMO PLAYGROUND CSS Filter Effects IN-HOUSE DEMO SNIPPET (source:simpl.info) #container { text-align: center; } .blur { filter: blur(5px) } .grayscale { filter: grayscale(1) } .saturate { filter: saturate(5) } .sepia { filter: sepia(1) } .multi { filter: blur(4px) invert(1) opacity(0.5) } <div id="container"> <h1><a href="https://simpl.info/cssfilters/" title="simpl.info home page">simpl.info</a> CSS filters</h1> <img src="https://simpl.info/cssfilters/balham.jpg" alt="No filter: B...

CSS Position:fixed Inside A Positioned Element

Answer : You can use the position:fixed; , but without set left and top . Then you will push it to the right using margin-left , to position it in the right position you wish. Check a demo here: http://jsbin.com/icili5 The current selected solution appears to have misunderstood the problem. The trick is to neither use absolute nor fixed positioning. Instead, have the close button outside of the div with its position set to relative and a left float so that it is immediately right of the div. Next, set a negative left margin and a positive z index so that it appears above the div. Here's an example: #close { position: relative; float: left; margin-top: 50vh; margin-left: -100px; z-index: 2; } #dialog { height: 100vh; width: 100vw; position: relative; overflow: scroll; float: left; } <body> <div id="dialog"> **** </div> <div id="clo...

Adding Data Attribute To DOM

Answer : Use the .data() method: $('div').data('info', '222'); Note that this doesn't create an actual data-info attribute. If you need to create the attribute, use .attr() : $('div').attr('data-info', '222'); jQuery's .data() does a couple things but it doesn't add the data to the DOM as an attribute. When using it to grab a data attribute, the first thing it does is create a jQuery data object and sets the object's value to the data attribute. After that, it's essentially decoupled from the data attribute. Example: <div data-foo="bar"></div> If you grabbed the value of the attribute using .data('foo') , it would return "bar" as you would expect. If you then change the attribute using .attr('data-foo', 'blah') and then later use .data('foo') to grab the value, it would return "bar" even though the DOM says data-foo="blah...

CSS: Line-through With A Color Different From The Text Color?

Answer : You can simulate the desired effect with two nested elements, e.g.: span.inner { color: green; } span.outer { color: red; text-decoration: line-through; } <span class="outer"> <span class="inner">foo bar</span> </span> jsfiddle With no extra DOM (but may not work for some layouts for obvious reasons): <style type="text/css"> .strikethrough { position: relative; } .strikethrough:before { border-bottom: 1px solid red; position: absolute; content: ""; width: 100%; height: 50%; } </style> <span class="strikethrough">Foo Bar</span> A jsfiddle example here. It's not possible to make a line-through with a different color. It will be in the color you define with property color . see http://www.w3.org/TR/CSS2/text.html#lining-striking-props EDIT : w...

ContentEditable, CTRL-B CTRL-I And Saving

Answer : This is standard in all major browsers. There are also programmatic equivalents of the keyboard shortcuts available via document.execCommand() in all major browsers. Bold and italic commands, for example, can executed as follows: document.execCommand("Bold", false, null); document.execCommand("Italic", false, null); However, the mark-up generated varies between browsers. For example, variations for bold include <b>foo</b> , <strong>foo</strong> and <span style="font-weight: bold">foo</span> . References: MSDN, list of commands MDN (Mozilla) Short answer 'yes'. You might find this article interesting. Many a' developer have gone down this route. If you want a nice wysiwyg editor, there are many to choose from. On to your question: yes you can read the formatting. Try an innerHTML on the element and you'll find <b> tags around your bolds and <i> around your italics. Also - i...