search
HomeWeb Front-endHTML TutorialThe left and right layout of css div has no effect, and the right one is pushed to the bottom_html/css_WEB-ITnose

In the CSS div, I first made a div background, and then wanted to put two

inside this
, which means dividing a web page in half, but a problem arises , that is: I first set the height and width of the
on the left, and placed the things, and then when I made the
on the right, it was not displayed side by side with the first
, but It is arranged at the bottom, and the right side is empty (the width of the two
s inside does not exceed the background). Please help. Can anyone tell me how to make the two
s inside appear side by side? It would be better to be more detailed. Thanks!

I added style: float:left; to the first div but it had no effect. I also added float:right; to the second
and it had the same effect!


Reply to discussion (solution)



                                             ="text/css">
.bd{position:relative;}
.bd-left{height:300px;;margin-right:300px;background:#ccc;}
.bd- right{width:300px;height:300px;position:absolute;top:0;right:0;background:#AAA;}

                                                                                                      div class="bd">
                                                                         class="bd-right">
                                           

Use absolute positioning position:absolute;

First of all, thank you for your answers. The problem is solved, not what 2# said. I tried that one and the situation is like this, in a body Using BACKGROUND: #d6e4ef; COLOR: #000000 will affect the div, and putting BACKGROUND: #d6e4ef; COLOR: #000000 into the div will not work. Finally, removing BACKGROUND: #d6e4ef; COLOR: #000000 will work. But I still don’t understand the principle. I hope you can explain it. Thank you.

I think there is something wrong with the syntax of the code you removed.

It is not parallel, 1. Being squeezed out by other elements. Two: The width is not enough.


You can use positioning without floating
These things will not happen

It’s very simple: just change float:right to float:left

float: left


First of all, thank you for your answers. The problem is solved, not what 2# said. I tried that one and the situation is like this. I used BACKGROUND in a body: #d6e4ef; COLOR: #000000 will have an impact on the div. Even if you put BACKGROUND: #d6e4ef; COLOR: #000000 into the div, it won't work. Finally, removing BACKGROUND: #d6e4ef; COLOR: #000000 will work, but I still don't understand. I hope you can explain the principle, thank you.


It should have nothing to do with this. It seems that the poster still hasn’t found the key to the problem.

My experience is that if you can use table for this kind of thing, use table for layout. If your program involves accessibility , i18n, UX designer needs to change frequently, etc., which is quite troublesome

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML in Action: Examples of Website StructureHTML in Action: Examples of Website StructureMay 05, 2025 am 12:03 AM

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.

How do you insert an image into an HTML page?How do you insert an image into an HTML page?May 04, 2025 am 12:02 AM

ToinsertanimageintoanHTMLpage,usethetagwithsrcandaltattributes.1)UsealttextforaccessibilityandSEO.2)Implementsrcsetforresponsiveimages.3)Applylazyloadingwithloading="lazy"tooptimizeperformance.4)OptimizeimagesusingtoolslikeImageOptimtoreduc

HTML's Purpose: Enabling Web Browsers to Display ContentHTML's Purpose: Enabling Web Browsers to Display ContentMay 03, 2025 am 12:03 AM

The core purpose of HTML is to enable the browser to understand and display web content. 1. HTML defines the web page structure and content through tags, such as, to, etc. 2. HTML5 enhances multimedia support and introduces and tags. 3.HTML provides form elements to support user interaction. 4. Optimizing HTML code can improve web page performance, such as reducing HTTP requests and compressing HTML.

Why are HTML tags important for web development?Why are HTML tags important for web development?May 02, 2025 am 12:03 AM

HTMLtagsareessentialforwebdevelopmentastheystructureandenhancewebpages.1)Theydefinelayout,semantics,andinteractivity.2)SemantictagsimproveaccessibilityandSEO.3)Properuseoftagscanoptimizeperformanceandensurecross-browsercompatibility.

Explain the importance of using consistent coding style for HTML tags and attributes.Explain the importance of using consistent coding style for HTML tags and attributes.May 01, 2025 am 12:01 AM

A consistent HTML encoding style is important because it improves the readability, maintainability and efficiency of the code. 1) Use lowercase tags and attributes, 2) Keep consistent indentation, 3) Select and stick to single or double quotes, 4) Avoid mixing different styles in projects, 5) Use automation tools such as Prettier or ESLint to ensure consistency in styles.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)