<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <!-- 左侧 --> <div style="width: 240px;float:left;height: 300px;background:#666; "> <button type="button" onclick="javascript:alert('test')">右侧按钮1</button> </div> <!-- 右侧 --> <div style="width:100%;float:right; margin-left:-250px;"> <div style="margin-left:250px; height:300px;background:#666;"> </div> </div> </body> </html>
This method can realize the left and right layout normally, but there is a problem: due to the floating overlay method, the button in the left div cannot be clicked.
Solution: Add position attributes (such as relative, absolute, etc.) to floating elements
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <!-- 左侧 --> <div style="width: 240px;float:left;height: 300px;background:#666; position: relative;"> <button type="button" onclick="javascript:alert('test')">右侧按钮1</button> </div> <!-- 右侧 --> <div style="width:100%;float:right; margin-left:-250px;"> <div style="margin-left:250px; height:300px;background:#666;"> </div> </div> </body> </html>